Home > Article > Backend Development > Example of filtering paging parameters in PHP to prevent sql injection, sql paging_PHP tutorial
The example in this article describes the method of filtering paging parameters in PHP to prevent SQL injection. Share it with everyone for your reference. The specific analysis is as follows:
As far as network security is concerned, do not trust any input information on the Internet. We must perform parameter filtering for any input information. In this regard, let’s first take a look at the following example:
I hope this article will be helpful to everyone’s PHP programming design.
I wrote a code to prevent SQL injection in PHP4 environment. After actual use, it is also compatible under PHP5. Everyone is welcome to modify and use it.
The code is as follows:
/*
sqlin anti-injection class
*/
class sqlin
{
//dowith_sql($ value)
function dowith_sql($str)
{
$str = str_replace("and","",$str);
$str = str_replace("execute","",$ str);
$str = str_replace("update","",$str);
$str = str_replace("count","",$str);
$str = str_replace(" chr","",$str);
$str = str_replace("mid","",$str);
$str = str_replace("master","",$str);
$str = str_replace("truncate","",$str);
$str = str_replace("char","",$str);
$str = str_replace("declare","" ,$str);
$str = str_replace("select","",$str);
$str = str_replace("create","",$str);
$str = str_replace ("delete","",$str);
$str = str_replace("insert","",$str);
$str = str_replace("'","",$str);
$str = str_replace(""","",$str);
$str = str_replace(" ","",$str);
$str = str_replace("or"," ",$str);
$str = str_replace("=","",$str);
$str = str_replace("%20","",$str);
// echo $str;
return $str;
}
//aticle() Anti-SQL injection function
function sqlin()
{
foreach ($_GET as $key=> ;$value)
{
$_GE...the rest of the text>>
Basically, I use the two methods htmlspecialchars() and mysql_escape_string() to process the obtained parameters. .