I have two php pages.
On the first php page called process.php I have the following code:

setcookie('username', 'dan', time() + 2592000 , '/');

And when I use the following code in this page:

$username = $_COOKIE['username'];
if (isset($username)) {
    echo $username;

Everything works fine, and I get the username printed.

In the second php page called check.php I have the same code for checking the value of the username, and I get noting.

The purpose of cookies is to enable us to pass data between different pages, but it doesn't work for me.
Can you please assist me in understanding what I am doing wrong?

Member Avatar




to check the cookie.
Browse your cookies via the browser (under the hood) to see if it exists.
Could there be a problem with regard to where the cookie is being stored? Are the pages in the same directory system?

Thanks, I found the problem.

In one place I used the domain , and in the other place I used .

Big mistake when you are working with cookies :icon_mrgreen:

Member Avatar


OK, mark as solved