有没有办法检测用户是否是第一次访问我的网站,如果是,将他们重定向到一个页面,例如 index-first-time-visitor.php - 如果他们不是第一次访问者,它将它们发送到 index.php
如果有办法做到这一点,请演示如何。
最佳答案
把它放在你的 index.php 的顶部
<?php
if ($_COOKIE['iwashere'] != "yes") {
setcookie("iwashere", "yes", time()+315360000);
header("Location: http://example.com/index-first-time-visitor.php");
}
?>
cookie 将存活 10 年,之后,用户将再次成为"new"访问者。
关于cookies - 检测用户是否是第一次访问者,如果是,则重定向到页面,如果不是,则重定向到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7714522/