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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:50:11+00:00 2026-06-16T03:50:11+00:00

I have a login page where i have to : insert user and password

  • 0

I have a login page where i have to : insert user and password (1 time); click the button(the login button) twice to actually login.I use Xamp with PHP 5.3 and HeidiSQL .If i’m already in session, it skips the login window and redirects to content page else the form is submitted(which is what i want it to do).This is my code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
 session_start();
 include("../conect.php");



 if(isset($_SESSION['name']))

 { 
    $username = $_SESSION['name']; 
    $pass = $_SESSION['pass'];
    $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());

    while($info = mysql_fetch_array( $check ))  
        {
                if ($pass != $info[2]){
                    header('.<?php $_PHP_SELF ?>.');  
                }

                else
                    {   if($_SESSION['role']==0) 
                        header("Location: content0.php");

                        if($_SESSION['role']==1) 
                        header("Location: content1.php");

                        if($_SESSION['role']==2) 
                        header("Location: content2.php");
                    }
        }
 }


 //if the login form is submitted 

 if (isset($_POST['login'])) { 
    $nume=mysql_real_escape_string($_POST['username']);
    $parola=md5(mysql_real_escape_string($_POST['pass']));
    if((!$_POST['username']) || (!$_POST['pass'])) {

        die('You did not fill in a required field.');

    }

    $check_pass = mysql_query("SELECT * FROM users WHERE username = '$nume'")or die(mysql_error());
    $check2 = mysql_num_rows($check_pass);

    if ($check2 == 0) {
        die("That user does not exist in our database");
    }

    while($data = mysql_fetch_array( $check_pass )) {
            //gives error if the password is wrong
            if ($parola != $data[2]) {

                die('Incorrect password, please try again.');
            }
            else {  
                        $result = mysql_query("SELECT * FROM users WHERE username = '$nume'")or die(mysql_error());
                        while($data=mysql_fetch_row($result)){
                            $_SESSION['name']=$data[1];
                            $_SESSION['pass']=$data[2];
                            $_SESSION['role']=$data[3];
                        }
                    }
                } 

} 


mysql_close($con);
?>

<html>

<head>
<title>Login</title>
<link rel="stylesheet" href="/css/butoane.css" type="text/css" />
<link rel="stylesheet" href="/css/admin_tools.css" type="text/css" />
<script>

</script>
</head>
<body id="login_background">

<div id="ambele">
<div class="form_box">

    <form action="<?php $_PHP_SELF ?>" method="post">
    <label for="username">Username</label><input type="text" id="username" name="username" maxlength="40"/>
    <label for="password">Password</label><input type="password" id="password"name="pass" maxlength="20"/>
    <input type="submit" name ="login" value="Login" class="button"/>
    </form>
</div>

<div id="register"> 
<a href="registration_form.php" id="reg">Not registered yet? Go to Registration</a>
</div>

</div>

</body>

</html>
  • 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-16T03:50:13+00:00Added an answer on June 16, 2026 at 3:50 am

    I think you need to exit your script to do redirection.

    <?php
    header('Location: content.php');
    die();
    ?>
    

    Also, you put the PHP tag in the wrong position.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?php
    [...]
    ?>
    [...]
    

    This will cause the Headers already sent error in PHP because you already send something to the client before you do redirection.

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

Sidebar

Related Questions

Normally we have login page with username, password filed and signin button. Using the
I have a login page. When the user enters valid Username and Password another
I have a Login page that captures User input like this. MD5calc ss =
Scenario: I have a login page which uses ajax to validate a user and
I have the following php pahe which accepts the user's first name and password
I have a login page (an activity in Android), during which I run an
I have a login page written in classic asp. I want to set the
I have created login page forced login in several pages. Now i need to
I'm using ASP.NET MVC 2 and have a login page that is secured via
I have a Login.aspx page, and I wanna incude some piece of code 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.