检测用户是否是第一次访问者,如果是,则重定向到页面,如果不是,则重定向到另一页面

Zac*_*ous 2 cookies redirect detect

有没有一种方法,如果用户访问我的网站,第一次检测,如果是这样,他们重定向到一个页面,例如,指数首次-visitor.php - 如果他们不是第一次访问,它将它们发送到index.php

如果有办法做到这一点,请演示如何.

小智 10

把它放在index.php的顶部

<?php
if ($_COOKIE['iwashere'] != "yes") { 
  setcookie("iwashere", "yes", time()+315360000);  
  header("Location: http://example.com/index-first-time-visitor.php"); 
}
?>
Run Code Online (Sandbox Code Playgroud)

该cookie将存活10年,之后,用户将再次成为"新"访问者.

  • @Talha - 简单的数学真的.315360000/10 = 31,536,000(1年).31,536,000/12 = 2,628,000(1个月). (2认同)