1. Computing

You Last Visited PHP Script

By , About.com Guide

1 of 4

The Full Code
 <?php 
 if(isset($_COOKIE['AboutVisit'])) 
 { 
 $last = $_COOKIE['AboutVisit']; } 
 $year = 31536000 + time() ; 
 //this adds one year to the current time, for the cookie expiration 
 setcookie(AboutVisit, time (), $year) ; 
 if (isset ($last)) 
 { 
 $change = time () - $last; 
 if ( $change > 86400) 
 { 
 echo "Welcome back! <br> You last visited on ". date("m/d/y",$last) ; 
 // Tells the user when they last visited if it was over a day ago 
 } 
 else 
 { 
 echo "Thanks for using our site!"; 
 //Gives the user a message if they are visiting again in the same day 
 } 
 } 
 else 
 { 
 echo "Welcome to our site!"; 
 //Greets a first time user 
 } 
 ?> 
More information about how this script works, and what each section does is on the following pages.
Related Video
Basic PHP Syntax
Using PHP With HTML
  1. About.com
  2. Computing
  3. PHP / MySQL
  4. Step By Steps
  5. Your Last Visit Script - PHP Last Visit Script - Last Time Visited PHP

©2013 About.com. All rights reserved.