Help - Search - Members - Calendar
Full Version: Cookies Not Being Read
Weborum Webmaster Forum > Web Page Design > PHP
Joe
I have a strange problem ... maybe it's just something I've overlooking but for some reason my PHP code isn't reading my cookies.

I have set the cookies;

PHP
    setcookie("Joe2TorialsCMS['IP']", $IP, $CurTime + 3600);
    setcookie("Joe2TorialsCMS['User']", $Username, $CurTime + 3600);


And then when I try to read them I get nothing blink.gif

PHP
if(!isset($_SESSION['successful'])) {
echo 'error';
} else {
$CurIP = $_COOKIE['Joe2TorialsCMS']['IP'];
$CurUser = $_COOKIE['Joe2TorialsCMS']['User'];

echo 'set';
echo '<p>'.$CurIP.'</p>';
echo '<p>'.$CurUser.'</p>';
}


Anyone see a problem here or can suggest anything different?

Cheers.
bassrek
I'm not a PHP expert, but have you checked to see if $IP and $Username each have values when you assign the cookies those values?
Joe
Yup. I have checked by using print_r($_COOKIE); which views all cookies currently set by the domain ... they both come up in the array. But neither of them will come up when I try to view them the normal way.

CODE
echo $_COOKIE[Joe2TorialsCMS]['IP'];
echo $_COOKIE[Joe2TorialsCMS]['User'];


Just won't work ... pinch.gif
Joe
mad.gif Really not happy about that!

I spend an hour trying to figure it out and in the end my own tutorial helped me figure it out ...

CODE
   setcookie("Joe2TorialsCMS['IP']", $IP, $CurTime + 3600);
   setcookie("Joe2TorialsCMS['User']", $Username, $CurTime + 3600);


Should have been;

CODE
   setcookie("Joe2TorialsCMS[IP]", $IP, $CurTime + 3600);
   setcookie("Joe2TorialsCMS[User]", $Username, $CurTime + 3600);


The cookies are now being read ... biggrin.gif Cheers for the help Mike.
bassrek
Heh, at least you know someone got some use from your tut biggrin.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.