Forum Moderators: coopster

Message Too Old, No Replies

URL redirection with PHP

         

kaboomboom

3:48 am on Jul 30, 2010 (gmt 0)

10+ Year Member



Hi,

I am trying to write a Login script that will take the user through several pages, and my goal is that when the user reaches the end, to have the user be automatically redirected (as in without having to click a link) to the page they were on before they clicked the "Login" link, whatever that page may have been. the REFERRER command is unreliable, so I am looking for some kind of alternative solution. Is this possible with PHP?

Thanks!

Anyango

6:26 am on Jul 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, one of the many ways could be this. When you put login link on your pages, send the link a parameter to specify which page it was on. after processing the login information, login script picks up that parameter and takes user to that page.

kaboomboom

1:41 am on Jul 31, 2010 (gmt 0)

10+ Year Member



Thanks for the reply Anyango,

I am relatively new to PHP as this is my first PHP site, so I am not fully understanding your suggestion. I am not entirely sure how to send the parameter to the "Login" link which will hold the current page. I am assuming I need to assign a variable by using the REQUEST_URI index, but the variable does not stay assigned from page to page.

Could you explain it in further detail for this PHP newbie? :)

Matthew1980

9:21 am on Jul 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there kaboomboom,

This is normally the way I do these type of things, and as yet I haven't had any reason to complain :)

Try this:-

//Absolute urls are preferred though
//and set the delay, you can do this dynamically too
header("refresh:5; url=/path/to/file/yourPage.php" );
exit;


Hope that helps, I find it more reliable than meta refresh anyway... Unless I have missed the point?

Cheers,
MRb

kaboomboom

9:22 am on Jul 31, 2010 (gmt 0)

10+ Year Member



After a lot of trial and error, I figured out that I needed to place the REQUEST_URI server global variable into a $_SESSION var and called that at the end of the registration process, so thank you for your suggestion, it helped in the end.

kaboomboom

9:24 am on Jul 31, 2010 (gmt 0)

10+ Year Member



Matthew, thanks for your reply, I didn't see it before I posted my other reply. I was actually looking for a script to remember whatever page the user was on before they clicked the "Login" button and then redirect them back to that page, and have found the solution by using the $_SESSION['variable'] command to remember the current page then to call upon it later.

Anyango

11:10 am on Jul 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you figured it out kaboomboom, i meant something like following, (just another way to do it)

lets say you were on testing.html and you click login link and want to get back to testing.html after login, you can do this


from testing.html link to "login.php?page=testing"

then login.php can pick it up

$previousPage=$_GET["page"];

then you process the login stuff here, and when you have to redirect, you redirect to

header("Location: ".$_GET["page"]."html");

Matthew1980

11:41 am on Jul 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad your sorted.

Cheers,
MRb

enigma1

1:12 pm on Aug 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The right way is to use a storage medium (sessions is one of them as you did). You don't want to complicate things with passing past pages in the url, it is much harder to do security checks and to keep track of login sequences.