【问题标题】:Detect if user is a first time visitor, if so, re-direct to page, if not, re-direct to another page检测用户是否是第一次访问者,如果是,则重定向到页面,如果不是,则重定向到另一个页面
【发布时间】:2011-10-10 14:45:50
【问题描述】:

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

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

【问题讨论】:

  • Cookies、IP 地址存储、会话等...您需要进一步定义您的架构。这过于笼统,无法得到具体答案。
  • 设置一个cookie在他们访问时永不过期(给它9999999999999),如果他们在第二次访问时有cookie,然后将他们重定向到not-first-time-index.php 它并不完美,因为人们总是喜欢清理他们的现金和饼干,但这是最好的。

标签: cookies redirect detect


【解决方案1】:

把它放在 index.php 的顶部

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

cookie 的有效期为 10 年,之后,用户将再次成为“新”访问者。

【讨论】:

  • 我假设 315360000=10 年。你如何计算,比如说,1 个月?
  • @Talha - 真正简单的数学。 315360000 / 10 = 31,536,000(1 年)。 31,536,000 / 12 = 2,628,000(1 个月)。
  • @Talha - 或者您可以使用 Google - 只需写下:1 个月以秒为单位
猜你喜欢
  • 2017-06-25
  • 1970-01-01
  • 2014-06-20
  • 1970-01-01
  • 2019-02-05
  • 2012-01-11
  • 1970-01-01
  • 1970-01-01
  • 2013-01-29
相关资源
最近更新 更多