1
In PHP I am creating a login coockie like this:
$data = "e".gmdate("dmY");
setcookie("elogado", $data, time() + 600, "/");
When I close the browser and reopen, will I check the coockie like this:
if(isset($_COOKIE["elogado"])){
echo "sim";
}
It falls inside that if, ie coockie does not disappear when closing the browser. Is there any way to unset when closing the browser and/or tab?
The sense of the cookie is to keep it until you close the browser. use $_SESSION for this and it will be removed when you close the browser
– Sveen
If you do not set the lifetime (duration) of a cookie, it will last as long as the browser remains open. setcookie('elogado', $data);
– user60252
@Sveen great, it worked!
– caiocafardo
@Leocaracciolo tested it, but it didn’t roll...
– caiocafardo
See the manual in the part
expire
http://php.net/manual/en/function.setcookie.php which saysSe configurado para 0, ou omitido, o cookie irá expirar ao fim da sessao (quando o navegador fechar).
Understand that closing your browser is closing all pages regardless of whether you belong to the site.– user60252
@Sveen, both
$_SESSION
how muchcookie sem data de expiração
will work until you close the browser. Including in your comment you state this. What maybe AP does not know is what it meansfechar o navegador
in such cases. You may think that you are closing the/the pages of the website that created the Session or cookie when you should actually close all the open pages of that browser.– user60252