1. Home
  2. Computing & Technology
  3. PHP / MySQL

You Last Visited PHP Script

By Angela Bradley, About.com

3 of 4

Welcome Back

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
}
}
This code first checks if $last is set. If you remember from the last step, $last is the time the visitor was last at the site. If they have visited before it then runs through two options. If the visitor has visited within the last day, it simply thanks them for visiting the site. If however the visitor visited over 1 day (86,400 seconds) ago, the message welcomes them back and reminds them of when they last visited.

3 of 4

Index: You Last Visited PHP Script

  1. The Full Code
  2. Setting and Retrieving the Cookie
  3. Welcome Back
  4. New Users

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. Your Last Visit Script - PHP Last Visit Script - Last Time Visited PHP

©2008 About.com, a part of The New York Times Company.

All rights reserved.