iwannabeleet Posted January 24, 2008 Share Posted January 24, 2008 I have an index.php page which sets a cookie: <?php setcookie('showpopup',1); ?> and has a brief flash animation which later automatically sends the user to the main page (index2.php), where the cookie is checked: if(isset($_COOKIE['showpopup'])) { //dostuff} So now I'm really confused because in Firefox & IE (i think) the code works in great, but in Safari, the ISSET is returning false. But here's the crazy thing, I check Safari's Cookies window and it shows the cookie right there, with a value of 1 ???. So it's set in the browser, but somehow the ISSET is returning false in Safari. Anyone have any clue what could be causing this?? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 24, 2008 Share Posted January 24, 2008 well m aybe safari stores the cookies but theres a problem with teh domain to which they are saved?? im not to good with cookie domains -0 the another thig could be that safari proccesses them differently and therefore th page is setting the cookie and then readig form teh cookie before its been written? either way , gdlk Quote Link to comment Share on other sites More sharing options...
iwannabeleet Posted January 24, 2008 Author Share Posted January 24, 2008 I'm wondering if part of this has to do with the situation of whether or not the URL has 'www' in front of it. It seems that the $_COOKIE isn't read if it was set by 'http://example.com/index.php' and then tries to get read by 'http://www.example.com/otherpage.php' I'm probably venturing out of PHP territory and now into more webserver territory but does anyone know if that might be the cause, and if so how I can remedy this? thank you in advance Quote Link to comment Share on other sites More sharing options...
iwannabeleet Posted January 24, 2008 Author Share Posted January 24, 2008 well m aybe safari stores the cookies but theres a problem with teh domain to which they are saved?? oops I just posted about that, yeah I think you're exactly right, although now I'm trying to figure out the best way to solve this problem. I have no way of knowing if a user will actually visit the domain from 'www.example.com' or just type in 'example.com' and my initial re-direct has to be hardcoded to one of those, so either way sometimes it will be wrong. I hope i'm making sense.... Quote Link to comment Share on other sites More sharing options...
iwannabeleet Posted January 24, 2008 Author Share Posted January 24, 2008 Sorry I did more googling and think I answered my own question, the PHP manual discusses this with the DOMAIN parameter of 'setcookie', I think it will solve my problem, fingers crossed. Quote Link to comment Share on other sites More sharing options...
iwannabeleet Posted January 24, 2008 Author Share Posted January 24, 2008 Sorry for posting so much without googling first, the problem was easily solved with that domain parameter of setcookie: bool setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly ]]]]]] ) domain The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the » spec for details. 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.