Jump to content

Displaying "include" page but not the main page...


elmas156

Recommended Posts

Hello everyone.  I'm having a problem with what should be a fairly simple login system that is included on the index page of my site.  Basically, it is set up to display a short form so that the user can enter his/her email address and password to log in.  If there is a mistake with the email/password, it displays the same form with a notification that there was an incorrect email or password.  The problem that I'm having is that when the wrong email/password is entered, the page goes to the next step of notifying the user of the incorrect information but it does not display the rest of the page that it is included on.  What is happening is when the user arrives at the site it displays the index.php page, which is currently a blank page with some simple text, and the included page mentioned above.  When an incorrect email/password is entered, instead of staying on the index page and displaying the included page with the login form, the user is redirected away from the index page to the included page only.

 

Here's my code for "head.inc.php":

 


<?php
include("conf.inc.php"); // Includes the db and form info.
session_start(); // Starts the session.
if ($_SESSION['logged'] == 1) { // User is already logged in.
    $_SESSION['email'] = $email;
    header("Location: main.php"); // Goes to main page.
    exit(); // Stops the rest of the script.
} else {
    if (!isset($_POST['submit'])) { // If the form HAS NOT been submitted.
        echo "<form name=\"form\" action=\"head1.inc.php\" method=\"POST\" style=\"margin-bottom:0;\">";
        echo "<a href=\"signup.php\" class=\"bluelink\">Sign Me Up!</a>                  ";
        echo "<a href=\"pwordhelp.php\" class=\"bluelink\" onClick=\"return popup(this, 'notes')\">Forgot Password</a>                           <br>";
        echo "<input type=\"text\" name=\"email\" size=\"17\" value=\"Email...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Email...') {this.value=''; this.style.color='#000000'}\">    ";
        echo "<input type=\"text\" name=\"pword\" size=\"17\" value=\"Password...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Password...') {this.value=''; this.style.color='#000000'; this.type='password'}\"> ";
        echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">    ";
        echo "</form>";
    } else {    // If the form HAS been submitted
        $email = form($_POST['email']);
        $pword = md5($_POST['pword']); // Lightly encrypts the password.
        
        $q = mysql_query("SELECT * FROM `signin` WHERE email = '$email' AND pword = '$pword'") or die (mysql_error()); // mySQL query
        $r = mysql_num_rows($q); // Checks to see if anything is in the db. 
        
        if (!$r) { // There is something in the db. The username/password match up.
        
            echo "<form name=\"form\" action=\"head1.inc.php\" method=\"POST\" style=\"margin-bottom:0;\">";
            echo "<a href=\"signup.php\" class=\"bluelink\">Sign Me Up!</a>                  ";
            echo "<a href=\"pwordhelp.php\" class=\"bluelink\" onClick=\"return popup(this, 'notes')\">Forgot Password</a>                           <br>";
            echo "<font color=\"#FF0000\"><strong>Incorrect Email or Password.</strong></font>   ";
            echo "<input type=\"text\" name=\"email\" size=\"17\" value=\"Email...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Email...') {this.value=''; this.style.color='#000000'}\">    ";
            echo "<input type=\"text\" name=\"pword\" size=\"17\" value=\"Password...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Password...') {this.value=''; this.style.color='#000000'; this.type='password'}\"> ";
            echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">    ";
            echo "</form>";
            
        } else {      // If the username/password is invalid
        
            $_SESSION['logged'] = 1; // Sets the session.
            $_SESSION['email'] = $email;
            header("Location: main.php"); // Goes to main page.
            exit(); // Stops the rest of the script.

        }
    }
}
?>

 

Here's the code for "index.php":

 


<?php

include("head.inc.php");

echo "This is the index page";

?>

 

Any ideas on how to stop the redirection from the index page when the incorrect info is entered?

Link to comment
Share on other sites

I solved it... the action on the forms was set to head.inc.php, which was causing the page to get stuck on that page when the login info was incorrect rather than going back to the index page and displaying the head.inc.php as an included file.  I just changed the action to index.php.  Now it works fine because the form variables are still being processed through head.inc.php since it is included on the index page.  If anyone has a better or more logical solution, I would be glad to hear it.  Thanks to all who looked at my code and attempted to help.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.