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
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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.