PHP cookie troubles

liunx

Guest
<?php
setcookie("beenhere","Yes", time() + 3600);
?>
<html>



<?php
if ($beenhere =="Yes")
{
print "Welcome back!";
}
else
{
print "Glad You could stop by!";
}

?>

i get an "undefined var" msg... help???try using $_COOKIE['beenhere'];if youre using it on your home box and you just installed it, you need to edit the error reporting, right now you probably have it set to show all notices warnings and errors. edit the php.ini file where it says error reporting. its near the beginning, you cant miss itok thanx.

for that:

$_COOKIE['beehere'];

thing, do you i still put:

$_COOKIE['beenhere','yes',time()+3600];

or not?no, $_COOKIE is a global, it gets the cookie and its value, it doesnt set oneoh ok i got ya!
\thanx for the help!always remeber morrow, tha twhen you set a cookie like that it will not read it until the page is fully reloaded again.

so basically yes that will work (with the addition of the global $_COOKIE) but it will not show them as logged in until it is refreshed.you should also do something like
if(!$_COOKIE['beenhere'])setcookie();
so it doesnt try to set it every time they visit it even when they have the cookieso it will look like

if ($_COOKIE['beenhere'] == "Yes")
{
print "Welcome back"
}
else
{
print "glad you stop by"
}ok well i tried that code, but there seems to be an error in the "setcookie" becuase every time i go it says "glad you could stop by"yes morrow that is corect.after you load the page try refreshing it.

what does it say after a refresh.it says the same thing every time... "Glad you could stop by"try this

<?php
setcookie("beenhere","Yes", time() + 3600, "/");
?>ok lemme try that.
thanx for all the help so far btw, i feel like im finally actually participating in these forums :)well that seems to have worked, thanx scoutt:)!you bet, and it looks like you are participating, good job :)lol thanx but umm... why did that "/" thing make a difference?sometimes you don't need it but it sets the path to be saved to.oh ok.
:cool:
 
Back
Top