<? PHP
$ _ 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;
}
// You can use the following Code Is also from copy. If there is a problem or a change to the system, I will add a description:
/*
Function Name: inject_check ()
Function function: checks whether submitted values contain SQL Injection characters to prevent injection and protect server security.
Parameter: $ SQL _str: Submitted variable
Return Value: Return detection result, true or false
*/
Function inject_check ($ SQL _str)
{
Return eregi ('select | insert | update | Delete |/* | .. /|. // | Union | into | load_file | OUTFILE ', $ SQL _str); // Filter
}
/*
Function Name: verify_id ()
Function: checks 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 ('submitted parameter is invalid! '); // Injection judgment
}
Elseif (! Is_numeric ($ id ))
{
Exit ('submitted parameter is invalid! '); // Number judgment
}
$ Id = intval ($ id); // integer
Return $ ID;
}
/*
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;
}
/*
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 () // you can check 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;
}
?>