Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

same cookie on different pages (cookie path)

I have an application and I need to store some information in cookies. I have an index page and put some piece of information into cookie (for example, some variable name). Index page cookie has path /Main/. In another page I need to read this cookie and if necessary modify it. But another page cookie path is /Main/info/. Browser just creates a new cookie, but I need to override it and use the same cookie with path /Main/ on all pages. How can I do that?


1 Answers

Add path=/; or specify a path when you create the cookie. This will prevent the browser from creating duplicate cookies per domain.

To one of the comments, if you look at Google Chrome and how it displays the cookies it will show you the path. If you use the same cookie name without specifying the path it will create a cookie for each.

Note: Internet Explorer doesn't do the same thing, it has the single text file per domain.

like image 174
Rob Avatar answered Oct 17 '25 04:10

Rob