Shakeel Ahmed Shakeel Ahmed - 2 months ago 6
PHP Question

PHP: Cookie Delete not working

I've created a cookie expire time 60 days... But now I am not able to delete cooking. I am using this function to delete cookie. When I refresh page then cookie is again there.

function delete_cookie($key_name)
{
$expire = time() - 3600;
setcookie($key_name, '', $expire, '/');
unset($_COOKIE[$key_name]);
}

Answer

try this

function delete_cookie($key_name)
{
  $expire = time() - 3600;
  $dimain = $_SERVER['HTTP_HOST'];
  setcookie($key_name, '', $expire, '/', $domain);
}

also you don't need unset()


Edit:

assuming that $key_name is the cookie name