The time of Cookies created when I close my browser is running out

Asked

Viewed 687 times

4

I’m here asking because unfortunately I’ve tried all the alternatives in research since last week. And I’m probably doing something wrong.

Come on:

    setcookie("email", "email", time() + (360 * 24 * 3600));

This is the code I created the cookie for. It stays in the header before reading the html. For the cookie to last 1 year.

However, the other day he inserts this cookie again. I do a check to see if it exists and then insert the record in the database, to have control:

    if(!isset($_COOKIE['email'])){

    setcookie("email", "email", time() + (360 * 24 * 3600));

    mysql_query("INSERT INTO db(id, email, data) VALUES (0, 'email', NOW() )")

    }

I don’t know the reason for the error. I may have to set up php.ini, or something else. I have already searched and can’t find the error. This is the first time I’ve worked with cookies.

Anyone who can help me, I thank.

  • Can’t the error be in the insertion in the database? If the field id is a primary key it will not be able to add the record.

  • No @gmsantos, several records are actually being entered. This should not occur since the cookie "should" last 1 year.

  • What I need, is that if the user turns off his computer, the other day I get the same cookie. That’s it. And register new users who are entering the site.

  • 3

    Since the cookie is inside the browser, it should not be any PHP configuration. There is also the possibility that your browser will not accept cookies or they will be cleaned when you restart the machine.

  • Open the console and see the expiration date of the cookie in your browser. @gmsantos may be right, when in doubt, use another browser to see if it is not the configuration.

  • So I took the test but that’s not it.

  • Tested in another browser and the console showed the expiration date for 2016?

  • I found the problem.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.