我有这个代码
<?php
setcookie('page', 'settings', time(),'/');
header('Location: settings.php');
?>
Run Code Online (Sandbox Code Playgroud)
但每次我用$ _COOKIE ['page']检查cookie都是空的?
您的cookie总是过期,使用:
setcookie('page', 'settings', time()+3600,'/'); // + 1 hour
Run Code Online (Sandbox Code Playgroud)
如果你有一些bellow标题,你也可以为你的脚本添加一个退出:
<?php
setcookie('page', 'settings', time()+3600, '/');
header('Location: settings.php');
exit();
?>
Run Code Online (Sandbox Code Playgroud)