View Full Version : Re-Direct To A Page After Login

02-25-2008, 11:42 PM
Hi all... I am sending out a e-newsletter, with a link to a page... However the to access the site people need to login, how could I re-direct the user once they logged in to this page? I only want it to happen with people who get the newsletter, regular users who login don't need to be re-directed... I thought this was a JavaScript issue so posted there first but think it may be php and variables...

02-25-2008, 11:47 PM
First of all let me just say there's probably a better way to do this.

But I would do it via a $_GET value (query string) on the login script, which you would then catch after a successful login and redirect.

02-26-2008, 12:18 AM
First of all let me just say there's probably a better way to do this.
No, that should be the best way unless the OP wants to make a separate login script for the newsletter links(not what I would recommend).

02-26-2008, 12:22 AM
I don't really understand how I would do this though... So I give them a link but add variables in the url?

02-26-2008, 12:46 AM
Yeah, you would send them a link like http://www.domain.com/login.php?newsletter=true then pass it through the session when the login form loads:

$_SESSION['newsletter'] = true;
And finally in the login code, forward them:

header('Location: newsletterinfo.php');
// might want to unset the newsletter variable here

02-26-2008, 02:52 AM
Yep that's exactly what I had in my head, thanks Inigoesdr for pulling the code out of my head :) (I was too lazy to give the example and hoped my explanation would be enough)

02-26-2008, 09:14 PM
It would be a lot more effective/abstract to pass a relative URL to the login script.

Upon loading, the script checks if they are logged in or not. If they aren't, forward to login page (appending the current relative URL to the forward).

Then the login page uses that to forward back to the original page.

For example:

Original: www.domain.com/newsletter/
Login Forward: www.domain.com/login.php?returnURL=newsletter/ (this needs to be urlencode()d).

This way you can reuse the code for the login page.