如何检查特定网页上的上次访问日期?我想在该页面上显示 link 7 天后过期
How do I check last visited date on particular web page ? I want to show link expired after 7 days on that page
我想在该浏览器上存储首次访问日期,7 天后我想在该网页上显示一些其他内容。那么如何检查用户第一次访问网页的时间呢?我想让该内容仅在 7 days.How 期间可见,我可以使用 php 代码实现吗?
请帮我解决这个问题。
示例:
// When a user visit that page, you will check whether a cookie is
// set or not. If not, then you can set a cookie with the current time
// as its value. If already set, then check if its time is greater than
// 7 days or not.
$showContent = true;
$datetime = new \DateTime();
$now = $datetime->format('Y-m-d H:i:s'); //current datetime
//check cookie
if(!isset($_COOKIE['pageVisitTime'])) {
setcookie("pageVisitTime", $now, time() + (10 * 365 * 24 * 60 * 60)); /* using a far future date */
} else {
$pageVisitTime = $_COOKIE['pageVisitTime'];
$visitDateTime = new \DateTime($pageVisitTime);
if($visitDateTime->diff($datetime)->days > 7) {
$showContent = false;
}
}
//Depending on value of $showContent you can control your content
我想在该浏览器上存储首次访问日期,7 天后我想在该网页上显示一些其他内容。那么如何检查用户第一次访问网页的时间呢?我想让该内容仅在 7 days.How 期间可见,我可以使用 php 代码实现吗? 请帮我解决这个问题。
示例:
// When a user visit that page, you will check whether a cookie is
// set or not. If not, then you can set a cookie with the current time
// as its value. If already set, then check if its time is greater than
// 7 days or not.
$showContent = true;
$datetime = new \DateTime();
$now = $datetime->format('Y-m-d H:i:s'); //current datetime
//check cookie
if(!isset($_COOKIE['pageVisitTime'])) {
setcookie("pageVisitTime", $now, time() + (10 * 365 * 24 * 60 * 60)); /* using a far future date */
} else {
$pageVisitTime = $_COOKIE['pageVisitTime'];
$visitDateTime = new \DateTime($pageVisitTime);
if($visitDateTime->diff($datetime)->days > 7) {
$showContent = false;
}
}
//Depending on value of $showContent you can control your content