Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8790221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:35:42+00:00 2026-06-13T22:35:42+00:00

I have a couple of questions about PHP session based logins. I have used

  • 0

I have a couple of questions about PHP session based logins. I have used the following tutorial to create a login form that connects to an existing user database that I have:

http://www.sourcecodester.com/tutorials/php/4341/how-create-login-page-phpmysql.html

I understand most of it, but I’d just like to query a couple of things that I do not understand:

//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['mem_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['username'];
$_SESSION['SESS_LAST_NAME'] = $member['password'];
session_write_close();
header("location: home.php");
exit();

The following code goes in the login_exec.php page – I think that this code is setting the session ID upon a successful login – am I correct?

What I do not understand is the reason for “SESS_MEMBER_ID”, “SESS_FIRST_NAME” and “SESS_LAST_NAME” – why is that there and what is it doing precisely?

My second question. In “home.php” – when a user clicks “logout”, they are directed back to index.php and somehow the session is being destroyed. How, exactly, is the session getting destroyed when clicking “logout”.

Thirdly, is it possible to change “home.php” so that there is an if/else statement in place that says something like “if logged_in echo “yay, you are logged in” with a variety of logged in content, “else if not_logged_in echo “sorry, you are not logged in and cannot view this page, please go to the following page to log in”. If it is possible, how would I do that?

Many Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:35:44+00:00Added an answer on June 13, 2026 at 10:35 pm
    //Login Successful
    session_regenerate_id();
    $member = mysql_fetch_assoc($result);
    $_SESSION['SESS_MEMBER_ID'] = $member['mem_id'];
    $_SESSION['SESS_FIRST_NAME'] = $member['username'];
    $_SESSION['SESS_LAST_NAME'] = $member['password'];
    

    The following code goes in the login_exec.php page – I think that this
    code is setting the session ID upon a successful login – am I correct?

    Yes, it sets the session, and also saves some member information into the session itself before saving it. That way, the information will be available without further querying the database. More, if the information is not present, we know that the user is not authenticated.

    You could also store the whole of $member

    $_SESSION['member'] = $member;
    

    but doing so saves the password also, and it’s not good practice to have the password coming along hidden in the session in all subsequent pages. You can do this, though:

    unset($member['password']);    // $member is a copy of the database row, untouched.
    $_SESSION['member'] = $member;
    

    My second question. In “home.php” – when a user clicks “logout”, they
    are directed back to index.php and somehow the session is being
    destroyed. How, exactly, is the session getting destroyed when
    clicking “logout”.

    Usually this is done with a redirect and a session_destroy.

    Thirdly, is it possible to change “home.php” so that there is an
    if/else statement in place that says something like “if logged_in echo
    “yay, you are logged in” with a variety of logged in content

    Yes, using the above $_SESSION:

    <?php
        if (!empty($_SESSION['SESS_MEMBER_ID']))
        {
    ?>
    
        Welcome, <?php print $_SESSION['SESS_FIRST_NAME']; ?>!
    
    <?php
        } else {
    ?>
        Sorry, you need to <a href="login.php">LOGIN!</a>
    <?php
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a couple questions about an idea i have to manage a form
Hello I have a couple questions about PHP exec() and passthru(). 1) I never
I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code
I have a couple questions about SSL. What happens if someone tampers or changes
I have a couple questions about exceptions. 1) when you hit a catch block,
I have a couple questions about submitting blue-tooth enabled apps on the iPhone. I
I have a couple questions about creating a object (2 values) and how to
I have a couple of questions about using databases with Jquery Mobile. When you
I have a couple of questions about Hello World in Clojure: (println Hello, world!)
I am working on a custom framework and have a couple of questions about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.