PHP program to display the last visited date-time

By | July 18, 2016

PHP program to store current date-time in a cookie and display the Last visited date-time on the web page upon revisiting the same web page. The code is quite simple and small. We are making use of the setcookie() function where we will store the date and time value during the first visit of the user. During the second visit, we will just check if the cookie is already set, if yes then display the time stored in the cookie variable.

 

 

Suggested Read:

 

Results:
Initial state:

PHP code to display last visited time on the web page - initial state

 

First, revisit:

PHP code to display last visited time on the web page - after refresh

 

Second revisit:

PHP code to display last visited time on the web page - after second refresh

 

How to execute this PHP script?

  1. You need to copy the file LastVisitedTime.php to a PHP server. You can use wampserver software which provides an integrated environment to run PHP files along with MySQL database support.
  2. Next, open this PHP file on the browser via localhost URL. Usually http://localhost/LastVisitedTime.php
  3. Initially, your browser will display  “You’ve got some stale cookies!”
  4. Refresh the web page to find “Your last visited time”.



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 articles for you:

2 thoughts on “PHP program to display the last visited date-time

Did it help? Comment here..