【问题标题】:header("Location: $value"); wont redirect... Why?header("位置:$value");不会重定向...为什么?
【发布时间】:2011-01-14 00:39:23
【问题描述】:

登录后我想将用户发送回$value
$value 是用我的代码生成的,打印出来的,看起来还不错。
这是一个完整的网址:http://example.com/page.php?id=6

但它忽略了header("Location: ".$value); 声明:

if($iniciando->iniciar()) {
    if (isset($_SESSION['redirect'])) {
        $he ="http://funcook.com" . $_SESSION['redirect'];
        mostrar_notificacion($he);
        header("Status: 301");
        header("Location: " . $he, true, 301);
    } else {
        imprimir_sesion_iniciada();
    }
} else {
    imprimir_formulario_sesion();
}

【问题讨论】:

  • 可能显示完整代码。之后你会die()吗?
  • 您在此代码之前是否打印过任何内容?尝试退出();在 header() 之后
  • die after header 不需要重定向工作。打开错误,你可能会得到一个标题已经发送警告,正如马特建议的那样。
  • 如果可能,尝试使用 'curl --head yoursite.com' 或使用 LiveHTTPHeaders(Firefox 的插件)。它们在调试时非常有用,它们会在标题中显示重定向。
  • 你能解释一下如何尝试 curl 选项吗?

标签: php redirect header


【解决方案1】:

header("Location x"); 必须在任何其他输出发送到浏览器之前调用。这包括<?php?> 标记之外的任何空格。

另外,请确保您也没有任何用于调试目的的打印/回显语句。

【讨论】:

    【解决方案2】:

    我怀疑您使用的是 Chrome?

    您应该为所有浏览器使用更好的重定向代码来遵循它:

        header("Status: 301");
        header("Location: ".$URL, true, 301);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    相关资源
    最近更新 更多