【问题标题】:header("Location: ".$url) having troubles with long urlsheader("Location: ".$url) 遇到长 url 问题
【发布时间】:2014-11-02 13:50:38
【问题描述】:

我正在开发一个网站,并且正在使用 steam openid,到目前为止没有任何问题。 问题是当我尝试将用户重定向到 Steam openid 页面时,它不起作用并将他们重定向到 steamcommunity.com 的根目录。

代码如下:

if (!isset($_SESSION['steamid']) && $_GET['a'] == "login") {
    $url = SteamSignIn::genUrl($_AMCFG['login_dir']);
    print($url);
    header("Location: ".$url);
}

手动输入时生成的 url 可以正常工作,但正如我所说的重定向,不是那么好。 我尝试手动替换标头中的 $url 并且效果很好。

header('Location: https://steamcommunity.com/openid/login?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=checkid_setup&openid.return_to=http%3A%2F%2Flocalhost%2Fadminmailer%2Findex.php&openid.realm=http%3A%2F%2Flocalhost&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select');

我很困惑为什么这不能按预期工作。

作为临时修复,我已将此添加到头部:

<?php
    if (isset($_GET['a'])) {
        if (!isset($_SESSION['steamid']) && $_GET['a'] == "login") {
            $url = SteamSignIn::genUrl($_AMCFG['login_dir']);
            ?><meta http-equiv="refresh" content="0; url=<?php print($url); ?>" /><?php
        }
    }
?>

【问题讨论】:

  • 嗯,“不太好”是什么意思?发生什么了?您是否检查过 Steam 不是结束重定向您?
  • 在更改页眉之前不要打印
  • 正如我所说,它会将我重定向到没有 /openid 的 steamcommunity.com 的根目录...
  • 正如 Apul 所说,在发送标头之前您不能打印任何内容。而且,您是否使用诸如 FireBug 之类的调试器检查了标头是否正在发送,并且您是否正在被重定向?我认为 Steam 正在将您重定向到主页,并且您的重定向成功。
  • 我会用 FireBug 检查什么?我对 PHP/HTML 还很陌生,这是我的第一个项目。

标签: php redirect header steam


【解决方案1】:

header 重定向之前不要打印任何内容。 Read Doc

重定向可能在正确的位置进行,但之后您再次被重定向到主页,即https://steamcommunity.com

【讨论】:

  • 打印在这里是为了调试目的,即使没有它我仍然有同样的问题。如果我使用生成的 url 它工作正常,为什么蒸汽会重定向我,它必须是标题没有正确解释 url,这很奇怪,因为当我手动添加它时它工作正常。
猜你喜欢
  • 2017-08-13
  • 1970-01-01
  • 1970-01-01
  • 2014-05-07
  • 2021-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多