473,508 Members | 2,216 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Three Strikes You're Out" rule fails

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!

[PHP]
// 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;
}

[/PHP]

And this is supposed to advance the $_SESSION counter:

[PHP]

/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[/PHP]

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

Mar 27 '06 #1
3 2059
comp.lang.php said the following on 27/03/2006 16:55:
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"


That's some of the most unreadable code I've ever seen.
--
Oli
Mar 28 '06 #2
Oli Filth wrote:
comp.lang.php said the following on 27/03/2006 16:55:
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"


That's some of the most unreadable code I've ever seen.

It's still obtuse if you do reformat it...
My comments with '--' prefix.

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 )
-- up to here the two clauses of the if are identical
&& (int)$_SESSION["${projectAcronym}_kounter"] >= 1 ) {
-- if we get here, i.e. kounter > 0, then we never increment it
-- net result: the kounter goes from 0 in the second clause
-- and stays at one here - which is the observed result.
-- Also, the casts to int are not needed
foreach( $_SESSION as $field)
if( strpos($field, $projectAcronym) === 0 )
-- why ===? checking the return type of strpos for integer?
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 ) {
-- the previous if clause will trap on kounter >= 1, so this test
-- should be == 0 if kounter has any chance of going negative
-- otherwise it is useless.
if ((int)($_SESSION["${projectAcronym}_kounter"]) > 0)
(int)$_SESSION["${projectAcronym}_kounter"]++;
else
$_SESSION["${projectAcronym}_kounter"] = 1;
-- so we know that kounter is always zero, to only this line will
-- be used, moving kounter to 1.
}
print_r("After: ");
print_r($_SESSION["${projectAcronym}_kounter"]);
print_r("<P>");
//--END OF "Three Strikes You're Out"

-david-

Mar 28 '06 #3
Read my comments below in **

David Haynes wrote:
Oli Filth wrote:
comp.lang.php said the following on 27/03/2006 16:55:
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"
That's some of the most unreadable code I've ever seen.

It's still obtuse if you do reformat it...
My comments with '--' prefix.

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 )
-- up to here the two clauses of the if are identical


** How? I don't see how they're identical in any way, they're
completely distinctive
&& (int)$_SESSION["${projectAcronym}_kounter"] >= 1 ) {
-- if we get here, i.e. kounter > 0, then we never increment it
-- net result: the kounter goes from 0 in the second clause
-- and stays at one here - which is the observed result.
-- Also, the casts to int are not needed
** I don't follow you here. Sorry, elaborate more, please. And I've
had no luck without casts using $_SESSION objects
foreach( $_SESSION as $field)
if( strpos($field, $projectAcronym) === 0 )
-- why ===? checking the return type of strpos for integer?
** I am checking to see if the $_SESSION key starts with
"$projectAcronym", isn't that what strpos() does?
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 ) {
-- the previous if clause will trap on kounter >= 1, so this test
-- should be == 0 if kounter has any chance of going negative
-- otherwise it is useless.
if ((int)($_SESSION["${projectAcronym}_kounter"]) > 0)
(int)$_SESSION["${projectAcronym}_kounter"]++;
else
$_SESSION["${projectAcronym}_kounter"] = 1;
-- so we know that kounter is always zero, to only this line will
-- be used, moving kounter to 1.
}
** No it should not always be 0, it might be 0 but it could be 1, 2,
.... N. It's supposed to be at the point where you made a mistake and
it auto--increments.
print_r("After: ");
print_r($_SESSION["${projectAcronym}_kounter"]);
print_r("<P>");
//--END OF "Three Strikes You're Out"

-david-


Mar 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
2389
by: Alf P. Steinbach | last post by:
A few days ago I posted an "Hello, world!" tutorial, discussed in <url: http://groups.google.no/groups?threadm=41ba4c0a.76869078@news.individual.net>. As I wrote then: <quote> because there...
10
1410
by: Steven Matthew Bennett | last post by:
I don't know about the rest of the posters, but I came to this NG to learn more about Access, not to have some idiot homophobic dipshit spewing hate with every post. You have nothing to add to...
72
4124
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and...
48
4706
by: mahurshi | last post by:
I am new to c++ classes. I defined this "cDie" class that would return a value between 1 and 6 (inclusive) It runs fine and gives no warnings during compilation. I was wondering if you guys...
7
2208
by: relient | last post by:
Question: Why can't you access a private inherited field from a base class in a derived class? I have a *theory* of how this works, of which, I'm not completely sure of but makes logical sense to...
15
6703
by: Joe Van Dyk | last post by:
Can someone explain what a heap and what a stack is? And why I should care? I used to know, but then I forgot. And I can't seem to find it in the C++ FAQ. I keep reading how allocating from...
53
26330
by: fdmfdmfdm | last post by:
This is an interview question and I gave out my answer here, could you please check for me? Q. What are the memory allocation for static variable in a function, an automatic variable and global...
169
8948
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
7
2145
by: rynato | last post by:
Simple question, probably a simple answer: I have a php-based email form. There are three hidden variables passed from the initial page to the php script which handles sending the message: ...
0
7331
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.