aebstract Posted July 2, 2008 Share Posted July 2, 2008 ??? ??? 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 More sharing options...
PFMaBiSmAd Posted July 2, 2008 Share Posted July 2, 2008 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 https://forums.phpfreaks.com/topic/112928-cookies-not-setting-properly/#findComment-580078 Share on other sites More sharing options...
interpim Posted July 2, 2008 Share Posted July 2, 2008 $_COOKIE['savedid'] Link to comment https://forums.phpfreaks.com/topic/112928-cookies-not-setting-properly/#findComment-580079 Share on other sites More sharing options...
aebstract Posted July 2, 2008 Author Share Posted July 2, 2008 Yes I know it is $_COOKIE['savedid'];, though I can not get that to display any results which I stated. Also, it is on a separate page after the cookie is set and being refreshed. Link to comment https://forums.phpfreaks.com/topic/112928-cookies-not-setting-properly/#findComment-580096 Share on other sites More sharing options...
PFMaBiSmAd Posted July 2, 2008 Share Posted July 2, 2008 I am guessing the path to the file in the URL changed when you went to the new page? Link to comment https://forums.phpfreaks.com/topic/112928-cookies-not-setting-properly/#findComment-580106 Share on other sites More sharing options...
aebstract Posted July 2, 2008 Author Share Posted July 2, 2008 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 https://forums.phpfreaks.com/topic/112928-cookies-not-setting-properly/#findComment-580108 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.