noyfb Posted February 24, 2009 Share Posted February 24, 2009 Hi, This is my first post, I am also a new PHP coder. Took a while to find a PHP forum so I hope this one is healthy cause I'll be active for a very long time! code: setcookie("user", "AArrr", time()+604800); $user = $HTTP_COOKIE_VARS["user"]; echo $user; Tired just using $_COOKIE['user']; with no luck. The cookie gets set in Safari, I see it and it's content when using Safari show cookies, but when I try to print it's content to the browser, using the code above, I get ether "array()" or " "blank data. It depends on the code used. Firefox work 100% I am sure I am not the only one that got this annoying glitch. Tried to search google for "Safari #_COOKIE" but it's polluted with ignorant users trying to delete there cookies. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/146633-can-not-echo-or-print_r-_cookie-variables-to-safari-firefox-ok/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 24, 2009 Share Posted February 24, 2009 The $_COOKIE variable is not available until the next time the browser requests a page. FF has a nasty habit of requesting pages twice to apply the default character encoding that has been set, so the code on your page has probably been requested twice in FF in which case, setcookie() has sent the cookie to the browser, and it has been sent back to the server, while better behaving browsers have only been sent the cookie and have not sent it back to the server yet. Link to comment https://forums.phpfreaks.com/topic/146633-can-not-echo-or-print_r-_cookie-variables-to-safari-firefox-ok/#findComment-769839 Share on other sites More sharing options...
noyfb Posted February 24, 2009 Author Share Posted February 24, 2009 Thank for the intel! I also found that Safari dictates that the 4 first variables must be set to be able to read it's data. setcookie( 'variable name', 'variable data', time, 'path') Time can not be empty, use NULL or specify 0. And like you said you have to reload the page to echo the data. <?php // SET COOKIE // setcookie ('user_id','44', NULL , '/'); // Print Cookie #1 $arr = $HTTP_COOKIE_VARS["user_id"]; echo $arr; #2 echo $HTTP_COOKIE_VARS["user_id"]; #3 echo $_COOKIE['user_id']; ?> I guess it's best to supply a variable for all cookie fields. setcookie('variable name', 'variable data', time, 'path', 'domain', secure); Link to comment https://forums.phpfreaks.com/topic/146633-can-not-echo-or-print_r-_cookie-variables-to-safari-firefox-ok/#findComment-770234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.