1

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();
Ankur Bhadania
  • 4,123
  • 1
  • 23
  • 38
Simon
  • 13
  • 3

2 Answers2

0

thats a fragment identifier, because the form posts to itself. never seen header done like that, isn't that killing the script before the header ? try changing them to

header("Location: _af/act_login.php");
die();
Billy
  • 2,448
  • 1
  • 10
  • 13
0

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

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
  • Thank you for that information it gave me something to look up. Found a work around for it here: `http://stackoverflow.com/questions/14076913/header-location-not-working-properly` – Simon Jan 02 '15 at 06:34