[Previous] [Contents] [Next]


Logout script


A separate script is called when a user logs out of the application. Example 9-10 shows the script that unregisters the $authenticatedUser session variable, registers the $loginMessage variable containing the appropriate message, and relocates back to the login script. The login script checks if the $loginMessage session variable is registered and displays the message that the user has logged out.

Example 9-10. Logout script
<?php
  session_start(  );

  $appUsername =
     $HTTP_SESSION_VARS["authenticatedUser"];

  $loginMessage =
    "User \"$appUsername\" has logged out";

  session_register("loginMessage");

  session_unregister("authenticatedUser");

  // Relocate back to the login page
  header("Location: example.9-8.php");
?>

[Previous] [Contents] [Next]