当前位置:Gxlcms > 数据库问题 > 预防SQL注入攻击

预防SQL注入攻击

时间:2021-07-01 10:21:17 帮助过:3人阅读

/**
* 预防SQL注入攻击
* @param string $value

* @return string

*/
function check_input($value)
{
  // 去除斜杠
  if (get_magic_quotes_gpc())
  {
    $value = stripslashes($value);
  }
  // 如果不是数字则加引号
  if (!is_numeric($value))
  {
    $value = "‘" . mysql_real_escape_string($value) . "‘";
  }
  return $value;
}
/*
//eg:
$str = "‘ OR ‘‘=‘";
$str1 = "111";
echo check_input($str);  //输出:‘\‘ OR \‘\‘=\‘‘
echo "<br>";
*/

预防SQL注入攻击

标签:

人气教程排行