管理员如何取消设置用户的所有 Cookie
How Admin Can Unset All The Cookies Of The Users
我有一个网站每天都举办艺术比赛,晚上 9 点管理员决定某人获胜,他还想取消所有用户的所有 cookie。
我设置一天的Cookie
$cookie_name = "participated";
$cookie_value = "yes";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
有什么方法可以在每天晚上 9 点取消设置,或者管理员有什么方法可以在每天晚上 9 点取消所有 cookie 吗?
已编辑:代码已尝试
<?php
date_default_timezone_set('Asia/Kolkata');
if(date("H") <= 12){
$date = date("H");
}else{
$date = date("H")-12;
}
echo 9-$date;
?>
使用 DateTime 内置 class 你可以简单地做
$cookie_name = "participated";
$cookie_value = "yes";
// get the timestamp of today @ 9PM to use as the expiry time
$expire = (new DateTime('today 21:00:00'))->getTimestamp();
// or with a specific timezone
//$expire = (new DateTime('today 21:00:00', new DateTimeZone('Asia/Kolkata')))->getTimestamp();
setcookie($cookie_name, $cookie_value, $expire, "/");
我有一个网站每天都举办艺术比赛,晚上 9 点管理员决定某人获胜,他还想取消所有用户的所有 cookie。
我设置一天的Cookie
$cookie_name = "participated";
$cookie_value = "yes";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
有什么方法可以在每天晚上 9 点取消设置,或者管理员有什么方法可以在每天晚上 9 点取消所有 cookie 吗?
已编辑:代码已尝试
<?php
date_default_timezone_set('Asia/Kolkata');
if(date("H") <= 12){
$date = date("H");
}else{
$date = date("H")-12;
}
echo 9-$date;
?>
使用 DateTime 内置 class 你可以简单地做
$cookie_name = "participated";
$cookie_value = "yes";
// get the timestamp of today @ 9PM to use as the expiry time
$expire = (new DateTime('today 21:00:00'))->getTimestamp();
// or with a specific timezone
//$expire = (new DateTime('today 21:00:00', new DateTimeZone('Asia/Kolkata')))->getTimestamp();
setcookie($cookie_name, $cookie_value, $expire, "/");