Jump to content

cookies not setting properly


aebstract

Recommended Posts

??? :o ???

Okay, I am trying to set a cookie and then use the information to set a session. Problem is, I can see the cookie when I go in to Tools > Options > Show Cookies (firefox) and see the right name and value for it. Though when I run a print_r($_COOKIE); I get this:

 

Array ( [__utma] => 250445717.1368899236585890600.1214858623.1215007336.1215009291.9 [__utmz] => 250445717.1214858623.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none) [__utmc] => 250445717

[phpSESSID] => 564t3rk66k6it4p8p73afim021 [__utmb] => 250445717.5.10.1215009291 )

My code for setting the cookie is:

if (isset($_POST['stayloggedin'])) {
$postsessid = $worked['plant'];
setcookie ('savedid', $postsessid, time()+5256000);

..........

 

Like I said, I see the cookie in my browser's list of cookies, though I don't see it when I run the print_r test. So is it being set wrong or what is going on here?

Link to comment
https://forums.phpfreaks.com/topic/112928-cookies-not-setting-properly/
Share on other sites

Where and when are you running the print_r() relative to when the setcookie() is executed? On the same page or after the page is refreshed/on a different page?

 

The $_COOKIE variables are set when a page is requested and the browser sends the matching cookies to the server. If you are doing the print_r() after the setcookie(), $_COOKIE won't yet be set until the page is requested by the browser after the setcookie() has been executed.

Well I was originally on domain.com/login2/ and am just working from domain.com now, does that make a difference? What I wanted it to do was auto log the user in no matter what page they are on, if this makes a difference then what I need to do is set the cookie within the index file when the user logs in with that option enabled?

 

 

edit: instead of creating it on the index file, I can just set the path to "/", is that right?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.