Redirect to last viewed page on login

Discussion forum for MOD Writers regarding MOD Development.
Locked
amochohan
Registered User
Posts: 92
Joined: Tue Dec 11, 2007 2:59 pm

Redirect to last viewed page on login

Post by amochohan » Tue Dec 11, 2007 3:04 pm

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?

KFCSpike
Registered User
Posts: 26
Joined: Wed May 18, 2005 11:27 am

Re: Redirect to last viewed page on login

Post by KFCSpike » Tue Dec 11, 2007 3:49 pm

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)

amochohan
Registered User
Posts: 92
Joined: Tue Dec 11, 2007 2:59 pm

Re: Redirect to last viewed page on login

Post by amochohan » Tue Dec 11, 2007 3:52 pm

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.

KFCSpike
Registered User
Posts: 26
Joined: Wed May 18, 2005 11:27 am

Re: Redirect to last viewed page on login

Post by KFCSpike » Tue Dec 11, 2007 4:14 pm

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 :)

amochohan
Registered User
Posts: 92
Joined: Tue Dec 11, 2007 2:59 pm

Re: Redirect to last viewed page on login

Post by amochohan » Tue Dec 11, 2007 5:08 pm

Nah it's not working with that mate, when I try to echo that variable - it's empty :-/

Locked

Return to “[3.0.x] MOD Writers Discussion”