limitphp Posted February 2, 2009 Share Posted February 2, 2009 I have a cookie on the index.php page that sets a cookie: setcookie("time",$time, 0, "/localhost"); I tried setting the path so it would always set there. But, it doesn't. My mod rewrite goes to http://localhost/page2/ and unforunately it then sets the cookie to path: /page2/ How can I make it always set the cookie to the real path of the localhost? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/ Share on other sites More sharing options...
fanfavorite Posted February 2, 2009 Share Posted February 2, 2009 Have you tried with just a "/"? Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752682 Share on other sites More sharing options...
limitphp Posted February 2, 2009 Author Share Posted February 2, 2009 Have you tried with just a "/"? Yeah. It didn't work. It still set it to path: /page2/ Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752683 Share on other sites More sharing options...
premiso Posted February 2, 2009 Share Posted February 2, 2009 setcookie("time",$time, time()+3600*24, "/", "localhost"); Try that. Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752695 Share on other sites More sharing options...
limitphp Posted February 2, 2009 Author Share Posted February 2, 2009 setcookie("time",$time, time()+3600*24, "/", "localhost"); Try that. It actually didn't even set a cookie when I tried it. Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752702 Share on other sites More sharing options...
limitphp Posted February 2, 2009 Author Share Posted February 2, 2009 This is a serious flaw with mod rewrite. Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752714 Share on other sites More sharing options...
premiso Posted February 2, 2009 Share Posted February 2, 2009 http://www.aeonity.com/frost/php-setcookie-localhost-apache Take a look at that and see if it works. Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752720 Share on other sites More sharing options...
limitphp Posted February 2, 2009 Author Share Posted February 2, 2009 http://www.aeonity.com/frost/php-setcookie-localhost-apache Take a look at that and see if it works. Ok I tried, setcookie("time",$time, 0, "/",false); It did not work. I also tried: setcookie("time",$time, false, "/",false); it also did not work. Both times it set the cookie to path: /page2/ Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752732 Share on other sites More sharing options...
premiso Posted February 2, 2009 Share Posted February 2, 2009 How are you checking the cookie was created? Remember that to check it the page has to reload after the cookie has been set. Other than that, I have no clue how/why it is not working. Maybe your browser is set not to accept cookies? I do not know. And a note, if you want the cookie valid for everything just use the "/" path and it should show for the whole server. Thinking even more about it, using mod_rewrite you should set it to "/" and not "/page2" as that is not a real folder so the cookie will most likely not be recognized. Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752748 Share on other sites More sharing options...
limitphp Posted February 2, 2009 Author Share Posted February 2, 2009 How are you checking the cookie was created? I have the web developer add-on in firefox that shows me the cookies for my site. Remember that to check it the page has to reload after the cookie has been set. Other than that, I have no clue how/why it is not working. Maybe your browser is set not to accept cookies? I do not know. And a note, if you want the cookie valid for everything just use the "/" path and it should show for the whole server. My browser is set to accept cookies. I checked to see before that it was getting them. I can clearly see with web developer add-on what cookies are set and what path and value they have. It is not working, I have no idea why.... Thinking even more about it, using mod_rewrite you should set it to "/" and not "/page2" as that is not a real folder so the cookie will most likely not be recognized. I have mod rewrite go to alot of directories that aren't real.....for SEO purposes. I have it goto /comments/artist-name/song-name/ for instance, even though its really: comments.php?artisthash=x&songHash=x digg.com and many other sites use index.com/page2/ for their pagination, I'm using it to rewrite my pagination links. I don't know why it sets the cookies to path:/page2/ (when I click on "http://localhost/page2/") when I clearly use: setcookie("time",$time, 0,"/"); to set it to "/" its driving me nuts! Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752830 Share on other sites More sharing options...
limitphp Posted February 2, 2009 Author Share Posted February 2, 2009 The only time it worked, is when I had my site in a folder ex) greckle/ And i set the path to the folder: setcookie("time",$time, 0,"/greckle"); But I don't want to set my site in a folder. I need it to work live. I would use sessions, because those session cookies seem to work....they always set to path: "/" even when the mod rewrite for my pagination says "http://localhost/page2/" BUT, my login system uses regular cookies. So, at some point, I'm going to have to use cookies. There has to be a work around or a setting I'm not familar with, mod rewrite cannot have a flaw as big as this one. I see thorpe is on the board.....THORPE, I need you help! I'm going crazy here......I've done google search after google search, noone seems to talk about the fix for mod rewrite MESSING up your cookies! Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752872 Share on other sites More sharing options...
limitphp Posted February 2, 2009 Author Share Posted February 2, 2009 Ok, I tried: setcookie("time",$time, 0, "/localhost;"); //with semicolon at end setcookie("time",$time, 0, "/localhost"); setcookie("time",$time, 0, "/;"); setcookie("time",$time, 0, "/ "); //with space before setcookie("time",$time, 0, " / "); //with space before and after none of them worked.... I tried: setcookie("time",$time, 0, "/", "/http://localhost/"); setcookie("time",$time, 0, "/", "/http://localhost"); just in case it needed the path and domain....the last two didn't even set a cookie. this is driving me crazy...I'm going to go home and not even be able to have a conversation with my wife...all I'll be thinking about is how to fix this problem.... Quote Link to comment https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/#findComment-752895 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.