Cookies 检测用户是否是第一次访问,如果是,请重新指向页面,如果不是,请重新指向其他页面

Cookies 检测用户是否是第一次访问,如果是,请重新指向页面,如果不是,请重新指向其他页面,cookies,redirect,detect,Cookies,Redirect,Detect,是否有方法检测用户是否是第一次访问我的网站,如果是,将他们重定向到一个页面,例如index-first-time-visitor.php,如果他们不是第一次访问,它会将他们发送到index.php <?php if ($_COOKIE['iwashere'] != "yes") { setcookie("iwashere", "yes", time()+315360000); header("Location: http://example.com/index-first-t

是否有方法检测用户是否是第一次访问我的网站,如果是,将他们重定向到一个页面,例如index-first-time-visitor.php,如果他们不是第一次访问,它会将他们发送到index.php

<?php
if ($_COOKIE['iwashere'] != "yes") { 
  setcookie("iwashere", "yes", time()+315360000);  
  header("Location: http://example.com/index-first-time-visitor.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年,此后,用户将再次成为“新”访问者。

cookie、IP地址存储、会话等。。。您需要进一步定义您的体系结构。这太宽泛了,无法得到具体的答案。设置一个cookie在他们访问时永不过期(给它9999999999),如果他们在第二次访问时有cookie,那么将其重定向到not-first-time-index.php这不是完美的,因为人们喜欢随时清除他们的现金和cookie,但这是你能得到的最好的,我想315360000=10年。比如说,你是如何计算1个月的?@Talha-真的很简单。315360000/10=31536000(1年)。31536000/12=2628000(1个月)。@Talha-或者你可以使用谷歌-只需写:1个月的秒数