Page 1 of 1

Redirect to last viewed page on login

Posted: Tue Dec 11, 2007 3:04 pm
by amochohan
Firstly, i'm sorry if this is being posted in the wrong section :oops:

I'm pretty new to phpBB but am using it with a site i'm developing at the moment. I've managed to get logins working from outside of the forum environment but i'm struggling to get the script to redirect back to the page from where the user logged in. It appears to work but once logged in phpBB kicks out a general error stating it was attempted to redirect to a potentially unsafe page.

The code i'm using to redirect is

Code: Select all

<input type="hidden" name="redirect" value=" . curPageName(); . " />
the curPageName() function i'm using works fine, as i've echo'ed it from the login page and it correctly states the page name - so I know that the correct value is being sent.

Does anyone have any ideas?

Re: Redirect to last viewed page on login

Posted: Tue Dec 11, 2007 3:49 pm
by KFCSpike
amochohan wrote:
The code i'm using to redirect is

Code: Select all

<input type="hidden" name="redirect" value=" . curPageName(); . " />
Does anyone have any ideas?
Should that not be:

Code: Select all

<input type="hidden" name="redirect" value=" . curPageName() . " />
(No semicolon after the function call)

Re: Redirect to last viewed page on login

Posted: Tue Dec 11, 2007 3:52 pm
by amochohan
If I ommit the semi-colon, phpBB will attempt to do the redirect - but can't find the page as the correct value isn't being passed.

I.e. it tries to redirect to "/forum/.%20curPageName()%20.?sid=whatever" rather than "pagename.php?sid=whatever". Without the semi-colon the function isn't called properly.

Re: Redirect to last viewed page on login

Posted: Tue Dec 11, 2007 4:14 pm
by KFCSpike
Maybe you should call your function earlier and assign the result to a variable rather than trying to call it inside the <input> part?


I use:

Code: Select all

$returnAddress = $_SESSION['PHP_SELF'];
$result .= '<input type="hidden" name="redirect" value="'.$returnAddress.'">';
($result is used to return the html for the form)

Works for me :)

Re: Redirect to last viewed page on login

Posted: Tue Dec 11, 2007 5:08 pm
by amochohan
Nah it's not working with that mate, when I try to echo that variable - it's empty :-/