Forum Moderators: coopster

Message Too Old, No Replies

Login refreshes current page

         

dave1236

2:20 am on Oct 10, 2006 (gmt 0)

10+ Year Member



All:
This is a followup to an earlier post -

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!

eelixduppy

2:36 am on Oct 10, 2006 (gmt 0)



You could always do something like this:

<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!