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.

<?php

/* 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:
require('includes/config.inc.php');
// 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:
require(MYSQL);

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

// Include the HTML header file:
include('templates/header.html');

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

// Include the HTML footer file:
include('templates/footer.html');
?>

 

Link to post
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.

or

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

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...