好吧,我想允许一个用户每个页面 1 次查看,然后向他们发送一个 cookie,阻止他们再次查看该页面,但我不擅长使用 cookie,我会使用 IP 来做到这一点,但我宁愿通过 cookies 来做到这一点。这可能吗?我该怎么做?
最佳答案
最简单的答案:
if(isset($_COOKIE['myCookie'])){
die('Not allowed! Only one view per user!');
}
else{
setcookie('myCookie', true);
}
//content here
通过 session 来实现:
session_start();
if(isset($_SESSION['mySession'])){
die('Not allowed! Only one view per user!');
}
else{
$_SESSION['mySession'] = true;
}
//content here
重定向而不是显示丑陋的错误:
if(isset($_COOKIE['myCookie'])){
header('Location: error.php');
exit;
}
else{
setcookie('myCookie', true);
}
//content here
关于php - 每个 IP 1 个 View 或设置 Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12212983/