dreamwest Posted June 27, 2009 Share Posted June 27, 2009 Im going round in circles trying to set a simple cookie, ive done this before but i cant get it to work. Can someone see my error?? $expire=time()+60*60*24*30*30; setcookie("turbo", "on", $expire, "/"); echo "Completed! <a href=\"/\">Click here to test</a>"; if(!$_COOKIE['turbo']){ echo 'its not there'; }elseif($_COOKIE['turbo'] == "on" ){ echo 'its on'; } Link to comment https://forums.phpfreaks.com/topic/163876-insane-cookie/ Share on other sites More sharing options...
thebadbad Posted June 27, 2009 Share Posted June 27, 2009 Works fine when I test it (although I'm getting an expected "undefined index" notice when $_COOKIE['turbo'] doesn't exist). Just remember that the cookie is first available on the next page load. Link to comment https://forums.phpfreaks.com/topic/163876-insane-cookie/#findComment-864658 Share on other sites More sharing options...
dreamwest Posted June 27, 2009 Author Share Posted June 27, 2009 Works fine when I test it (although I'm getting an expected "undefined index" notice when $_COOKIE['turbo'] doesn't exist). Just remember that the cookie is first available on the next page load. Thats why i added the echo "Completed! <a href=\"/\">Click here to test</a>"; part Ive tested it on 3 browser and no cookie is set, although i can set cookies with javascript ...maybe an elusive bug.... Link to comment https://forums.phpfreaks.com/topic/163876-insane-cookie/#findComment-864693 Share on other sites More sharing options...
thebadbad Posted June 27, 2009 Share Posted June 27, 2009 Try adding this to the top of the script, for debugging: ini_set('display_errors', 1); error_reporting(E_ALL); Also check if setcookie() returns false: if (setcookie("turbo", "on", $expire, "/") === false) { echo 'setcookie() failed'; } Link to comment https://forums.phpfreaks.com/topic/163876-insane-cookie/#findComment-864701 Share on other sites More sharing options...
dreamwest Posted June 27, 2009 Author Share Posted June 27, 2009 Yep works now. It was the ajax http request i was using to initiate the page. It still doesnt work with ajax but works when browser enters page. Link to comment https://forums.phpfreaks.com/topic/163876-insane-cookie/#findComment-864847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.