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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:51:20+00:00 2026-05-30T23:51:20+00:00

I am using PHP to build a very basic login script . However, the

  • 0

I am using PHP to build a very basic login script. However, the else from the ifelse statement shows by default before the user has even clicked log in.
Before the user has even tried to login they are greeted with this:

Warning: Cannot modify header information - headers already sent by (output started at /home/madhous3/public_html/dev/admin/index.php:12) in /home/madhous3/public_html/dev/admin/login.php on line 13
Sorry, please try again.

How do I stop this? However, if the user enters the details correctly, they are directed to the right page.

Code

index.php

   <?php 
        include("login.php"); 
        ?>
        <h1>Admin Area Login</h1>



        <form method="post" action="login.php">
        Username<input type="text" name="username" />
        Password<input type="text" name="password" />
        <input type="submit" name="log_in" value="Log In" />

        </form>

login.php

<?php 

$username_inputted = $_POST['username'];
$password_inputted = $_POST['password'];


if($username_inputted == 'admin' && $password_inputted == 'password'){

header("location:login_success.php");


}else{
header("location:index.php");
echo "Sorry, please try again."; 
}



?>
  • 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-30T23:51:21+00:00Added an answer on May 30, 2026 at 11:51 pm

    Try removing the include(“login.php”) from index.php.

    Instead, you should redirect back to index.php from your login.php with a flag specifying that the user entered the wrong information (if they failed the login).

    index.php

    <?php
        if(isset($_REQUEST['fail'])) {
            echo 'Login failed.';
        }
    ?>
    <h1>Admin Area Login</h1>
    <form method="post" action="login.php">
    Username<input type="text" name="username" />
    Password<input type="text" name="password" />
    <input type="submit" name="log_in" value="Log In" />
    </form>
    

    login.php

    <?php 
    
    $username_inputted = $_POST['username'];
    $password_inputted = $_POST['password'];
    
    if($username_inputted == 'admin' && $password_inputted == 'password'){
        header("location:login_success.php");
    } else {
        header("location:index.php?fail=1");
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a script that receives json data from a php script using
Using PHP and MySQL, I have a forum system I'm trying to build. What
I am using PHP and jQuery to build an interactive timeline which needs to
I am using MySQL and PHP to build a data layer for a flash
I build a css file using PHP which allows me to easily customize the
I am trying to build a Connect app using PHP and the Zend Framework.
I'm using CodeIgniter (a PHP framework) to build an app, and I have an
I'm using the DOM extension in PHP to build some HTML documents, and I
I built a very simple app using a PHP form with a bit of
I know very little about XML. I build reports exported from Quickbooks based in

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.