标题("位置:"。$ url)遇到长网址问题

时间:2014-11-02 13:50:38

标签: php redirect header steam

我正在网站上工作并使用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
        }
    }
?>

1 个答案:

答案 0 :(得分:3)

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

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