Login Redirect?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sakaki
Forum Newbie
Posts: 12
Joined: Mon Dec 02, 2002 12:37 pm

Login Redirect?

Post by Sakaki »

Ok I have a login form in the navigation for my site. I want it so that whatever page a user logs in at, it will bring them back to that page after they log in. What do I need to do?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

All this problem takes is a little creativity. ;)

Within the login form, add a hidden variable.

Code: Select all

<input type="hidden" value=" <?=$thispage? > ">
(with no space between the ? and >)

then a little bit of php code before the form

Code: Select all

<?
$thispage = $_SERVER['PHP_SELF'];
?>
Then in the processing page, in the if statement that processes the database query, add the following code if the login was successful:

Code: Select all

$jumpto = trim($thispage);
 header("location: $jumpto");
pardon my coding & organization, it's been a long day. :)
Post Reply