doushi9376 2015-01-01 11:16
浏览 342
已采纳

在页面之间重定向时,在URL末尾出现奇怪的#

Problem I'm having is a #f1 is being passed between all of my pages, the #f1 refers to my login form eg 127.0.0.1/#f1 displays login form using div tags. Form posts to itself for validation then is redirected to 127.0.0.1/_af/act_login.php with session variables to login user using die(header(location:)); exit(). But that URL will also have #f1 at end eg 127.0.0.1/_af/act_login.php#f1. Then when I redirect from that page back to 127.0.0.1 it carries it over again eg 127.0.0.1/#f1 bring up the login form again instead of just my home page. Not sure what I'm doing wrong? or where to look to fine answer, any help appreciated. Thank you.

Here's snippets of the code:

To bring up login form: <a href="#f1"><li>Login</li></a>

Login form:

<div id="f1">
    <div id="loginForm">
        <h3>Login</h3>
        <form name="loginForm" action="" method="post">
            <input type="hidden" name="form" value="Login" />
            <div>Email:</div>
            <div><input type="text" name="email" value="" /></div>
            <div id="newLine"></div>
            <div>Password:</div>
            <div><input type="password" name="password" /></div>
            <div id="newLine"></div>
            <div class="submitButton"><input type="submit" value="SUBMIT" /></div>
        </form>
    </div> </div>

PHP once validation complete to redirect:

die(header("Location: _af/act_login.php"));
    exit();
}

PHP to redirect back once log entries made and log in complete:

die(header('Location: http://127.0.0.1'));
    exit();
  • 写回答

2条回答 默认 最新

  • dozpox8752 2015-01-01 18:11
    关注

    The fragment identifier (#f1) is copied to the new location because you are using a relative URI-Reference. You need to use an absolute URI-Reference:

    header ('Location: http://127.0.0.1/_af/act_login.php');
    

    This behaviour is detailed in RFC 7231:

    7.1.2.  Location
    
         Location = URI-reference
    
       The field value consists of a single URI-reference.  When it has the
       form of a relative reference ([RFC3986], Section 4.2), the final
       value is computed by resolving it against the effective request URI
       ([RFC3986], Section 5).
    
       ...
    
       If the Location value provided in a 3xx (Redirection) response does
       not have a fragment component, a user agent MUST process the
       redirection as if the value inherits the fragment component of the
       URI reference used to generate the request target (i.e., the
       redirection inherits the original reference's fragment, if any).
    

    References

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 根据以下文字信息,做EA模型图
  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥60 关机时蓝屏并显示KMODE_EXCEPTION_NOT_HANDLED,怎么修?
  • ¥66 如何制作支付宝扫码跳转到发红包界面