As I mentioned before, this script doesn't work on my server. So I'm including the code that would create a reusable logout button.

This entire code is stored in the include file.

  1. <?php

  2. // run this script only if the logout button has been clicked

  3. if (array_key_exists('logout', $_POST)) {

  4. // empty the $_SESSION array

  5. $_SESSION = array();

  6. // invalidate the session cookie

  7. if (isset($_COOKIE[session_name()])) {

  8. setcookie(session_name(), '', time()-86400,'/');

  9. }

  10. // end session and redirect

  11. session_destroy();

  12. header ('Location: http://jessicahough.com/location-of-login-form/);

  13. exit;

  14. }

  15. ?>

  16.  

  17. <form id="logoutForm" name="logoutForm" method="post" action="">

  18. <input name="logout" type="submit" id="logout" value="Log out" />

  19. </form>

Now, when I add this line of code...

  1. <?php include('/location-of-include/file.php'); ?>

...to any page, the logout button will appear and be fully functional.