[SOLVED] How create a cookie who expire at midnight?

Hello,

I’m trying to create a cookie that expires every day at midnight so that users have to log in every morning, but I can’t do it.

In module “adm_Login”, function “remember_me_validate”, this is my change :

$remember_me_expiry_cookie = [sett_cookie_expiration_time];
// setcookie("usr_data", sc_encode(serialize($usr_data)),time()+60*60*24* $remember_me_expiry_cookie, '/');
$currentDateTime = new DateTime();
$midnightTimestamp = strtotime('tomorrow', $currentDateTime->getTimestamp());
setcookie("usr_data", sc_encode(serialize($usr_data)),$midnightTimestamp, '/');

Sometime I can see the cookie “user_data” :

image

But not in the morning when I reconnect.

Do you have an idea about this problem ?

Thanks

Hi again,

Well once again, I confused user_data with PHPSESSID.

How to destroy the PHPSESSID cookie at midnight? This duration is one year while the value of “session.gc_maxlifetime” in php is equal to “1440”

THANKS.

This is my solution :

if(!isset($_COOKIE[‘usr_data’])){
if(isset($_COOKIE[‘PHPSESSID’]))
{
unset($_COOKIE[‘PHPSESSID’]);
setcookie(‘PHPSESSID’,’’,time()-3600,’/’);
sc_redir(‘adm_Login’);
}
}

in “OnApplicationInit” in my Menu.

1 Like