PDA

View Full Version : Cookie code - what's wrong here?


Thomas P
05-22-2004, 10:17 PM
Hi there,

I need your PHP expertise regarding a cookie code:

<?PHP

if ($set) { setcookie("testcookie","inhalt",time()+3600); }

echo 'Anzahl der Cookies: ' . count($_COOKIE) . '<br>';
echo 'Cookie testcookie: ' . $_COOKIE['testcookie'];

?>

code ist accessed via "script.php?set=true"

Doesn't really work.

What's wrong here?

Thanks,
-Tom

Xenon
05-23-2004, 05:45 PM
well, if you have register_globals = off in your php.ini (as it should be) then this code won't work.

so you have to use this:
if ($_GET['set']) { setcookie("testcookie","inhalt",time()+3600); }

echo 'Anzahl der Cookies: ' . count($_COOKIE) . '<br>';
echo 'Cookie testcookie: ' . $_COOKIE['testcookie'];

Thomas P
05-23-2004, 08:19 PM
I see, thanks - that works!

Danke Dir,
-Tom

Xenon
05-24-2004, 02:30 PM
you're welcome :)