21.10. How to create a Logout module

Figure 21-4. Logout link in the Modules block.

Logout link in the Modules block.

Do you consider it too much work for your registered users to have to click on the “Your Account” link in the Modules block, be directed to their personal account page, then have to click on “Logout” in order to get logged out of your site? Why not have a direct “Logout” link in the Modules block? Well, since all links in the Modules block are automatically created from the active modules (unless you created a custom Modules block along the lines of Section 17.2), asking for a Logout link in the Modules block is asking for a Logout module!

In fact, it is easy to construct a Logout module - and is another example of using Javascript in modules (see Section 21.9):

Create a new folder, call it Logout, in the modules directory. In the Logout folder, create an index.php file that contains (see Add "Logout" to Modules Block):

<?php
echo "
<script type=\"text/javascript\">
top.location.replace ('modules.php?name=Your_Account&file=index&op=logout')
</script>
"
?>

Activate the Logout module from the administration panel. From now on, a Logout link will appear in the Modules block - it will log a registered user immediately upon clicking on it.