Below are my test files. This is all they contain.
File test.php:
<?php
setcookie("test", "test", time() + 3600);
header("Location:test2.php");
File test2.php:
<?php
if(!isset($_COOKIE['test'])) {
echo 'cookie not set';
} else {
echo 'cookie set';
}
When I try to display the test.php page I got "cookie not set". This is driving me crazy...
Here is what i checked so far:
- I tested with Safari / Chrome / Firefox,
- My browsers accept cookies,
- As you can see in my example there is no output sent to browser before calling setcookie function,
- When displaying the result of the setcookie function, I got true,
- it works on my local computer, but not on my server,
Last point let me believe there is something wrong in the server configuration? I'm on a share hosting server so there is not much I can do about that.