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?

Recommended Answers

All 3 Replies

Member Avatar for diafol

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?

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 for diafol

OK, mark as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.