For general anti-injection, you only need to use the php addslashes function. $ _ POSTsql_injection ($ _ POST); $ _ GETsql_injection ($ _ GET); functionsql_injection ($ content) {if (! Get_magic_quotes_gpc () {if (I... general anti-injection, you only need to use the addslashes function of php.
Php code
$ _ POST = SQL _injection ($ _ POST );
$ _ GET = SQL _injection ($ _ GET );
Function SQL _injection ($ content ){
If (! Get_magic_quotes_gpc ()){
If (is_array ($ content )){
Foreach ($ content as $ key => $ value ){
$ Content [$ key] = addslashes ($ value );
}
} Else {
Addslashes ($ content );
}
}
Return $ content;
}
Php code
/**
* Function name: inject_check ()
* Function: checks whether the submitted value contains SQL injection characters to prevent injection and protect server security.
* Parameter: $ SQL _str: submitted variable
* Return value: return the detection result, true or false.
*/
Function inject_check ($ SQL _str ){
Return eregi ('select | insert | update | delete | \ '| \/\ * | \. \. \/| \. \/| union | into | load_file | outfile ', $ SQL _str); // filter
}
Php code
/**
* Function name: verify_id ()
* Function: Check whether the submitted ID class value is valid.
* Parameter: $ id: submitted ID value
* Return value: return the ID after processing.
*/
Function verify_id ($ id = null ){
If (! $ Id) {exit ('no submission parameter! ');} // Determines whether it is null.
Elseif (inject_check ($ id) {exit ('The submitted parameter is invalid! ');} // Injection judgment
Elseif (! Is_numeric ($ id) {exit ('The submitted parameter is invalid! ');} // Number judgment
$ Id = intval ($ id); // integer
Return $ id;
}
Php code
/**
* Function name: str_check ()
* Function: filter submitted strings.
* Parameter: $ var: string to be processed
* Return value: returns the filtered string.
*/
Function str_check ($ str ){
If (! Get_magic_quotes_gpc () {// determines whether magic_quotes_gpc is enabled
$ Str = addslashes ($ str); // filter
}
$ Str = str_replace ("_", "\ _", $ str); // filter '_'
$ Str = str_replace ("%", "\ %", $ str); // filter '%'
Return $ str;
}
Php code
/**
* Function name: post_check ()
* Function: Process submitted edits.
* Parameter: $ post: content to be submitted
* Return value: $ post: the filtered content is returned.
*/
Function post_check ($ post ){
If (! Get_magic_quotes_gpc () {// determines whether magic_quotes_gpc is enabled.
$ Post = addslashes ($ post); // filter submitted data when magic_quotes_gpc is not enabled
}
$ Post = str_replace ("_", "\ _", $ post); // filter '_'
$ Post = str_replace ("%", "\ %", $ post); // filter '%'
$ Post = nl2br ($ post); // press enter to convert
$ Post = htmlspecialchars ($ post); // html tag conversion
Return $ post;
}