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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:20:47+00:00 2026-05-21T22:20:47+00:00

I been doing alot of research with php logins and how they work for

  • 0

I been doing alot of research with php logins and how they work for a while. I came across this site a couple of days ago. http://www.intechgrity.com/create-login-admin-logout-page-in-php-w/#comment-25300. Looking at it I notice that it was using session_register which is a huge problem in PHP 5.3. I begin playing around with it and I got the login part to work with no problem, but for some reason I can’t get the username to show in the header of the admin page. What I want is: <h1>Welcome To Admin Page Username</h1> and it gives me <h1>Welcome To Admin Page</h1>. I was wondering if it’s because I have 2 sessions using the same var?

My changes from the tutorial:

check_login.php –

    <?php
define(DOC_ROOT,dirname(__FILE__)); // To properly get the config.php file
$username = $_POST['username']; //Set UserName
$password = $_POST['password']; //Set Password
$msg ='';
if(isset($username, $password)) {
    ob_start();
    include(DOC_ROOT.'/config.php'); //Initiate the MySQL connection
    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($username);
    $mypassword = stripslashes($password);
    $myusername = mysqli_real_escape_string($dbC, $myusername);
    $mypassword = mysqli_real_escape_string($dbC, $mypassword);
    $sql="SELECT * FROM login_admin WHERE user_name='$myusername' and user_pass=SHA('$mypassword')";
    $result=mysqli_query($dbC, $sql);
    // Mysql_num_row is counting table row
    $count=mysqli_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1){
        // Register $myusername, $mypassword and redirect to file "admin.php" 
        $_SESSION["admin"]= $myusername;
        $_SESSION["password"]= $mypassword;
        $_SESSION["name"]= $myusername;
        header("location:admin.php");
    }
    else {
        $msg = "Wrong Username or Password. Please retry";
        header("location:login.php?msg=$msg");
    }
    ob_end_flush();
}
else {
    header("location:login.php?msg=Please enter some username and password");
}
?>

admin.php –

<?php
session_start(); //Start the session
define(ADMIN,isset($_SESSION["name"])); //Get the user name from the previously registered super global variable
if(isset($_SESSION["admin"])){ //If session not registered
header("location:login.php"); // Redirect to login.php page
}
else //Continue to current page
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Welcome To Admin Page Demonstration</title>
</head>
<body>
    <h1>Welcome To Admin Page <?php echo ADMIN /*Echo the username */ ?></h1>
    <p><a href="logout.php">Logout</a></p> <!-- A link for the logout page -->
    <p>Put Admin Contents</p>
</body>
</html>

These are the only 2 pages I did changes. Thanks for any help.

UPDATE: I tired the changes from everyone who answer and still got a blank. I just going to give up on it. It puzzles me how it work with the old code but not with the new code. Thanks for all the help.

UPDATE 2: Got it to work thanks to Gumbo suggestion about using var_dump();. What I did is I took everything from *check_login.php* and placed it into the admin.php and went from array(0){} to array(3) { ["username"]=> string(6) "admin" ["admin"]=> string(6) "admin" ["password"]=> string(5) "************" }.

Thanks everyone for all of your help.

  • 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-05-21T22:20:47+00:00Added an answer on May 21, 2026 at 10:20 pm

    isset does only return a boolean value depending on whether the given variable exists or not; but it does not return the variable value if it exists.

    Do this instead:

    session_start();                  // Start the session
    if (!isset($_SESSION["admin"])) { // If session not registered
        header("location:login.php"); // Redirect to login.php page
        exit;                         // Stop execution of current script
    } else {
        header('Content-Type: text/html; charset=utf-8');
        define('ADMIN', $_SESSION["name"]); //Get the user name from the previously registered super global variable
    }
    

    And note that you’ve used $_SESSION["name2"] and not $_SESSION["name"] in your check_login.php.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been doing research on HTML canvas libraries and I came across this
I've been doing research on this for the past 2, almost 3 days now.
I have been doing a lot of research trying to figure this out, but
I've been doing some web development work in PHP recently which has led me
I have been doing a lot if research into this, but I havent found
I've been doing a lot of research on web platforms (mainly .Net vs Java),
I have been doing a lot of research on the internet with regards to
After doing some research on the subject, I've been experimenting a lot with patterns
I've been doing alot of testing with my new MVC App and now I'm
I've been doing alot of XML processing in C# of late and after coming

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.