Web design tools - 5. Finally, create the fifth file, testcookie.php: Beginning

5. Finally, create the fifth file, testcookie.php:

This is the Test Cookie Page

No cookie was set.
Click here to set your cookie. Your cookies were set:
Username cookie value:
Password cookie value:

How It Works We ran through this cookie example to show you how you can keep persistent logins between single browser sessions. As you may have noticed, some of the pages are just display or navigation pages. For that reason, we won t explain those. We will focus instead on setcookie_un.php, setcookie_pw.php, and testcookie.php. The setcookie_un.php page does just what the name says: It sets the cookie for the username, which is just hard-coded for this example. It then uses a header redirect to send you to the next page. That next page is setcookie_pw.php, which does the same as setcookie_un.php, except that it is setting the cookie for the password. Then you re redirected to a simple display page that tells you your cookies have been set. You can then navigate to testcookie.php. This page checks to see if the cookie values are valid. If they are not, it says No cookies were set, and you can try to set the cookies again. If you are successful in your login, the screen will look like the one in Figure 12-16. If you need to delete or end a cookie, simply run some code (such as the code that follows) to end the cookie from the user s browser. setcookie( username , , time() - 3600); This sets the username cookie for one hour ago and sets the username value to an empty string, thereby making the username cookie unavailable to the Web site the user is logged into. 401 User Logins, Profiles, and Personalization
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Leave a Reply