Search code examples
phpcookiessetcookie

Cookie value changing between directories?


I'm having a problem with a cookie. I set it in one directory of my website and want it to work in all sub directories of the directory I set it in. The problem is, the value is different when I use it in the sub directories

I set it like this:

setcookie("user", $values, $expire,"/foo/"); 

And it works fine on every page inside of "/foo/"

But when I retrieve it inside of directory "foo/bar" it says it's set, but the value is different. Any help is really appreciated :) I haven't run into this error before and I've been playing around with it for about an hour trying to see what's causing the problem.


Solution

  • I think you'll need to make the cookie site-wide rather than directory-specific.

    setcookie("user", $values, $expire,"/");