0

Hi,

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?

2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by diafol
0

Use

if(isset($_COOKIE['username']))

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?

0

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:

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.