简体   繁体   中英

PHP header redirect doesn't work in IE 8

I'm using in redirecting by header(Location : 'http://..' ) command in PHP. It's working in FireFox and Chrome but not in IE 8. I'm getting the error: "Internet Explorer cannot display the webpage" and it's though the page is indeed existed.

What may be the reason for it?

The redirect function:

function redirect($url, $statusCode = 303) {
    header('Location: ' . $url, true, $statusCode);
    die();
}

The call:

redirect("/page.php");

Thanks, Nimrod.

The PHP manual says:

HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:

<?php
/* Redirect to a different page in the current directory that was requested */
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'mypage.php';
header("Location: http://$host$uri/$extra");
exit;
?>

I think IE8 is one of those browsers...

也许您还需要将HTTP状态代码设置为3xx之一

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