在php中如何使用cookie?

2025-05-09 11:12:48
推荐回答(1个)
回答1:

setcookie() 函数用于设置 cookie
例如创建名为 "user" 的 cookie,把为它赋值 "Alex Porter"。我们也规定了此 cookie 在一小时后过期:
setcookie("user", "Alex Porter", time()+3600);
?>
取回 cookie 的值
echo $_COOKIE["user"];
print_r($_COOKIE);
?>
当删除 cookie
// set the expiration date to one hour ago
setcookie("user", "", time()-3600);
?>