1) when the user input content may contain single quotation marks, double quotation marks, backslash, and null NUL, it is executed in mysql statements, set magic_quotes_gpc in APACHE to On. if the AP... 1) when the user input content may contain single quotation marks, double quotation marks, backslash, and null NUL, it is executed in mysql statements, set magic_quotes_gpc in APACHE to On.
If this item in APACHE is set to Off, the php function addslashes () can be used for the same purpose. However, the two methods cannot be used at the same time. Otherwise, the replacement is repeated and an error occurs.
The sample PHP code is as follows:
Of course, if the magic_quotes_gpc item in APACHE is On but sometimes does not want to escape a special character, you can use stripslashes () to remove it.
2) filter the characters that affect the normal operation of MSSQL.
The magic_quotes_sybase item in APACHE should be set to On when the user-entered content may contain single quotes and executed in mssql statements. in this case, the magic_quotes_gpc item does not take effect.
If this option in APACHE is set to Off, php does not have a suitable function to achieve the same purpose, you can only use the string replacement function to achieve this purpose.
Example: PHP code:
Currently, PHP on 10.218.17.53 needs to access both mysql and mssql. the configuration in APACHE does not take into account the two types of databases. Therefore, only mysql is configured accordingly.
2. measures should be taken to input SQL statements.
The following two SQL writing methods are common, but the security level is different. when the user submits the $ id = '1 and 1 = 2 union select... ', the first type will show the data that should not be displayed, and the second type will be relatively safer.
SQL code:
Select * FROM article Where articleid = $ id
Select * FROM article Where articleid = '$ ID'
3. prevent the normal display of the page from being affected by html tags or javascript. you can use htmlspecialchars () to filter the & "<>, PHP code:
$ Content = htmlspecialchars ($ content );
4. when the content to be displayed on the page contains the line breaks, you can use nl2br () to achieve the effect of line breaks on the page.
Method 1.
"; Print" $ user1
"; Print" method 2 -----------------
"; Print" $ user2
";
Method 2.
= 0) {return $ tag_str.mysql_real_escape_string ($ string ). $ tag_str;} $ string = str_replace ("'", "[url = file: // \] \' [/url]", str_replace ('\', '\', str_replace ("", "[url =] \ [/url]", $ string); return $ tag_str. $ string. $ tag_str;} return $ tag_str.str_replace ('\ "', '"', $ string ). $ tag_str ;}
Tutorial address:
Reprinted! But please include the article address ^