Redirect to Previous Page on Login

Permalink 1 user found helpful
Right now when a user logs into my C5 site, they get directed to the dashboard rather than back to the page they were on. Is there an easy way to change this? I thought I saw something in the Forum here about that, but now I can't find it.

Thanks!

AndyB37
 
andrew replied on at Permalink Reply
andrew
You should be able to do this. Typically, in a theme, you might login using this

<a href="<?=$this->url('/login')?>">Login here!</a>


To login and redirected back, this should work:

<a href="<?=$this->url('/login', 'forward', $c->getCollectionID()?>">Login here!</a>


The forward method ensures that on completion of the login process, you'll be forwarded back to that page ID. At least, that's how it's supposed to work.
AndyB37 replied on at Permalink Reply
AndyB37
Thanks Andrew, worked perfectly!

Now I'm wondering if there's any way to do the same thing if you're on a front-end page and hit the logout button (obviously logging out from within the dashboard is a separate issue).

I found the page "elements/page_controls.php" with its logout link, but obviously I don't want to go meddling with the core code. Any thoughts on a workaround? I tried creating my own file at root level and it didn't seem like I can override the core elements pages.
DavidMIRV replied on at Permalink Reply
DavidMIRV
ok so that forwards back to the same page but what If I want to have a login go to a 'members' area (and not dashboard)
AndyB37 replied on at Permalink Reply
AndyB37
David,

If I understand Andrew's post correctly, I think you could accomplish your goal by substituting the members area's cID in place of $c->getCollectionID(). So if your member area collection ID is "48", you would make the link:

<a href="<?=$this->url('/login', 'forward', '48')?>">Login here!</a>
marxion replied on at Permalink Reply
marxion
This is exactly what I have wanted to do but can't seem to get it to work. Any help is appreciated...Thanks.

Here's my code:

<form method="post" action="<?=$this->url('/login';'forward','24')?>">


I get a Parse error: syntax error, unexpected ';' in default.php on this line of code.
ecli replied on at Permalink Reply
...after the first argument
<form method="post" action="<?=$this->url('/login', 'forward', '24')?>">

should do the things :D

cYa
marxion replied on at Permalink Reply
marxion
Yep...needed the reading glasses. However this approach still requires a user to login twice prior to passing to the cID. Anyway to do this directly from my post action??

I tried this but no go:
<form method="post" action="<?=$this->url('/login/-/do_login','forward','24')?>">


Thoughts..??
redtype replied on at Permalink Reply
<a href="<?=$this->url('/login','forward',$c->getCollectionID())?>">

you'll need another ")" at the end as the original was just ('/login'), we added getCollectionID() but forgot to close the ")"
nothingserious replied on at Permalink Reply
I know this is a very old topic, but any ideas on how to reverse this for the logout?

<a href="<?php echo $this->url('/login', 'logout')?>">


"logout" seems to replace the "forward" variable. Can they be stacked or something?
firepixel replied on at Permalink Reply
firepixel
Does anybody know a way to forward back to the same page but also pass the GET variables? Otherwise can we pass the URL instead of the page id?