Jump to content

Redirect to referer after login page


jesuralem

Recommended Posts

Posted

Hi,

My forum is part of a larger site but is the owner of the user base.

What i would like to do is :

- Put a link on any page of my site to the mysite.com/forums/login page
- let the user authenticate on IPS
- Have the user automatically redirected after login to the page he came from.

This plugin is supposed to do the job but i can't get it to work :

 

 

Would anyone be able to update it or make one that would do the job ?
I can pay for this although i am on a budget :).

Posted

Thanks for your answer but from what i understand this plugin redirects every user to the same adress.

What i want to do is to redirect each user to the the page he came from (which is in his http referer).

Posted

that would be great.

Plus it seems IPS provided a request to get the referrer in 4.4

Quote

Added \IPS\Request::referrer() method to more reliably and securely get the referrer for a request without duplicating code.

 

Posted
2 hours ago, jesuralem said:

that would be great.

Plus it seems IPS provided a request to get the referrer in 4.4

 

not all browsers support the referrer and if some blockers are installed on the browser it can also mask the referrer, even with IPS's \IPS\Request::referrer()  you need to add a " if referrer then refer if not then go to this url "

Posted

If you can find another solution to do what i need i am more than interested 🙂

I think we could also add the return url as a parameter of the link to the login page, but i don't know if IPS would support that.

  • 1 month later...
Posted
On 2/28/2019 at 12:12 AM, jesuralem said:

as a matter of fact the more i think about it the more i think this might be the best option.

the idea would be to link to the login page with the redirect url as a parameter such as https://www.mysite.com/forums/login?return=www.mysite.com/mypage
and have a plugin return to www.mystie.com/mypage

Did you ever find your solution?

Funny thing is, IPB used to do this behavior by default.  It used to correctly send the client back to the referring page outside of IPB, now it only does that within IPB.

I have that behavior working on logout pages.

This is a hack to the IPB core, so when you update, it will tell you that it's going to overwrite it and then after your update you'll have to reapply.  I've been doing this for years now, at least I have logout working.  Would be much happier with the situation if it were the login!  Eff the logout, who cares.

Anyways.  Guess it's better than nothing.

Search /ipbroot/applications/core/modules/front/system/login.php for "$redirectUrl" then paste this line following that line... easy as pie!

$redirectUrl	= ( !empty( $_SERVER['HTTP_REFERER'] ) ) ? \IPS\Http\Url::external( $_SERVER['HTTP_REFERER'] ) : \IPS\Http\Url::internal( '' ); // change this line

This is what I've been doing for a while but I still can't figure out why I can't do the same with the login. 

Doing the mod above will make your logout return the client to the previous page, from referrers inside and outside of IPB.

If you figure out a way to do the same with the login, I would really love to know how you did it.

BTW, I tried using a GET request to attach the referrer in the URL string... it doesn't seem to want to listen.  It just sends you to the board index.  I'm obviously overlooking something in the process.  I keep revisiting this and end up in the same boat each time.  HELP!!!

 

EDIT: Forgot to mention - a simple hack for login.

One way to get all of your logins to redirect is with mod_rewrite.  edit /ipbroot/.htaccess and add the following lines.

RewriteCond %{QUERY_STRING}     _fromLogin=(.*)$    [NC]
RewriteRule ^(.*)$ https://[your-website-url]/ [L]

You can do the same for _fromLogout  -- but this isn't the behavior I want.  Ideally the client is returned to the page they clicked "login" on, not a static URL.

Posted

Got it.  100%.  I had to pull the query string through an IPB function.

To hack the login to do what we want, follow these instructions.

Search /ipbroot/applications/core/modules/front/system/login.php for

\IPS\Output::i()->redirect( $ref->setQueryString( '_fromLogin', 1 ) );

replace with 

if(isset( $_ref->queryString['referer'])){
    $_ref_full = "https://[your-website-address]".$_ref->queryString['referer'];
    \IPS\Output::i()->redirect( $_ref_full );
}else{
    \IPS\Output::i()->redirect( $ref->setQueryString( '_fromLogin', 1 ) );
}

Make sure your site address has no trailing slash.  Then call upon this with your login URL.

/ipb/login/?referer=/   [forwards to home index after login]

/ipb/login/?referer=/another=page.php

That, combined with my previous logout hack (above)... does the trick for both login and logout.  Just make your program's side insert the page address into the URL string.

e.g.

$urlbPath = strtok($_SERVER["REQUEST_URI"],'?');

echo'
			<a class="signin" href="/ipb/login/?referer='.$urlbPath.'">Sign In</a>';

Someone -- turn that into a plugin for people... and you better not charge for it!  😛 

Again, you'll have to reapply this whenever you update IPB as it will give you a warning during updates and will overwrite the changes made.

Hope this helps.

You can see this working now at https://testmy.net -- try my beta while you're at it https://testmy.net/set-beta 

Posted

This also works with 

/ipb/register/?referer=/

Google sign-in (I assume other social logins as well) and also post before register.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...