By "Solved but Kludged" I mean that I have absolutely no freakin' idea why the logic works out the way it does. Hello, all, btw. This is my first post. I've lurked for a "while". This basically amounts to my abusing these forums for the knowledge contained herein. I've yet to run into something that needs interactive assistance. Until now. 🙂
Anyhow, I have a registerUser() function in a process.php (no html, just processing) that does some basic preg_match() testing against some form fields (email, username, password) for errors, strlens() and stuff of that nature. I also use sessions. Essentially, the program flow works so that if a preg_match doesn't work, it sets $errorMsg to some error message, such as "password must be between 6 and 24 characters". The content of these messages are superfluous.
Then, $this->registerInfo($errorMsg) is called, basically to simplify everything and lessen the amount of code needed in the program. This function assigns $SESSION['errorMsg'] to whatever is passed via $errorMsg from registerUser(), then sets our error incrementor bit (details of this function are arbitrary, I believe), which tells the referring page there actually is an error, assigns $SESSION['errorForWho'] to designate who the error is for (registerPage.php), then shoots a Header("location: $referrer"), which is usually set to $session->lastPage. Session object, by the way, sets its $lastPage to whatever page was just in the $page variable, and then assings $_SERVER['PHP_SELF'] to the $page variable. This keeps a pretty good record of page referrals.
HERE'S THE CODE:
<<<from registerUser()>>>
if(!isset($_POST['termsAgree'])) {
$errorMsg = "You must agree to the Terms and Conditions.";
$this->registerInfo($errorMsg);
}
<<<then further down>>>
function registerInfo($errorMsg) {
$_SESSION['error'] = $errorMsg;
$_SESSION['errorForWho'] = "register";
$_SESSION['errorCount'] = '1';
$referrer = $_SESSION['lastPage'];
header("Location: $referrer");
exit;
}
THE PROBLEM:
Whenever I remove the exit; code underneath the header() function, it somehow (incredulously) catches EVERY error message in registerUser() -- I've done echo tests.. heh.. basic debugging.. on every errorMsg point in the function -- then spits out the LAST error message in the refreshed page (the one that's called in the header() function)!!!!
WTF!?
Essentially, it acts like it GETS the error messages just fine, and then catalogs the header() function as like "OK, I need to refresh later", then CONTINUES processing until it gets to the end of the registerUser() function!
WTF!?
So that exit; was necessary to KILL processing AFTER it caught the errorMsg and stuff! KLUDGE ALERT!
Can anyone here tell me what the hell is going on here!? I'd be EXTREMELY happy for any and all responses. I am in Baghdad, Iraq (deployed infantryman), so I work LONG 12 hour days, but I'll be HAPPY and GLAD to post any and all code needed to solve this mystery during my off-hours.
THANK YOU EVERYONE and WELL MET!