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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:14:03+00:00 2026-06-05T16:14:03+00:00

I’m pretty new to PHP, but I decided to try and make a simple

  • 0

I’m pretty new to PHP, but I decided to try and make a simple login page on my test website, just to see how things work. I know it’s not very secure, but I’m not worrying too much about that yet. The problem I am having is when I try to login, be the username correct or not, I am redirected to the login page instantly. I don’t think it is even going to the PHP script that checks the username and password or anything, since I get the same results when I use an incorrect username or password. I’m not entirely sure if this is a PHP problem or not, since the form is in HTML, so sorry if it’s not.

Login Page:

<?
include"includes/head.inc";
?>

    <div class="login" align="center";>

    <h1>Log In</h1>

    <form action="/cp/login.php" method="post">

        <table border="0" cellspacing="2" cellpadding="2">
            <tr>
                <td>
                    Email
                </td>
                <td>
                    <input type="text" name="username">
                </td>
            </tr>
            <tr>
                <td>
                    Password
                </td>
                <td>
                    <input type="password" name="password">
                </td>
            </tr>
        </table>

        <input type="submit">

    </form>

    </div>

    <?
    include"includes/footer.inc";
    ?>

Login.php:

<?
$username = $_POST['username'];
$password = $_POST['password'];

session_start();
include"../includes/connect.inc";

$q = "SELECT * from users where email='$username' and password='MD5($password)'";
$result = mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());

if (!$result) {

    echo "<h1>Incorrect username or password.</h1>";

}
else {
    $r              = mysql_fetch_array($result);
    $login_username = $r["email"];
    session_register("login_username");
    Header("Location: protected.php");
}

?>

Protected.php:

<?
session_start();
if ($login_username == "") {
    Header("Location: ../login.php");
}
else {
    include"../includes/head.inc";
    include"../cp.inc";
    include"../includes/footer.inc";
}
?>

I included all the files just in case they are needed, but it seems to just be looping the login page, not cycling through the others. The username and password I am entering are correct, and worked in my previous login system before I rewrote it to make it work better. I hope I’m not missing anything silly or obvious. Thanks for reading.

  • 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-05T16:14:05+00:00Added an answer on June 5, 2026 at 4:14 pm

    Something that might cause this:

    session_start();
    if($login_username=="") {
    

    You’re referring to something inside the session; this is how you should do that:

    session_start();
    if (!isset($_SESSION['login_username']) || $_SESSION['login_username']=="") {
    

    Another small issue:

    <?
    $username=$_POST['username'];
    $password=$_POST['password'];
    
    session_start();
    

    You should test the $_POST keys first before attempting to access them.

    if (!isset($_POST['username'], $_POST['password'])) {
        die("Invalid page request");
    }
    session_start();
    $username=$_POST['username'];
    $password=$_POST['password'];
    

    Last but not least, learn PDO; see also the page here that warns about continued use of mysql_ functions: http://uk.php.net/manual/en/function.mysql-connect.php

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has

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.