Page 1 of 1

Firefox reporting that the request will never complete

Posted: Thu Nov 01, 2007 10:01 am
by impulse()
The URL for this error is

http://stesbox.co.uk/racetrack2/index.p ... ser=yoyoyo The user=yoyoyo is a valid user from a MySQL DB. If I put a user that doesn't exist in there the page loads fine.

The code for the function that runs is

Code: Select all

function verifyCode() {

  if(isset($_GET['user']))
    $user = $_GET['user'];
  else
    $user = $_POST['postuser'];

  $query = mysql_query("SELECT code, admin, id
                        FROM logins
                        WHERE username = '$user'");

  if(mysql_num_rows($query) > 0) {

    $code  = mysql_result($query, 0, 0);
    $uid   = mysql_result($query, 0, 2);
    $admin = mysql_result($query, 0, 1);


    if($code == $_POST['code']) {

      mysql_query("UPDATE logins
                   SET verified = 'Y'
                   WHERE username = '$user'");

      $_SESSION['username'] = $user;
      $_SESSION['uid']      = $uid;
      if($admin == "Y") $_SESSION['admin'] = "Y";

      echo "Code verified. <br><br>Click <a href = 'http://stesbox.co.uk/racetrack2'> Here </a> to continue <br>";

    }
    else
      header("Location: http://stesbox.co.uk/racetrack2/index.php?page=verifyCode&user=$user");

  }


  else
    echo "There was a problem processing your form. Please try again";


}
Cookies are turned on in my browser and when I try and load the page in IE the page never even gets there. I have sessions turned on at the beginning of my code. Can you see an error that may cause this?

Posted: Thu Nov 01, 2007 10:24 am
by pickle
Put an exit() after your call to header().

I'd also put an echo statement in there temporarily to see if that condition is ever being reached.

Posted: Thu Nov 01, 2007 10:29 am
by impulse()
A-ha!

I think I've created an infinite loop on the header function. Just checked my Apache logs and there's thousands of requests for the URL that isn't displaying properly.

Doh! :)

Posted: Thu Nov 01, 2007 10:32 am
by Ollie Saunders
impulse() wrote:A-ha!

I think I've created an infinite loop on the header function. Just checked my Apache logs and there's thousands of requests for the URL that isn't displaying properly.

Doh! :)
Yes, that's exactly what FireFox was trying to tell you. pickle's advice is good. There's hardly ever a time where you'll call header('Location: ... and not follow it with an exit()

Posted: Thu Nov 01, 2007 10:40 am
by impulse()
I'd never thought about the dangers of not exiting after a header function. I suppose not thinking about it you assume as soon as the header function is hit nothing else is going to happen after that.

Thanks for the tip I shall keep that one well remembered.