简体   繁体   中英

php header not forwarding ie9

I use the following which works perfectly in all browsers, except ie9

$result = mysql_query("SELECT u_id, from users where (id = '$userID')",$db); 
$item = mysql_fetch_row($result);

$how_many = mysql_num_rows($result);

// if not a user send to reg
if ($how_many < 1){ 
header("Location: /pages/registration");
} 

It simply does not forward - the header function does nothing - however, if i change the last block of the code to what is below, it works?!?!

if ($how_many < 1){ 
header("Location: /pages/registration");
// added echo for ie9
echo "<br /><br /><br /><br />here i am ";
} 

I cannot fathom any logical reason for this, am I missing something?

As long as you don't need to do any more processing after the redirect you should exit after you send out the Location header:

if ($how_many < 1){ 
    header("Location: /pages/registration");
    exit;
} 

By exiting or echoing, the buffers are flushed by the web browser, which IE9 awaits before taking action.

The following will also work:

header('Location: /page');
flush();

I would recommend exit/die to be used after the header function is called to prevent unnecessary code/resources being utilized.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM