检测用户是否是首次访问者,如果是,则重定向到页面,如果不是,则重定向到另一个页面 [英] Detect if user is a first time visitor, if so, re-direct to page, if not, re-direct to another page

查看:76
本文介绍了检测用户是否是首次访问者,如果是,则重定向到页面,如果不是,则重定向到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to detect if a user is visiting my website for the first time, and if so, redirect them to a page, for example, index-first-time-visitor.php - and if they are not a first time visitor, it sends them to index.php

如果有办法,请演示如何操作。

If there is a way to do this, please demonstrate how.

推荐答案

将其放在index.php的顶部。

Put this at the top of your index.php

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

该Cookie的有效期为10年,之后用户将再次成为新访问者

The cookie will live for 10 years, after that, a user will be a "new" visitor again.

这篇关于检测用户是否是首次访问者,如果是,则重定向到页面,如果不是,则重定向到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆