Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cookies not working on different pages

Tags:

php

cookies

Ok I have a cookie set, and I can clearly see it if I go to private data in Firefox... ok so when I echo it on one page in a certain directory it works, (www.example.com/dir), but on the index page of the site (www.example.com), it wont echo, it says the cookie is not set. Yes I have cookies enabled, yes I tried clearing cache and all that. Any ideas? PHP btw

like image 438
David Avatar asked Jan 10 '10 21:01

David


People also ask

Why are my cookies not setting?

That, or the dough wasn't cool enough before baking. Warm cookie dough or excess butter will cause the cookies to spread too much, baking quickly on the outside but remaining raw in the middle. Next time, chill your cookies in the fridge for 10 minutes before you bake them. If the problem persists, use less butter.

Where are cookies stored?

Cookies are stored on your device locally to free up storage space on a website's servers. In turn, websites can personalize while saving money on server maintenance and storage costs.

How do you set cookies?

Cookies are usually set by a web-server using the response Set-Cookie HTTP-header. Then, the browser automatically adds them to (almost) every request to the same domain using the Cookie HTTP-header.

Which of these attributes when true about a cookie does not let JavaScript access the cookie?

httponly is a flag you can set on cookies meaning they can not be accessed by JavaScript.


1 Answers

Which directory are you in when the cookie gets set?

From the PHP manual on setcookie(), emphasis mine:

Path

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 . If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain . The default value is the current directory that the cookie is being set in.

like image 147
Pekka Avatar answered Oct 18 '22 12:10

Pekka