Redirect First Time Website Visitors

27. January 2012 12:32 by Matt in Information Technology Adventures  //  Tags: , , , ,   //   Comments (0)

submit to reddit

Using browser cookies is an easy way to detect if a website visitor has been to your page before.  This PHP code will allow you set a cookie in your user's browser and redirect them to another web page if they have not visited your site or page before. 

Use the code below within the <head></head> tags of your index.php page.



if ($_COOKIE['firstvisit'] != "yes") { 

  setcookie("firstvisit", "yes", time()+315360000);  





Then set the name of the cookie, ("firstvisit" in this case) set the amount of time the cookie will be registered in the browser, (315360000 corresponds to 1 year in seconds) and set the redirect location.

This is a simple and quick option for sites that may want to redirect to an intro page or even a webform that can capture information prior to letting users reach content.

Add comment

  Country flag

  • Comment
  • Preview

LinkedIn Subcribe to Our RSS Feed

Matt Gonzalez

Currently working as the IT Director for Vitech Corporation, a leading Systems Engineering solutions provider.  

I train at Gold's Gym 6 days a week with emphasis on the core lifts. (deadlifts, squats, and presses)