Jump to content

Recommended Posts

I've got to ask the same thing. Why store the password (or a hashed version of it) in a session? The only time you care what a password is, is when a visitor enters it in order to authenticate who they are. Once you match the password (or a hashed version of it) with what has been previously stored on the server (in a database or flat-file), you store a value in a session that says the current visitor is authenticated (usually a session variable that holds their username), you don't deal with the password again unless you need the visitor to re-authenticate who they are again.

Link to comment
https://forums.phpfreaks.com/topic/170387-session-question/#findComment-898831
Share on other sites

You would only check the username/password when they login not for every page they view. Instead when they login successfully define a new session variable called is_logged_in and set it to true. Now on every page that requires the user to be logged have the following at the top of the page.

<?php
session_start()
// check if they are logged in
if(!isset($_SESSION['is_logged_in']) || isset($_SESSION['is_logged_in']) && $_SESSION['is_logged_in'] != true)
{
    header('Location: login.php');
    exit;
}

// code for page here

When they logout destroy the session or unset the is_logged_in session variable.

Link to comment
https://forums.phpfreaks.com/topic/170387-session-question/#findComment-898833
Share on other sites

does this have to be set on logging $_SESSION['is_logged_in'] like when i user logos in i set it then

if(!isset($_SESSION['is_logged_in']) || isset($_SESSION['is_logged_in']) && $_SESSION['is_logged_in'] != true)
{
    header('Location: login.php');
    exit;
}

Link to comment
https://forums.phpfreaks.com/topic/170387-session-question/#findComment-899024
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.