Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/143487-set-the-same-path-for-all-cookies/
Share on other sites

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/

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.

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!

 

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!

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

 

 

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.