In this project, you will create a cookies program that stores the date
and time of a user’s last visit.
1. Create a new document in your text editor and type the
declaration, element, header information,
and element. Use the strict DTD and “Last Visit” as
the content of the element.
2. Add the following script section above the
3. Add the following if...else statement to the script sec-
tion to assign a value to the $LastVisit variable. If the
$_COOKIE['lastVisit'] variable is set, the date and time of
the last visit is assigned to the $LastVisit variable. Otherwise,
the variable is assigned a value of “This is your ﬁrst visit!”
$LastVisit = "Your last visit was on "
$LastVisit = "This is your first visit!\n";
4. Add the following statement to the end of the script sec-
tion. The statement uses the date() function with the
setcookie() function to assign the date to the $LastVisit
variable. Notice that the cookie is set to expire in one year.
setcookie("lastVisit", date("F j, Y, g:i a"),
5. To the document body, add the following output directive,
which displays the value of the $LastVisit variable:
6. Save the document as LastVisit.php in the Projects direc-
tory for Chapter 9, and then close the document in your text
7. Open the LastVisit.php ﬁle in your Web browser by enter-
ing the following URL: http:///PHP_Projects/
Chapter.09/Projects/LastVisit.php. The ﬁrst time you open the
page, you should see “This is your ﬁrst visit!” in the browser
window. Reload the Web page; you should see the date and
time in the browser window.
8. Close your Web browser window.