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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:24:29+00:00 2026-06-14T19:24:29+00:00

I have three files index.php login.php auth.php My login form is based on my

  • 0

I have three files

  • index.php
  • login.php
  • auth.php

My login form is based on my index.php. i including the login.php on the index page.

i want it so when i log in, it will be authenticated by auth.php (which is does) and a message will be displayed on auth.php which says “Your login was successfully” (which is does), however, when it goes back to the index page it comes up with the login form instead of saying “Welcome USER you have successfully logged in.

I believe the error comes from the session mainly because i do not know what else could be wrong.

Here is my code of each page.

Index.php:

<?php include ("login.php"); ?>

login.php

<?php
if ($loggedin){
    echo '<h2>Logged in</h2><p style="font-size:14px;">Welcome '.$user.' you have sucessfully logged in.</p>';
}
else {
     echo '
       <h2>Login</h2>
       <form action="auth.php" method="POST">
       <div class="smallform">
                <p><span>Username:</span><br>
                <input type="text" name="user"></p>
                <p><span>Password:</span><br>
                <input type="password" name="pass"></p>
                <p style="padding-top: 15px"><input type="submit" value="Submit"></p>
        </div>
        </form>';
}
?>

Auth.php:

<?php
session_start();
$con = mysqli_connect("HoST", "USER", "PASS", "DBNAME");
$user = $_POST["user"];
$pass = $_POST["pass"];
$sql = "SELECT UserID FROM Customer 
        WHERE UserID = \"$user\"
        AND Password = md5(\"$pass\")";

$res = mysqli_query($con, $sql);
?>
<!DOCTYPE>
<html>

<head>
<title>VeloCity</title>
<link href="_stylesheet.css" rel="stylesheet" type="text/css" />
<?php echo '<meta http-equiv="refresh" content="1;URL=index.php" />'; ?>
</head>

<body>
<div align="center">
<?php 
if(mysqli_num_rows($res)==1){
    $_SESSION["user"] = $user;
    echo "You have sucessfully logged in";
}
else{
    echo "You have entered an incorrect password. Please try again";
}
?>
</div>
</body>
</html>

Would really appreciate some 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-06-14T19:24:31+00:00Added an answer on June 14, 2026 at 7:24 pm

    With sessions it’s best to put session_start(); right at the very top of the page. Line 1 as this avoids session setting errors.

    On every page you make that you want restricted access to you will need to apply session_start(); on every page.

    There after you can add your custom session rules. So after the database check you’d need to create a session variable within the Auth.php file like so:

    $_SESSION['loggedin']['username']=$_POST['users'];
    $_SESSION['loggedin']['bros'] = md5($_SERVER['HTTP_USER_AGENT']); // To secure not needed in some cases.
    

    Then for every other page you want to check that the session exists.

    if(isset($_SESSION['loggedin'])){
        //view page = true
    }
    

    EDIT :
    better validation;

    if(!isset($_SESSION['loggedin']) || $_SESSION['loggedin']['bros'] !== md5($_SERVER['HTTP_USER_AGENT']))
    {
        die('No access');
        sleep(1);
        header('location:Auth.php');
    }
    

    apply that to the top of the index page and remove the include(Auth.php); that should work better.

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

Sidebar

Related Questions

If I have three files index.php file.php and fns.php First example (it works): index.php
Basically, I have two files, in two different directories: index.php (in /login/) and index.php(in
I have three files; index.php, searchbar.php and search.php now when i have search.php show
I have three files: one called sql.php witch has a class db that I
I have three files in a folder 'test' one.php two.php print.html And i have
I have three source files in a folder. I simply want to compile them
I have a simple login page and the URL structure is like www.mydomain.com/admin/auth I
I have an index.php with the following content: include_once('includes/auth.php'); include_once('classes/class.DatabaseQuery.php'); include_once('classes/class.Project.php'); include_once('classes/class.User.php'); $project =
I have three files: lib.c lib.h => They should be built as a .so
I have three files: movie.h (header); movie.cpp (implementation file); lab9.cpp (driver file using movie

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.