rnlogout.php

The final ingredient in our social networking recipe is Example 20-13, rnlogout.php, the logout page that closes a session and deletes any associated data and cookies. The result of calling up this program can be seen in Figure 20-8, where the user is now asked to click on a link which will take them to the un-logged-in home page and remove the logged-in links from the top of the screen. Of course, you could write a JavaScript or PHP redirect to do this, and this is probably a good idea in order to keep logging out looking clean.

The logout page
Figure 20-8. The logout page
Example 20-13. rnlogout.php
<?php // rnlogout.php
include_once 'rnheader.php';

if (isset($_SESSION['user']))
{
destroySession();
echo "<h3>Log out</h3>You have been logged out. Please
<a href='index.php'>click here</a> to refresh the screen.";
}
else echo "<h3>Log out</h3>You are not logged in";
?>

And that, as they say, is that. If you write anything based on this code, or any other examples in this book, or have gained in any other way from it, then I’m glad to have been of help, and thank you for reading this book.

But before you go out and try out your newly learned skills on the Web at large, please take a browse through the appendices that follow, as there’s a lot of additional information there you should find useful.

Get Learning PHP, MySQL, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.