PDA
Partners

View Full Version : cookies


konputer
July 9th, 2004, 03:47 PM
I decided for my website that there should be an intro page, but it would only show once;
I tried writing a script at /index.php
but can't seem to get the cookies set right.
<?php

if (!isset($_COOKIE['cookie'])) {
setcookie("cookie", "yep", time() + 3600000);
}

if ($_COOKIE['cookie'] != "1")
{
$cookie_data='1';
setcookie("cookie", $cookie_data, time()+3600000);
//echo '<meta http-equiv="Refresh" content="1;url=http://www.konputer.org/intro.html">';
echo "cookie set.. ";
echo $_COOKIE['cookie'];

};


?>

(after this html begins for the main page...)

ZYV
July 9th, 2004, 04:41 PM
Hi!

setcookie("cookie", "yep", time() + 3600000);

should probably be

setcookie("cookie", "1", time() + 3600000);

HTH,
Z.

Marshall
July 13th, 2004, 07:49 PM
Also at the end, you dont need the ; after the } for the end of the if. And the cookies settings are correct because if he changed it to 1 then it would always skip the intro and never play it. You could actually delete the first if and just go if theres no $_COOKIE['cookie'] then run the intro and set it and if there is one to skip it.

konputer
July 13th, 2004, 09:13 PM
thanks a lot.. seems to work fine now!

Marshall
July 14th, 2004, 03:51 AM
No problem, glad to hear it helped :)