First Time Visitor detection PHP script

First Time Visitor detection PHP script

First Time Visitor detection PHP script

With this PHP script you’ll be able to detect if it’s the first time the visitor comes to your website. The technique is simple, by checking and setting a specific cookie, we’ll be able to check if the user has come to the website before.

This technique can come in very handy when you want to trigger actions/content/… to your first time visitors of your website.

<?php
if (!isset($_COOKIE['firsttime']))
{
    setcookie("firsttime", "no", /* EXPIRE */);
    header('Location: first-time.php');
    exit();
}
else
{
    header('Location: site.php');
    exit();
}
?>

About the Author

Daan is a Creative-Geek who loves learning and sharing new techniques! Follow him on Twitter to keep up to date with the Creative-Geeks blog and other subjects. Contact him on e-mail : info[at]creative-geeks.com.