Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi Larry,

My logout message "You are now logged out." from my logout.php script (below) reverts back to the default language (English) when the user logs out. How do I get the $_SESSION['lid'] = $row['lang_id'] to remain valid until just after the user logged out so that the logout message displays in the user's selected language?

Thank you.


/* This script:
 - is the sign out page for the site.
 - calls the configuration script.
 - redirects invalid users.
 - opens the database connection.
 - destroys the variables, session and cookie.

// Require the configuration before any PHP code as the configuration controls error reporting:
// The config file also starts the session.

// Redirect invalid user:
if (!isset($_SESSION['user_id'])) {
	$url = 'index.php'; // Define the URL.
	header("Location: $url");
	exit(); // Quit the script.

// Destroy the session:
$_SESSION = array(); // Destroy the variables.
session_destroy(); // Destroy the session itself.
setcookie (session_name(), '', time()-300); // Destroy the cookie.

// Require the database connection:

// Include the page title:
$page_title = $words['signout_page_title_1'];

// Include the HTML header file:

// Print a message:
echo '<h2 class="display-5 my-2 font-weight-normal">' . $words['log_out_message'] . '</h2>';

// Include the HTML footer file:


Link to comment
Share on other sites

Ah, good question! There are two options:

A. Use the current code but before the current session is destroyed, copy the lang ID to a new variable and then after the current session and cookie are destroyed, start a new session and store the lang ID in that using the variable.


B. Don't clear and destroy the session in this script, only remove those session elements that represent "being logged in". 

Link to comment
Share on other sites


  • Create New...