Weird # at end of URL when redirecting between pages


Problem I’m having is a #f1 is being passed between all of my pages, the #f1 refers to my login form eg displays login form using div tags. Form posts to itself for validation then is redirected to with session variables to login user using die(header(location:)); exit(). But that URL will also have #f1 at end eg Then when I redirect from that page back to it carries it over again eg 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">
        <form name="loginForm" action="" method="post">
            <input type="hidden" name="form" value="Login" />
            <div><input type="text" name="email" value="" /></div>
            <div id="newLine"></div>
            <div><input type="password" name="password" /></div>
            <div id="newLine"></div>
            <div class="submitButton"><input type="submit" value="SUBMIT" /></div>
    </div> </div>

PHP once validation complete to redirect:

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

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



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:');

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).


Answered By – Nisse Engström

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published