-
- if(phpversion() < '5.3.0') {
- set_magic_quotes_runtime(0);
- }
Copy code >> Magic_quotes_gpc cannot be defined through a function, so it is recommended to unify it on the server Turn it on. You should make a judgment when writing a program to avoid security issues caused by not turning on gpc.
When escaping gpc through addslashes, attention should be paid to the filtering of key and value when users submit 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 code
Use to escape html entities when user input or output to prevent xss vulnerabilities produce!
Today I encountered a problem with processing special characters in files. I noticed this problem again. In php:
-
- $str = "ffff
-----------------------
9
102 102 102 102 0 102 102 102 102
-
- Example of replacing special characters
-
-
$str = "ffff
-----------------------
8
102 102 102 102 102 102 102 102
Octal ascii code example:
//Note that a string that conforms to the regular pattern [0-7]{1,3} represents an octal ASCII code. - $str = "
-----------------------
11
0 1 2 3 7 8 9 0 56 92 56
-
- Hexadecimal ascii code example:
-
-
-
-
-
- $str = "x0x1x2x3x7x8x9x10x11xff";
- echo(strlen($str));
echo("n"); for($i=0;$i echo("n");
Copy code
Output result:
-----------------------
10
0 1 2 3 7 8 9 16 17 255
Detailed explanation of php special character escaping
- Example of php regular expression escape characters
-
- Commonly used escape character functions in PHP
-
- PHP function to escape regular expression characters
-
- php code to implement anti-injection and form submission value escaping
-
Examples of character escaping methods in mysql statements
Notes on php character escaping
|