将会话/ Cookie设置为24小时,以便每天向用户显示一次 [英] Set session/cookie for 24hs to show something only once per day to users
问题描述
我一直在寻找最后一个小时如何做到这一点...我认为这很容易,但不能使它的工作。
I've been searching for the last hour how to do this... I think it's pretty easy, but couldn't make it work.
我想每天只显示一次(AdSense)。
I want to show something (AdSense) only once per day.
我不知道是最好的方式,如果使用cookies或PHP会话。在任何情况下,你能帮助我,告诉我我该怎么做?
I don't know what would be the best way, if using cookies or PHP Sessions. In any case, can you help me and tell me how could I do this?
提前感谢!
圣地亚哥
编辑:我认为这种方式我可以创建会话,但我不知道如何重新创建每24小时,如何检查
I think this way I can create the Session, but I don't know how to "recreate" it each 24 hours and how to check for that session in order to show what I want to show once a day.
if (!isset($_SESSION['adSense'])
$_SESSION['adSense'] = time();
if (time() - $_SESSION['adSense'] <= 60*60*24 ) {
return true;
} else {
return false;
}
推荐答案
会话将在用户离开网站时过期,使用Cookie是您想要的:
Sessions will expire when the user leaves the site, using cookies is what you want:
<? if (!isset($_COOKIE['showstuff'])): ?>
<!-- replace this whatever you want to show -->
<?
setcookie('showstuff', true, time()+86400); // 1 day
?>
<? endif; ?>
这篇关于将会话/ Cookie设置为24小时,以便每天向用户显示一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!