Jump to content

Recommended Posts

I have a page that contains both a login and registration form. I set the actions on the forms to be index.php#login and index.php#register so that if the form failed, the user would be taken down the form they were just working with.

 

The problem I am running into is that a successful form completion either logs the user in or brings them to a screen letting them know that they need to verify their email and the #login or #register anchor is being included in the next page's URL.

 

So a user visits my /login.php page, successfully logs in to the site, and sees the next page of /page.php#login instead of just /page.php

 

I read though the manual for header() but didn't really see anything relevant to anchors being preserved or how to flush URL information. Is this information being stored somewhere by the browser and I can just purge it from memory?

 

I was able to find this thread on StackOverflow, but my issue here is that I'm not listing the anchor (fragment as they call it) in the redirect. So according to one of the answers, it should get discarded.

 

I've tried structuring the redirect in two different ways to see if anything can be done as well:

header('Location: http://example.com/page.php');
header('Location: /page.php');

 

Any ideas here? Thanks.

<?php
if ( isset($_POST['login']) && $_POST['login'] == "submit" )
{
// do database stuff
header('Location: /page.php');
exit();
}
if ( isset($_POST['register']) && $_POST['register'] == "submit" )
{
// do database stuff
header('Location: /index.php?status=verify');
exit();
}
?>
<form id="login" action="index.php#login" method="post">
<!-- the form -->
<button type="submit" name="login" value="submit">Login</button>
</form>
<form id="register" action="index.php#register" method="post">
<!-- the form -->
<button type="submit" name="register" value="submit">Register</button>
</form>

The problem I am running into is that a successful form completion either logs the user in or brings them to a screen letting them know that they need to verify their email and the #login or #register anchor is being included in the next page's URL.

 

So a user visits my /login.php page, successfully logs in to the site, and sees the next page of /page.php#login instead of just /page.php

 

Sorry if it wasn't clear. I actually don't want them. They are being preserved and I do not want them to be preserved.

I set the actions on the forms to be index.php#login and index.php#register so that if the form failed, the user would be taken down the form they were just working with.

 

Ideally I wouldn't want to do that. Unless you know of another way to jump them back down to their form.

Edited by charlieholder

Hmmm... Upon re-reading your thread, I think I understand what your problem is. Though, that said I don't see why it's happening. Will need to do some testing.

 

Added:

After some testing it seems as if the browser keeps the identifier and then automatically adds it to the URL, if redirected to the same resource. The way to defeat this is by adding an empty identifier to the redirected URI.

In other words: Add a single # to the end of the URIs in your header () calls, and this problem will go away. ;)

Edited by Christian F.
  • 8 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.