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

标签 cookies redirect detect

有没有办法检测用户是否是第一次访问我的网站,如果是,将他们重定向到一个页面,例如 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/

相关文章:

Android:检测到用户打开状态栏

vue.js - 在 VueJS 上使用 axios 全局设置 WithCredentials

java - CAS 单点登录过滤器

javascript - 使用 jQuery 页面重定向后向列表元素添加类

python - 我正在尝试检测按下的某个键(Python)

jquery - 检测文本区域中的内容(jQuery)

python - 如何使用 pyramid cookie 在 tornado web 框架中对用户进行身份验证?

session - 在Grails 3.0中更改 session Cookie名称

.htaccess RewriteRule subsubdomain.subdomain.domain.tld 到 subdomain.domain.tld/subsubdomain

javascript - 处理来自 http 响应的重定向