<![CDATA[ &redirectToPrior always redirects to the homepage - My Forums]]> https://forums.modx.com/thread/?thread=69967 <![CDATA[Re: &redirectToPrior always redirects to the homepage]]> https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-562929
If I'm right, making the page accessible but protecting it with a custom snippet that forwards users to the login page may make redirectToPrior work correctly (or not -- if sendRedirect doesn't set the referer properly):


/* CheckForLogin snippet */

if (! $modx->user->hasSessionContext($modx->context->get('key'))) {
    $loginPageId = '12'; // change to ID of login page
    $url = $modx->makeUrl($loginPageId, "", "", "full");
    $modx->sendRedirect($url);
}
]]>
BobRay Nov 26, 2018, 09:10 AM https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-562929
<![CDATA[Re: &redirectToPrior always redirects to the homepage]]> https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-562620 &redirectToPrior=`0` resolved the problem I was using version 1.9.5. I see that the latest version is 1.9.7.]]> andytough Nov 09, 2018, 10:32 AM https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-562620 <![CDATA[Re: &redirectToPrior always redirects to the homepage]]> https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-562617
[[!Login?
&redirectToPrior=`1`
&loginTpl=`lgnLoginPageTpl`
&logoutTpl=`lgnLogoutPageTpl`
]]


I see in the HTML:
<input class="returnUrl" type="hidden" name="returnUrl" value="https://www.fluidwelltest.com/about/our-goal.html">

So that looks correct, but still it redirects back to the login page.
(tried &redirectToPrior=`0` also but then returnUrl is the login page.]]>
ThaClown Nov 09, 2018, 08:36 AM https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-562617
<![CDATA[Re: &redirectToPrior always redirects to the homepage]]> https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-557157 &redirectToPrior=`0` WORKS -> I have banged my head for the last year trying to get this to work (here and there) and just gave up.

Thank you Andy!]]>
rcarnrick Mar 04, 2018, 07:26 PM https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-557157
<![CDATA[Re: &redirectToPrior always redirects to the homepage]]> https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-552847

]]>
BobRay Jul 28, 2017, 08:19 PM https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-552847
<![CDATA[Re: &redirectToPrior always redirects to the homepage]]> https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-552805 I think I will leave it as it is. Thanks for checking it out!

I looked at what Chrome thought the http_referer was each time I tried to visit the protected page and login. In all cases, Chrome (console document.referrer) showed that whether I had &redirectToPrior set to 1 or 0 the http_referer was the original protected url that I had tried to access from the email link at all stages of the process.

But here is an interesting thing that might shed some light on things. Not that I really understand it!

If you do both the things listed below, the default behaviour of Login is to redirect you to the page that you were originally trying to visit.

1. Remove the zero from the loginResourceId in the Login snippet properties, so this field is empty
2. Do not use &redirectToPrior at all on your page.

So could it be that the loginResourceId property being set to zero (it's default - redirect to self) tells &redirectToPrior that the HTTP_REFERER is actually the login page?]]>
andytough Jul 26, 2017, 04:56 PM https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-552805
<![CDATA[Re: &redirectToPrior always redirects to the homepage]]> https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-552791

I even moved the getProperty() code and the call to it to a separate snippet and it behaves just as it should. redirectToPrior is set as it should be, and if it's set, the http_referer is used in the URL, which is the only way they could be redirected back to the page they came from.

]]>
BobRay Jul 26, 2017, 05:05 AM https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=4#dis-post-552791
<![CDATA[Re: &redirectToPrior always redirects to the homepage]]> https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=3#dis-post-552768
When people use a link in an email to visit a restricted page they are redirected to a login page, unless they are already logged in.

The code for my Login page is
[[!Login? &loginTpl=`lgnLoginTpl` &logoutTpl=`lgnLogoutTpl` &redirectToPrior=`0` &logoutResourceId=`8` &errTpl=`lgnErrTpl`]]
<a href="[[~5]]">Forgot your Password?</a>


With this code, after logging in they are redirected to the original url they tried to visit.

If I change the code to &redirectToPrior=`1` they end up back on the login page after logging in.]]>
andytough Jul 24, 2017, 10:35 PM https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=3#dis-post-552768
<![CDATA[Re: &redirectToPrior always redirects to the homepage]]> https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=3#dis-post-552760 ) I don't see how that's possible.

 $redirectToPrior = $this->getProperty('redirectToPrior',false,'isset');
// ...
if (!$redirectToPrior) {
            $phs['request_uri'] = str_replace(array('?service='.$logoutKey,'&service='.$logoutKey,'&service='.$logoutKey),'',$_SERVER['REQUEST_URI']);
        } else {
            $phs['request_uri'] = str_replace(array('?service='.$logoutKey,'&service='.$logoutKey,'&service='.$logoutKey),'',$_SERVER['HTTP_REFERER']);
        }



I tested the getProperty() function using the arguments above and it definitely returns 1 and 0 as it should.]]>
BobRay Jul 24, 2017, 07:10 PM https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=3#dis-post-552760
<![CDATA[Re: &redirectToPrior always redirects to the homepage]]> https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=3#dis-post-552748 &redirectToPrior to zero it will Redirect to Prior. Not what you would expect, but useful to know.

This does not redirect to the previous page
&redirectToPrior=`1`


This does redirect to the previous page
&redirectToPrior=`0`
]]>
andytough Jul 24, 2017, 12:38 PM https://forums.modx.com/thread/69967/redirecttoprior-always-redirects-to-the-homepage?page=3#dis-post-552748