After I destroy session on logout and `setcookie` to past so I can expire it, on next authentication I cannot set cookie again. Here is my logout:

```
session_start();
unset($_SESSION['id_user']);
session_destroy();
setcookie('logat', '', time() - 3600);
header("location: index.php"); 

```

and here is where I `setcookie` on authentication:

```
<?php
header('Content-Type: application/json');
session_start();
include('engine/core/dbconfig.php');
$password   = $_POST['password'];
$email      = $_POST['email'];
$hash       = hash('sha512', $password);
$hash_email = hash('sha512', $email);

$stmtt = $dbh->prepare("SELECT * FROM Users where Email=:email and Password= :hashed");
$stmtt->bindParam(':email', $email);
$stmtt->bindParam(':hashed', $hash);
$stmtt->execute();
if ($row = $stmtt->fetch()) {

    setcookie('logat', $hash_email, time() + (60 * 60 * 24 * 1000));

    $stmt = $dbh->prepare("Update Users SET Cookie_Log=:cookie_log where ID_User=:id_user");
    $stmt->bindParam(':id_user', $row['ID_User']);
    $stmt->bindParam(':cookie_log', $_COOKIE['logat']);
    $stmt->execute();
    $stmt = $dbh->prepare("Update Cos SET ID_User=:id_user where cookie=:cookie_cos");
    $stmt->bindParam(':id_user', $row['ID_User']);
    $stmt->bindParam(':cookie_cos', $_COOKIE['cos']);
    $stmt->execute();
    $_SESSION['id_user'] = $row['ID_User'];
    $arr                 = array(
        'tip' => 'user',
        'id' => '' . $_SESSION['id_user'] . ''
    );

}
?>

```

i did a test and it seems the cookie is set but it's not inserted into the database. At first login it is inserted but after logout and relog the column `Cookie_Log` is updated to empty