Page Redirection doesnt work

0 down vote favorite

I grabbed a piece of code a login and registration script when i run the index.php from apache it gives this error in the address tab

http://localhost/johnlogin/?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login?msg=login

and this below error on the browser page

The page isn’t redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

This problem can sometimes be caused by disabling or refusing to accept cookies.

I dig out the code but cant solve the problem here’s the code of index.php
[php]
require_once(‘load.php’);
$logged = $j->checkLogin();

if ( $logged == false ) {
//Build our redirect
$url = “http” . ((!empty($_SERVER[‘HTTPS’])) ? “s” : “”) . “://”.$_SERVER[‘SERVER_NAME’].$_SERVER[‘REQUEST_URI’];
$redirect = str_replace(‘index.php’, ‘login.php’, $url);

//Redirect to the home page
header("Location: $redirect?msg=login");
exit;

} else {
//Grab our authorization cookie array
$cookie = $_COOKIE[‘joombologauth’];

//Set our user and authID variables
$user = $cookie['user'];
$authID = $cookie['authID'];

//Query the database for the selected user
$table = 'j_users';
$sql = "SELECT * FROM $table WHERE user_login = '" . $user . "'";
$results = $jdb->select($sql);

//Kill the script if the submitted username doesn't exit
if (!$results) {
    die('Sorry, that username does not exist!');
}

//Fetch our results into an associative array
$results = mysql_fetch_assoc( $results );

?>
[/php]
the load.php basically consists a require_once statement which loads db and a class file here’s the class code which id been called by
[php]
$logged = $j->checkLogin();

---------the class.php code-------

    function checkLogin() {
    global $jdb;

    //Grab our authorization cookie array
    $cookie = $_COOKIE['joombologauth'];

    //Set our user and authID variables
    $user = $cookie['user'];
    $authID = $cookie['authID'];

    /*
     * If the cookie values are empty, we redirect to login right away;
     * otherwise, we run the login check.
     */
    if ( !empty ( $cookie ) ) {

        //Query the database for the selected user
        $table = 'login';
        $sql = "SELECT * FROM $table WHERE uName = '" . $user . "'";
        $results = $jdb->select($sql);

        //Kill the script if the submitted username doesn't exit
        if (!$results) {
            die('Sorry, that username does not exist!');
        }

        //Fetch our results into an associative array
        $results = mysql_fetch_assoc( $results );

        //The registration date of the stored matching user
        $storeg = $results['user_registered'];

        //The hashed password of the stored matching user
        $stopass = $results['user_pass'];

        //Rehash password to see if it matches the value stored in the cookie
        $authnonce = md5('cookie-' . $user . $storeg . AUTH_SALT);
        $stopass = $jdb->hash_password($stopass, $authnonce);

        if ( $stopass == $authID ) {
            $results = true;
        } else {
            $results = false;
        }
    } else {
        //Build our redirect
        $url = "http" . ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        $redirect = str_replace('index.php', 'login.php', $url);

        //Redirect to the home page
        header("Location: $redirect?msg=login");
        exit;
    }

    return $results;
}

}
[/php]
all the bug is being happening here

regards

I don’t see where you are actually setting the cookie, so it’s always going to be empty, because their isn’t one and hence your re-direct loop.

Whats the remedy

Don’t keep redirecting, if a cookie isn’t present.

Sponsor our Newsletter | Privacy Policy | Terms of Service