Nimi
Nimi

Reputation: 599

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.

Upvotes: 0

Views: 3168

Answers (2)

Ofir
Ofir

Reputation: 415

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

Upvotes: 2

Ed Heal
Ed Heal

Reputation: 59997

Perhaps you also need to set the HTTP status code to one of 3xx

Upvotes: 0

Related Questions