Jump to content

[SOLVED] Mod Rewrite Messes Up Cookies


limitphp

Recommended Posts

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?

 

 

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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.

 

 

 

 

 

Link to comment
Share on other sites

"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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.