Hi,
I've added a custom action that is intended to be accesible to logged in users only. Basically, if you are logged in it shows you some information, otherwise it informs you that you need to login, and provides a link to the login page.
It works just fine when you're accesing it while logged in.
However, if you are not logged in, after going to the login page and successfully logging in, you are redirected to the board frontpage.
How can I redirect the user back to my action?
I did some digging in the LogInOut.php file - there are some statements there noting that the Login() function "caches the referring URL in $_SESSION['login_url']" and that the Login2() function "after successful login, redirects you to $_SESSION['login_url']".
However, after some more code and forum digging, I have found out the the Login() function redirects back only to some URLs, namely those matching this regexp: (board|topic)[=,]
Obviously, my custom action does not match. Apparently, the reason for this picky redirection is that some time ago the board redirected back to things people did not want - like attachments - and this protection was put there.
My question: besides the obvious action of adapting that regexp (which happens to be present once for each of the two login functions), is there a better way? I'd rather not modify the board code unless absolutely necessary.
There is a very old module that does this and if you can find it, may require a custom install to function correctly, I use it on my system and I think the name of it is http://custom.simplemachines.org/mods/index.php?mod=1443
Thanks, but no, it does not do what I want. It simply stores two URLs (for after login/logout) and sends you there.
I'm just looking to allow my custom action to be redirected back to after login by the default login mechanism.
Found a workaround that does not require modifying the SMF core files
As noted before, SMF uses the (board|topic)[=,] regexp to determine if the page that the user came from to the login page should be redirected back to.
Solution:
My custom action does not match the regexp as is:
example.com/index.php?action=customaction
However, due to how SMF (and web servers in general) handle GET parameters, I have realized that URL to the action can be appended with some extra parameters that will make it match, without changing its meaning:
example.com/index.php?action=customaction;board,
The ";board," termination will trigger the regexp, and make SMF to happily redirect back to my action.
This is still a hack, however I am more content on using this harmless addition to the URL than to actually having to modify the SMF files.
As an added bonus, it "redirects" back even when using the quick login box.