Redirect to Referring Page after Login
3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: December 3, 2012 (RSS)
Hello, All -
I'm not sure whether this should go here or in the plugin dept - so pleas forgive me if I've got it wrong.
I want to explore the possibilities for redirecting users after they login. The current options are pretty static and have led to complaints from both customers and users.
The main issue concerns redirection once a user has logged in.
In my particular scenario, a user could come from any number of different pages to the main login page.
Once logged in, however, I need the user to be returned to the referring page.
The websiteMembership.php file doesn't provide an awful lot of options here! So I tried to create a "go back" button which the user could click on to send them back to the referring page.
I tried experimenting with HTTP_REFER, et al, but this doesn't work as expected. Once a user has a arrived at the login page, and then logs in, the referring page IS the login page!
I've seen examples using $_SESSIONS but I don't know if this would make things overly complex.
Any advice would be most welcome.
:0)
Perch
I'm not sure whether this should go here or in the plugin dept - so pleas forgive me if I've got it wrong.
I want to explore the possibilities for redirecting users after they login. The current options are pretty static and have led to complaints from both customers and users.
The main issue concerns redirection once a user has logged in.
In my particular scenario, a user could come from any number of different pages to the main login page.
Once logged in, however, I need the user to be returned to the referring page.
The websiteMembership.php file doesn't provide an awful lot of options here! So I tried to create a "go back" button which the user could click on to send them back to the referring page.
I tried experimenting with HTTP_REFER, et al, but this doesn't work as expected. Once a user has a arrived at the login page, and then logs in, the referring page IS the login page!
I've seen examples using $_SESSIONS but I don't know if this would make things overly complex.
Any advice would be most welcome.
:0)
Perch
Re: [Perchpole] Redirect to Referring Page after Login
Hi Perch,
There is a website membership function that can be used to redirect a user after they have logged in back to the previous page they were on. If you add this code to pages that you want users to be redirected back to:
This needs to be added after you have loaded the viewer functions, but if your redirecting users to the login page, it will need to be before that. Also on some servers you will need to add this before the header of the webpage is created.
This will override the WEBSITE_LOGIN_POST_LOGIN_URL global setting in the websiteMembership plugin, and redirect the user back to the page this code is on after log in.
Thanks!
There is a website membership function that can be used to redirect a user after they have logged in back to the previous page they were on. If you add this code to pages that you want users to be redirected back to:
<?php
setPrefixedCookie('lastUrl', thisPageUrl());
?>
This needs to be added after you have loaded the viewer functions, but if your redirecting users to the login page, it will need to be before that. Also on some servers you will need to add this before the header of the webpage is created.
This will override the WEBSITE_LOGIN_POST_LOGIN_URL global setting in the websiteMembership plugin, and redirect the user back to the page this code is on after log in.
Thanks!
Greg Thomas
PHP Programmer - interactivetools.com
PHP Programmer - interactivetools.com
Re: [greg] Redirect to Referring Page after Login
Hi, Greg -
Thanks for this. It's perfect and so simple!
All those hours I wasted searching the internet......!
;0)
Perch
Thanks for this. It's perfect and so simple!
All those hours I wasted searching the internet......!
;0)
Perch