Firefox reporting that the request will never complete

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Firefox reporting that the request will never complete

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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! :)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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()
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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.
Post Reply