3 ms·
Perhaps you ask a user to enter the month of their CC expiration date, which is shown as 08/14 on their card. $v = validated_integer($user_input); // the use
by jessedhillon 15y ago
Perhaps you ask a user to enter the month of their CC expiration date, which is shown as 08/14 on their card.
$v = validated_integer($user_input); // the user input 08
if($v == 0 || $v === 0) { // let's just be safe
// the Wrong Thing happens
}
This is a contrived example, sure. But you've never checked to see if a user input the number 0? Or a non-zero, positive integer?
- wvenable 15y agoI'm not sure what you expect to happen there but the following code always produces "Correct!": $user_input = '08'; $user_input = (integer)$user_input; if ($user_input == 8) echo 'Correct!'; if ($user_input == 0) echo 'Incorrect!'; If you take out the cast, the result is the same. If you change the numbers to '010' and 10 respectively, the result is also "Correct!". There is no weirdness.
- DisposaBoy 15y agoThat's not a PHP issue. It's a programmer issue. Validate the bloody input properly! e.g if someone types in a phone number with hyphens or a credit card number which may contain spaces, don't blindly check it for a number...