Detect if user is a first time visitor, if so, re-

2020-06-23 21:15发布

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.

1条回答
够拽才男人
2楼-- · 2020-06-23 21:47

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.

查看更多
登录 后发表回答