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

Please Share: Tweet about this on TwitterShare on FacebookShare on Google+Share on RedditPin on PinterestShare on LinkedInDigg thisShare on StumbleUponShare on TumblrBuffer this pageShare on VKEmail this to someone

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

Leave a Reply

Your email address will not be published. Required fields are marked *