Forum Moderators: coopster

Message Too Old, No Replies

php redirect question

how can I keep the link of the original page

         

icpooreman

4:53 am on Jan 10, 2006 (gmt 0)

10+ Year Member



I built a little login script for my site which checks to see if you're logged in at the top of restricted pages (with php) and if you're not logged in it redirects you to a login page. I want to keep track of the original link the user was trying to get to so after they login I can forward them to the page they were originally trying to reach. I'm not sure how to do this and would appreciate any insight.

dreamcatcher

7:39 am on Jan 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi icpooreman,

You can pass the referring page into a hidden variable in your form, then when processing the login, redirect back to that page if successful.

dc

simon2263

9:56 am on Jan 10, 2006 (gmt 0)

10+ Year Member



Or you can store it in the PHP session for that user and extract it later.

elgumbo

1:35 pm on Jan 10, 2006 (gmt 0)

10+ Year Member



Just be careful that the original link the user followed wasn't to your logout page. Endless loop of logging in / logging out. logging in / logging out. logging in / logging out.

Yep, I did that once :)

icpooreman

4:01 pm on Jan 10, 2006 (gmt 0)

10+ Year Member



How would I pass the referring page into a hidden variable?

the way I'm currently doing the redirect is at the top of my page I have a few lines of code to see if you're logged in and if not I use
header('Location: 'loginpage');

icpooreman

4:27 am on Jan 11, 2006 (gmt 0)

10+ Year Member



nevermind, I think I found a pretty easy way to do what I want, I'm simply turning my login page into an include file which if your not logged in gets included and then the php script exits. So once you hit log in you can simply refresh the page and voila page you were attempting to reach loads.