Jump to content

The page isn't redirecting properly


aaronrb

Recommended Posts

Changed:

if($_COOKIE['user'] == " ")
//to
if(!isset($_COOKIE['user']))

 

I also changed all header functions to be double quoted, so you don need to concatenate (less characters and simpler).

 

Change each line mentioned above the code, to what the code shows.

 

Lines 12-20:

if(isset($_COOKIE['user']))
{
// if there is a cookie redirect to required page


header('Location: http://admin.fsma.co.uk/login2.php');
echo "cookie set";
exit;
} 

 

Line 22:

if(!isset($_COOKIE['user']) && $_GET['action'] == "Login")//if no cookie and action is login

 

Line 42:

header("Location: http://$refer");

 

Line 51:

header("Location: http://admin.fsma.co.uk/login2.php?refer=$refer");

 

 

Link to comment
Share on other sites

Changed your code:

<?php
// if there is a cookie redirect to required page
if(isset($_COOKIE['user']) && !empty($_COOKIE['user']))
{
    header('Location: http://admin.fsma.co.uk/login2.php');

    echo "cookie set";
    exit;
}
// login
elseif(isset($_GET['action']) && $_GET['action'] == "Login")
{
    // check if username field is field in. If it doesn't set an error message
    if(!isset($_POST['Username']) || empty($_POST['Username']))
    {
        $error[] = 'Please provide a username';
    }

    // check if passwoord field is field in
    if(!isset($_POST['Password']) || empty($_POST['Password']))
    {
        $error[] = 'Please provide a password';
    }

    // check to see if there is any validation errors from above. If there is display the errors.
    if(isset($error) && is_array($error))
    {
        echo "Please correct the following errors:\n<ul>\n<li>" . implode("</li>\n<li>", $error) . "</li>\n</ul>";

        include 'login.php';

        exit;
    }

    // validation passed continue to login user with supplies details

    $user     = mysql_real_escape_string($_POST['Username']);
    $password = md5($_POST['Password']);
    $refer    = (isset($_POST['Refer']) && !empty($_POST['Refer'])) ? $_POST['Refer'] : 'index.php';

    require 'db_connect.php';

    $query = "SELECT * FROM users WHERE user='$user' AND `password`='$password'";

    $result = mysql_query($query) or die("Error" . mysql_error());

    if(mysql_num_rows($result) == 1)
    {
        //if login successful. set cookie & go to referrer.
        setcookie('user', $user); /* Expires when browser closes */

    	header('Location: http://' . $refer);
        exit;
    }
    else
    {
        // Not authenticated
        header('Location: http://admin.fsma.co.uk/login2.php?refer='.$refer);
        exit;
    }
}
// no cookie or action found
else
{
    echo 'cookie or action not found!';
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.