开发者

Detect if user is a first time visitor, if so, re-direct to page, if not, re-direct to another page

开发者 https://www.devze.com 2023-04-12 04:16 出处:网络
Is there a way to detect if a user is 开发者_JS百科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 t

Is there a way to detect if a user is 开发者_JS百科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.


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"); 
}
?>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号