- if (Phpversion () < ' 5.3.0 ') {
- Set_magic_quotes_runtime (0);
- }
Copy Code>> cannot define MAGIC_QUOTES_GPC through functions, so it is recommended to open the server uniformly, when writing the program should be judged, to avoid the security problems when the GPC is not turned on by Addslashes to the GPC when escaping, You should be aware of the filtering of key values and values when the user submits the array data
if (!GET_MAGIC_QUOTES_GPC ()) {
- $_get = Daddslashes ($_get);
- $_post = Daddslashes ($_post);
- $_cookie = Daddslashes ($_cookie);
- $_files = Daddslashes ($_files);
- }
- function Daddslashes ($string, $force = 1) {
- if (Is_array ($string)) {
- foreach ($string as $key = = $val) {
- Unset ($string [$key]);
- $string [Addslashes ($key)] = Daddslashes ($val, $force);
- }
- } else {
- $string = Addslashes ($string);
- }
- return $string;
- }
?>>
Copy CodePrevent XSS exploits by escaping HTML entities at user input or output! Today, I came across a special character to handle the file, and again notice the problem in PHP:
- $str = "FFFF\0FFFF";
- Echo (strlen ($STR));
- Echo ("\ n");
- for ($i =0; $i
- Echo ("\ n");
Copy CodeOutput Result:----------------------9 102 102 102 102 0 102 102 102 102 Examples of replacing special characters
- $str = "FFFF\0FFFF";
- $str = Str_replace ("\x0", "", $str);
- or with $STR = Str_replace ("n", "", $str);
- or with $STR = Str_replace (chr (0), "", $str);
- Echo (strlen ($STR));
- Echo ("\ n");
- for ($i =0; $i
- Echo ("\ n");
Copy CodeOutput Result:----------------------8 102 102 102 102 102 102 102 102 An example of an octal ASCII code:
- Note that a string that conforms to the regular \[0-7]{1,3} represents an octal ASCII code.
- $str = "\0\01\02\3\7\10\011\08\8"; The \8 here do not meet the requirements and are revised to "\\8" (ASCII 92 and 56)
- Echo (strlen ($STR));
- Echo ("\ n");
- for ($i =0; $i
- Echo ("\ n");
Copy CodeOutput:----------------------11 0 1 2 3 7 8 9 0 56 92 56 Example of hexadecimal ASCII code:
- $str = "\x0\x1\x2\x3\x7\x8\x9\x10\x11\xff";
- Echo (strlen ($STR));
- Echo ("\ n");
- for ($i =0; $i
- Echo ("\ n");
Copy CodeOutput:----------------------0 1 2 3 7 8 9 255 PHP special character escapes details php regular expression escape character php common escape character function Php escaped regular expression characters PHP implementation anti-injection and form submission value Escaped code a method for escaping characters in a MySQL statement an example of PHP character escapes related considerations |