limitphp Posted February 3, 2009 Share Posted February 3, 2009 I have a cookie "time" on my index.php page. I have mod rewrites for my pagination that takes users to page2, page3, etc. So the addresses would be www.index.com/page2/ www.index.com/page3/ www.index.com/page4/ etc.... sort of like how digg.com does it. Instead of my "time" cookie on index.php going to path: "/" it goes to path: "/page2/", or path: "/page3/", etc. How can I fix this? Quote Link to comment Share on other sites More sharing options...
corbin Posted February 3, 2009 Share Posted February 3, 2009 http://php.net/setcookie check the param list Quote Link to comment Share on other sites More sharing options...
limitphp Posted February 3, 2009 Author Share Posted February 3, 2009 http://php.net/setcookie check the param list I had looked into that and saw that you can set the path. So I tried it. I tried setting it to all kinds of things: setcookie("time",$time, 0, "/"); setcookie("time",$time, 0, "/localhost/"); a whole bunch of other things..... but it would still set the path to "/page2/", "/page3/", etc.... I'm using wamp server. Maybe there's a setting that I need to change or something? I don't know what to do here....I'm really frustrated. Quote Link to comment Share on other sites More sharing options...
corbin Posted February 3, 2009 Share Posted February 3, 2009 Uhhhh.... You're passing 0 as the expires parameter..... You need to send a time in the future. For example, for the cookie to last a day: setcookie("time", $time, time()+86400, "/"); (You might not even need a path specified if you've been passing the time of 0 this entire time.) Quote Link to comment Share on other sites More sharing options...
limitphp Posted February 3, 2009 Author Share Posted February 3, 2009 Uhhhh.... You're passing 0 as the expires parameter..... You need to send a time in the future. For example, for the cookie to last a day: setcookie("time", $time, time()+86400, "/"); (You might not even need a path specified if you've been passing the time of 0 this entire time.) Someone on this board told me that passing 0 makes the cookie expire when the session ends. Is that not true? Quote Link to comment Share on other sites More sharing options...
limitphp Posted February 3, 2009 Author Share Posted February 3, 2009 Uhhhh.... You're passing 0 as the expires parameter..... You need to send a time in the future. For example, for the cookie to last a day: setcookie("time", $time, time()+86400, "/"); (You might not even need a path specified if you've been passing the time of 0 this entire time.) edit: Oh my gosh! It works now when I use something other than 0 for time! Thank you corbin! But, why doesn't it work with 0? What should I set time equal to if I want it to end as close to the session as possible? "If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes). " from: http://us3.php.net/setcookie "The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain . " I don't understand....why that is not working. It says right there that setting it to '/' should work. Unless setting it to '/' makes it availavle to to the entire "/page2/" domain, "page3/" domain, etc.... I'm so incredibly frustrated right now, I really don't know what to do here. Quote Link to comment Share on other sites More sharing options...
limitphp Posted February 3, 2009 Author Share Posted February 3, 2009 "What should I set time equal to if I want it to end as close to the session as possible?" Scratch that...I'm just going to use a session variable for it, but now I know that my login cookies will work! You don't know how much stress you saved me from, corbin, Thank you so much! You are awesome! Although, I'm still curious why 0 for expire doesn't work. Quote Link to comment Share on other sites More sharing options...
corbin Posted February 4, 2009 Share Posted February 4, 2009 No idea. Perhaps the client handles it wrongly? Or PHP? Perhaps try passing NULL and see what happens? 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.