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 8752051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:09:30+00:00 2026-06-13T13:09:30+00:00

I am trying to store a session variable in the login page and then

  • 0

I am trying to store a session variable in the login page and then carry it over to the member page but for some reason the session variables are not storing when you go over to the member page.

<?php
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];

?>

then a bunch of html. then next php code is…

<?php

$form = "<form action='login.php' method='post'>
<table>
<tr>
<td><input type='text' name='user' /></td>
</tr>
<tr>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td><input type='submit' name='loginbtn' value='Login' /></td>
</tr>
</table>
</form>";

if ($_POST['loginbtn']) {
$user = $_POST['user'];
$password = $_POST['password'];

if ($user) {
    if ($password){
        require("connect.php");

        $password = md5(md5("kjfiufj".$password."GSA54"));
        //make sure login info is correct
        $query = mysql_query("SELECT * FROM users WHERE username='$user'");
        $numrows = mysql_num_rows($query);

        if ($numrows == 1) {
            $row = mysql_fetch_assoc($query);
            $dbid = $row['id'];
            $dbuser = $row['username'];
            $dbpassword = $row['password'];
            $dbactive = $row['active'];

            if ($password == $dbpassword) {
                if ($dbactive == 1) {
                //set session info
                    $_SESSION['userid'] = $dbid;
                    $_SESSION['username'] = $username;


                    echo "logged in as        <strong>$dbuser</strong>. <a href='member.php'>Click here</a> to go to the member page.";
                }
                else
                    echo "User not active";
            }
            else
                echo "Wrong password.";
        }
        else
            echo "The username you entered was not found";

        mysql_close();
    }
    else 
        echo "What's the password brah?";


}
else 
    echo "What's the user name brah?";



}
else 
    echo $form;
?>

The code for the member page is

    <?php
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];

?>

<?php
if ($username && $userid) {
    echo "Welcome <strong>$username</strong>,<a href='logout.php'>Logout</a>.";
}

else
    echo "Please login to acces this page <a href='login.php'>Login here</a>";



?>
  • 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-13T13:09:32+00:00Added an answer on June 13, 2026 at 1:09 pm

    Are you calling session_start() in your login page?

    You have to call session_start() in every page that is going to access session variables if you have not set session.auto_start runtime configuration option to true.

    EDIT

    Actually, your $_SESSION['userid'] probably isn’t empty, because you’re actually assigning a defined variable to it as $_SESSION['userid'] = $dbid;

    However, you are creating your $_SESSION['username'] by assigning the value of $username to it which seems to be undefined.

    Maybe

    $_SESSION['username'] = $username;
    

    should be

    $_SESSION['username'] = $dbuser;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to store the user's ID in the session using django.contrib.auth.login . But
I’m trying to store an array in a session variable then use it latter
I am trying to store sub-query result in session variable using MySQL, but the
I'm trying to store a std::map on a shared memory segment. But I'm not
Trying to add some extra elements to my session variables for filesystem directory work,
I am trying to get Session Value and store in the variable.. how can
I am trying to store a UserID in a session variable in Google App
I'm trying to get value from dropdown box into variable and then store it.
I am trying to pass a session variable from one page to another using
I was trying to set a session in mvc to store the current user

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.