I have a counter that evokes the "Three Strikes You're Out" rule.. if you make more than N mistakes it auto-resets to avoid flooding $_SESSION with attempt after attempt, etc.
However, the counter never advances beyond 1!
// HANDLE THE PART WHERE THE STUDENT INFORMATION WILL BE UPDATED OR SEARCHED
if (is_array($_POST) && @sizeof($_POST) > 0) {
$accepter =& new Accepter($student_id);
if (!$accepter->isValid) $errorArray = $accepter->getErrorArray();
} else {
// NEW 3/24/2006: MAKE SURE THE $_SESSION KOUNTER IS RESET SINCE THEY HAVE DONE NO FORM ACTION
//unset($_SESSION["${projectAcronym}_kounter"]);
//@session_unregister("${projectAcronym}_kounter"); // DESTROY SESSION ERROR COUNTER TO FORCE IT TO RESET
$_SESSION["${projectAcronym}_kounter"] = null;
}
And this is supposed to advance the $_SESSION counter:
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
New 2/27/2006: New "Three Strikes You're Out" Rule: To prevent overstuffing of $_SESSION and other memory-encroaching collection objects,
a "Three Strikes You're Out" rule will be implemented. If the user makes fewer than 3 mistakes either within Accepter or in ActionPerformer combined,
then a $_SESSION counter will increase, up to 2 tries. After the 2nd try, all $_SESSION variables prefixed by $projectAcronym are destroyed and you are
automatically rerouted back to the default page
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
print_r("Before: "); print_r($_SESSION["${projectAcronym}_kounter"]); print_r("<P>");
if (is_array($_POST) && @sizeof($_POST) > 0 && is_object($accepter) && @is_a($accepter, 'Accepter') && is_object($ap) && @is_a($ap, 'ActionPerformer') &&
(!$accepter->isValid || !$ap->isSuccessful) && (int)$_SESSION["${projectAcronym}_kounter"] >= 1
) {
foreach ($_SESSION as $field) if (strpos($field, $projectAcronym) === 0) unset($_SESSION[$field]);
$qs = '?sort=' . $_REQUEST['sort'] . '&willDesc=' . $_REQUEST['willDesc'] . '&willShowDetail=1&id=' . $_REQUEST['id'];
$errorMsg = "<p><font color=\"#cc0000\"><b>Application display restarted due to too many errors, all values reset</b></font></p>";
$qs .= '&errorMsg=' . urlencode($errorMsg);
header('Location: ' . $_SERVER['PHP_SELF'] . $qs);
} elseif (is_array($_POST) && @sizeof($_POST) > 0 && is_object($accepter) && @is_a($accepter, 'Accepter') && is_object($ap) && @is_a($ap, 'ActionPerformer') &&
(!$accepter->isValid || !$ap->isSuccessful) && (int)$_SESSION["${projectAcronym}_kounter"] >= 0
) {
if ((int)($_SESSION["${projectAcronym}_kounter"]) > 0) (int)$_SESSION["${projectAcronym}_kounter"]++; else $_SESSION["${projectAcronym}_kounter"] = 1;
}
print_r("After: "); print_r($_SESSION["${projectAcronym}_kounter"]); print_r("<P>");
//--END OF "Three Strikes You're Out" RULE------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Problem is that the session counter never advances beyond 1, it remains 1 indefinitely unless you do not do a form action then it's null again.
It's supposed to go to 1 if you make one mistake, to 2 if you make another, and so on until you reach the limit and then it auto resets while destroying all SESSION objects whose keys are stamped to this particular project alone.
Help!
Thanx
Phil