On one page I have something like this
setcookie('user', 'value' ,6000, '/', 'mydomain.co.uk');
On the subsequent page I have
var_dump($_COOKIE);
I can see all the automatically generated ones, like PHPSESSID
but I cannot see user
.
If I do echo setcookie('user', 'value' ,6000, '/', 'mydomain.co.uk');
it returns true
. So I'm not sure why I can't see it.
I have tried a lot of different ideas, but nothing has worked. Also, I have using .htaccess to redirect all requests via one page index.php
not sure if this is doing anything.
The PHP isset() checks whether a cookie is set. Reminder: if you detect PHP setcookie not working, make sure it appears before the <html> element in your code, and that the set path parameter is correct.
The setcookie() function defines a cookie to be sent along with the rest of the HTTP headers. A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too.
php'; function setCookieData($arr) { $cookiedata = getAllCookieData(); if ($cookiedata == null) { $cookiedata = array(); } foreach ($arr as $name => $value) { $cookiedata[$name] = $value; } setcookie('cookiedata', serialize($cookiedata), time() + 30*24*60*60); } function getAllCookieData() { if (isset($_COOKIE[' ...
To create cookies in PHP, you need to use the setcookie function. Let's have a look at the basic syntax which is used to create a cookie. setcookie ( string $name , string $value = "" , int $expires = 0 , string $path = "" , string $domain = "" , bool $secure = false , bool $httponly = false );
Try this:
setcookie('user', 'value' ,time() + 6000, '/', 'mydomain.co.uk');
The expires Parameter needs to be a timestamp. 6000
as a timestamp is in the past and therefore removes the cookie.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With