Forum Moderators: coopster
I want the page that refers users to my login page to be the variable included in the header after a user logs in.
For example, if page 'a' refers the user to the login page, after login they should be referred back to page 'a'...
Currently, when a user logs in, I use this:
this is my header on the login page itself:
$url_of_refering_page = $_SERVER['HTTP_REFERER'];
header("Location: $url_of_refering_page");
How can I get this header to reflect the referring page - this appears to send the user back to the login?
Thanks!
<form action="login.php?r=<?php echo (isset($_SERVER['HTTP_REFERER']))? urlencode($_SERVER['HTTP_REFERER']): "login.php";?>" method="post">
Username:<input type="text" name="username" />
....yada yada yada
</form>
//validate user, then redirect
if(isset($_GET['r'])) {
header("Location: ".urldecode($_GET['r']));
exit();
}
The reason why you get the login page again is because you submitted the form. So you are getting the login page as the referer.
Good luck!