Page 462 - Beginning PHP 5.3
P. 462
Part III: Using PHP in Practice
Creating a Logout Function
As well as being able to log in to the members ’ area, members need to be able to logout when they ’ ve
finished their session. To do this, create a simple script that clears the $_SESSION[ “ member “ variable.
]
Save the following file as logout.php in your members folder:
< ?php
require_once( “../common.inc.php” );
session_start();
$_SESSION[“member”] = “”;
displayPageHeader( “Logged out”, true );
? >
< p > Thank you, you are now logged out. < a href=”login.php” > Login
again < /a > . < /p >
< ?php
displayPageFooter();
? >
When viewed, this page immediately logs the member out, then displays a thank - you message, along
with a link inviting them to log in again.
Creating the Pages for the Members ’ Area
You ’ ve now built the nuts and bolts of your members ’ area. The only thing left to do is to create some
dummy pages for the members ’ area. Create the following four pages in the members folder that you
created earlier.
index.php:
< ?php
require_once( “../common.inc.php” );
checkLogin();
displayPageHeader( “Welcome to the Members’ Area”, true );
? >
< p > Welcome, < ?php echo $_SESSION[“member”]- > getValue( “firstName” ) ? > !
Please choose an option below: < /p >
< ul >
< li > < a href=”diary.php” > Upcoming events < /a > < /li >
< li > < a href=”books.php” > Current reading list < /a > < /li >
< li > < a href=”contact.php” > Contact the book club < /a > < /li >
< li > < a href=”logout.php” > Logout < /a > < /li >
< /ul >
< ?php displayPageFooter(); ? >
424
9/21/09 9:14:10 AM
c14.indd 424 9/21/09 9:14:10 AM
c14.indd 424