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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:32:19+00:00 2026-06-13T18:32:19+00:00

Hello i have problem: in login.php file i’m storing $_SESSION[‘$myusername’]; I try to check

  • 0

Hello i have problem: in login.php file i’m storing $_SESSION[‘$myusername’];
I try to check that SESSIOn username in page.php file, if session not exists it redirects back to login.php. I try to login with valid user but i’m redirecting back to login.php
I dont know where is the problem.

login.php:

 <?php


$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="2"; // Database name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if (isset($_POST['formsubmitted'])) {
    $error = array();//Declare An Array to store any error message 
};  
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM `members` WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_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 "login_success.php"
//store data:
$_SESSION['$myusername'];

//next page:


header("location:page.php");
}

else {

include 'index.php';
$error[] = '<b><h5>Invalid Username or Password!</b>';


if(isset($error) && is_array($error))
{
   echo "<div class='content1'>" . implode("<br />", $error) . "</div>";
};

};
?>

page.php :

<?php
    ob_start();
    session_start();
    if(!isset($_SESSION['$myusername']))
    {
         header("Location: login.php")
    }


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

    In Page.php you shouldn’t include the $ when checking the session variable:

    if(!isset($_SESSION['$myusername']))  
    

    should be:

    if(!isset($_SESSION['myusername']))  
    

    In Login.php you must set the session variable:

    if($count==1){
      // Register $myusername, $mypassword and redirect to file "login_success.php"
      //store data:
      $_SESSION['$myusername'];
      //next page:
      header("location:page.php");
    }
    

    should be:

    if($count==1){
      // Register $myusername, $mypassword and redirect to file "login_success.php"
      //store data:
      $_SESSION['myusername'] = $myusername;
      //next page:
      header("location:page.php");
    }
    

    Login.php also needs a call to session_start() at the top.

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

Sidebar

Related Questions

Hello I have a problem wherein I have to read a huge csv file.
Hello guys i have a problem streaming PDF files with php, i'm using this
Hello i have a big problem .. I'm creating a user login site but
Hello guys I have this code in main.php config file: 'components' => array( '[.........]',
Hello I have a question that could seem complicated. But I will try to
Hello I have problem to put together animations of two separate objects to second
Hello I have a problem with trimming string in c++. It adds some weird
Hello i have the following problem, I record a video using red5 like this:
Hello everyone I have a problem. I want to do a GridView with a
Hello I have a very weird problem in chrome I just cannot figure out!

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.