Quote from: BobRay at Mar 26, 2013, 04:46 PMThe Login page is a form that submits to itself, so when you click on the Login button, SaveReferer will execute again with (I think) the Login page as the referer.
If you put the SaveReferer tag below the Login tag, it should only execute once, but it should also make sure not to set the $_SESSION variable if it's already set (in case the user enters the wrong info and the page reloads).
Thanks, that tidbit about the Login page submitting to itself is what I was missing. I changed the code in my SaveReferer script to the following:
if ($_SERVER['HTTP_REFERER'] != 'http://www.<mysite>.com/index.php?id=1'){
$_SESSION['CallingPage'] = $_SERVER['HTTP_REFERER'];
}
And now I'm getting the correct value!
I tried putting this code back in my PreHook snippet, but this same code returns a blank if run from there, meaning that $_SERVER['HTTP_REFERER'] will always return the Login page if called from there.
So I just left my 'SaveReferer' snippet call as shown above (before the call to the 'Login' snippet even) in the Login page and it worked great. Then, to redirect to the correct page after Login I created the following PostHook:
if ($_SESSION['CallingPage'] != ''){
$modx->sendRedirect($_SESSION['CallingPage']);
}
return true;
And now everything works like a charm!
I suspect that now I'm completely overriding the &redirectToPrior=`1` parameter, but I'll leave it there anyways for now. You know, if it's not broken...
Thanks BobRay for all the help. Your suggestions and pointers in the right direction made all the difference!