【问题标题】:PHP header redirect doesn't work in IE 8PHP 标头重定向在 IE 8 中不起作用
【发布时间】:2011-09-14 02:22:52
【问题描述】:

我在 PHP 中使用 header(Location : 'http://..' ) 命令重定向。 它适用于 FireFox 和 Chrome,但不适用于 IE 8。 我收到错误: “Internet Explorer无法显示该网页” 虽然页面确实存在。

可能是什么原因?

重定向功能:

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

电话:

redirect("/page.php");

谢谢, 尼姆罗德。

【问题讨论】:

  • 显示代码,如果可能,显示 URL
  • 你能用一小段代码复制这个并发布给我们吗?
  • 试试 header('Location: ' . url);退出;
  • 不要在 URL 周围加上引号。

标签: php redirect internet-explorer-8 header


【解决方案1】:

PHP 手册说:

HTTP/1.1 需要绝对 URI 作为 » Location 的参数:包括方案、主机名和绝对路径,但有些客户端接受相对 URI。您通常可以使用 $_SERVER['HTTP_HOST']、$_SERVER['PHP_SELF'] 和 dirname() 自己从相对的 URI 中创建绝对 URI:

<?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;
?>

我认为 IE8 是那些浏览器之一...

【讨论】:

  • 您是否尝试在 IE8 中直接访问该页面? PHP重定向后地址栏显示的是哪个url?
  • 是的,我试过了。主页显示在 URL 中(调用重定向操作的页面)。看来IE8和header()命令有问题。
【解决方案2】:

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

【讨论】:

  • header("location: 会自动完成
  • @nimi - 你说得对。考虑使用与 PHP 不同的语言。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
相关资源
最近更新 更多