PHP progarm to display last visited time on web page

By | September 18, 2014

PHP progarm to store current date-time in a COOKIE and display the ‘Last visited on’ date-time on the web page upon reopening of the same page.


<?php
//date_default_timezone_set('Asia/Calcutta');

//Calculate 60 days in the future
//seconds * minutes * hours * days + current time

$inTwoMonths = 60 * 60 * 24 * 60 + time();
setcookie('lastVisit', date("G:i - m/d/y"), $inTwoMonths);
if(isset($_COOKIE['lastVisit']))

{
$visit = $_COOKIE['lastVisit'];
echo "Your last visit was - ". $visit;
}
else
echo "You've got some stale cookies!";
?>


OUTPUT:

Your last visit was - 23:42 - 12/09/10



Author: Ravi Bandakkanavar

A Techie, Blogger, Web Designer, Programmer by passion who aspires to learn new Technologies every day. It has been 6 years since I have been publishing articles and enjoying every bit of it. I want to share knowledge and build a great community with people like you.

Suggested read for you:

2 thoughts on “PHP progarm to display last visited time on web page

Did it help? Comment here..