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'; } Quote Link to comment 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. Quote Link to comment 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.... Quote Link to comment 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'; } Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.