PHP setcookie () not working

On one page I have something like this

setcookie('user', 'value' ,6000, '/', 'mydomain.co.uk'); 

On the next page I have

 var_dump($_COOKIE); 

I see everything automatically generated, for example PHPSESSID , but I do not see user .

If I do echo setcookie('user', 'value' ,6000, '/', 'mydomain.co.uk'); , it returns true . Therefore, I am not sure why I do not see this.

I tried a lot of different ideas, but nothing worked. Also, I use .htaccess to redirect all requests through a single index.php page, not sure if this is doing anything.

+8
php cookies
source share
2 answers

Try the following:

 setcookie('user', 'value' ,time() + 6000, '/', 'mydomain.co.uk'); 

Validity period The parameter must be a timestamp. 6000 as a timestamp in the past and therefore deletes the cookie.

+17
source share

What about:

 setcookie('user', 'value' ,6000, '/', '.mydomain.co.uk'); 

Check your cookies. Some browsers (firefox and chrome) have add-ons that allow you to see cookies as they arrive so that you can debug.

EDIT: Problem 6000. This is wrong. use this: time() + 6000

+1
source share

All Articles