Weak PHP security question notes and php security question notes
I. type conversion problems
Intval (); var_dump (intval ('1asdfasd'); // 1 var_dump (intval ('awqw12'); // 0 var_dump (intval (array ())); // 0 var_dump (intval (array ('foo', 'val'); // 1 var_dump (intval (0x1A )); // 26 hexadecimal conversion var_dump (intval ('asdfqwer '); // 0
Intval if the conversion value is a string, no error is returned, but 0 is returned. If the conversion value is an array, there are two cases. If the conversion value is an empty array, 0 is returned, otherwise, 1 is returned.
Note: php uses a 32-Bit Memory to store an integer. A 32-bit memory can represent 4294967296 digits, with the characters-2147483647 to 2147483648;
Ii. Loose problem of built-in functions
switch(); $i='3adcd'; switch($i){ case 1: echo 'i is 1'; break; case 2: echo 'i is 2'; break; case 3: echo 'i is 3'; break; default: echo 'i is default'; break; }
The above result enters switch case 3. Why? If switch is a case of the numeric type, switch converts the parameter to the int type, therefore, during the above execution, $ I is converted to type first, and the conversion result is 3...
in_array(); $arr = [0,1,2,3,'test']; var_dump(in_array('abd',$arr)); // true var_dump(in_array('1bc',$arr)); // true
Why is the above execution result like this? I will use the query manual later. The official statement is that in_array adopts the loose comparison method by default, and the ratio is equal only, the above result is available only when the type of the value is the same, but the third parameter of the in_array function can be set to True, which is a rigorous comparison method.
The above are common areas of attention for development.