I would like my script to verify the existence of the informed Cookie and if it did not exist insert, and if it was already existing did not insert.
My code is this:
$protocol = (strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === true) ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['REQUEST_URI'];
$current_uri = $protocol . '://' . $host . $uri;
$current_uri = $protocol . '://' . $host . $uri;
$current_url = md5($current_uri); // SOLUÇÃO
if(isset($_COOKIE[$current_url])) {
echo "O usuário já tem o cokkie.";
} else {
setcookie($current_url, date("d-m-Y H:i:s"), time()+3600); // 3600 => 1 hour
echo "Cookie inserido com sucesso";
}
But it has not worked! The cookie is actually inserted. The problem is that it is always renewed and the message that the Cookie already exists is not passed. Could someone help me?