Forum Moderators: coopster

Message Too Old, No Replies

Problem with sessions/cookies

         

smatts9

10:48 pm on Jul 18, 2006 (gmt 0)

10+ Year Member



I have a site that allows users to sign in, and when they do I set a cookie.

php Code:

setcookie( "id", "$userid", time()+3600, "/", false);

But on other pages like

url.com/member

I try this code:

php Code:

<?php
if (isset($_COOKIE["id"]))
echo "logged in";
else
echo "logged out";
?>

Even though I just signed in it still sends me "logged out"

Sekka

11:43 pm on Jul 18, 2006 (gmt 0)

10+ Year Member



Are you 100% sure your code is setting the cookie? Try this instead,

setcookie("id", $userid, time()+3600);

The setcookie() parameters are,

setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )

I think you were missing the domain part, hence why it wouldn't set.

whoisgregg

2:59 pm on Jul 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



print_r($_COOKIE);

is always handy for testing cookie values. :)