Do you have &redirectToPrior=`1` in the Login snippet tag?
$modx->sendRedirect($url, array('REDIRECT_HEADER');$docId = $modx->resource->get('id');
$currentUrl = $modx->makeUrl($docId, "", "", "full");
$_SERVER['REQUEST_URI'] = $currentUrl;
$_SERVER['HTTP_REFERER'] = $currentUrl;
That does make sense.
Everything below assumes that you are using &redirectToPrior=`1`.
In the snippet, are you using sendRedirect() or sendForward()? If it's sendForward(), try sendRedirect().
If it's sendRedirect, you might try some of the possible second arguments to see if they make a difference: https://docs.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.sendredirect
The form would be:
$modx->sendRedirect($url, array('REDIRECT_HEADER');
If none of that works, you could try getting the URL of the current page and setting the $_SERVER variables. I'm not sure it would work:
That would look like this (above the redirect):
$docId = $modx->resource->get('id'); $currentUrl = $modx->makeUrl($docId, "", "", "full"); $_SERVER['REQUEST_URI'] = $currentUrl; $_SERVER['HTTP_REFERER'] = $currentUrl;
I meant the PrivatePage snippet. Oddly, I don't actually have a copy of it, so I can't check, but it must redirect the user to the Login page and I don't know how else that could happen.Ah ok sorry. See below:
<?php
/* PrivatePage snippet */
/* Redirect anyone who is not logged in */
$key = $modx->context->get('key');
if (! $modx->user->hasSessionContext($key)) {
$modx->sendUnauthorizedPage();
}
return '';
<?php
/* PrivatePage snippet */
/* Redirect anyone who is not logged in */
$key = $modx->context->get('key');
if (! $modx->user->hasSessionContext($key)) {
$loginId = '12'; /* change this to the ID of your Login page !!! */
$loginUrl = $modx->makeUrl($loginId, "", "", "full");
$modx->sendRedirect($loginUrl);
}
return '';$docId = $modx->resource->get('id');
$currentUrl = $modx->makeUrl($docId, "", "", "full");
$_SERVER['REQUEST_URI'] = $currentUrl;
$_SERVER['HTTP_REFERER'] = $currentUrl;Try this:
<!--?php /* PrivatePage snippet */ /* Redirect anyone who is not logged in */ $key = $modx--->context->get('key'); if (! $modx->user->hasSessionContext($key)) { $loginId = '12'; /* change this to the ID of your Login page !!! */ $loginUrl = $modx->makeUrl($loginId, "", "", "full"); $modx->sendRedirect($loginUrl); } return '';
Be sure to clear the cache before testing.
If it doesn't work, try adding this just above the sendRedirect() line:
$docId = $modx->resource->get('id'); $currentUrl = $modx->makeUrl($docId, "", "", "full"); $_SERVER['REQUEST_URI'] = $currentUrl; $_SERVER['HTTP_REFERER'] = $currentUrl;
[[!Login? &loginTpl=`lgnLoginTpl` &logoutTpl=`lgnLogoutTpl` &errTpl=`lgnErrTpl` &logoutResourceId=`111` &redirectToPrior=`1` ]]
&loginResourceId=`3`
<?php
/* PrivatePage snippet */
/* Redirect anyone who is not logged in */
$key = $modx--->context->get('key');
if (! $modx->user->hasSessionContext($key)) {
$loginId = '12'; /* change this to the ID of your Login page !!! */
$loginUrl = $modx->makeUrl($loginId, "", "", "full");
$docId = $modx->resource->get('id');
$currentUrl = $modx->makeUrl($docId, "", "", "full");
$_SERVER['REQUEST_URI'] = $currentUrl;
$_SERVER['HTTP_REFERER'] = $currentUrl;
$modx->sendRedirect($loginUrl);
}
return '';