1
There is no way to get this information because it is not sent to the server.
When the server sends a cookie to the user (SERVER -> CLIENT) the header of Set-Cookie
, it has some parameters like listed here, the attribute of expires
is one of them.
However, on the contrary this is not done. When the customer requests the site he uses the header of Cookie
, it contains only the information of the nome
and valor
of the cookie, but not the other data.
Therefore:
== Servidor -> Cliente ==
Set-Cookie: lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
== Cliente -> Servidor ==
Cookie: lang=en-US
PHP only has the information of
lang=en-US
, the expiration data the client does not report (since this value has already been informed by the server at a previous time).
An alternative is to include the "expiry" date within the cookie itself, or store the "expiry" time when using the Set-Cookie
.
In this case you could use:
$t = time() + 172800;
setcookie("visita", $t, $t, $path = "/");
That way, when to use the $_COOKIE['visita']
will have the value that is "the same" as the expiration term.
Thanks! has how to transform the value that appears in date ?
– Matheus Vitor
You can format using
date
.– Inkeliz