Method of filtering sql injection by $_ GET and $_ POST in php

  • 2021-07-24 10:24:32
  • OfStack

This article describes the example of php $_ GET and $_ POST filtering sql injection method, to share for your reference. The specific analysis is as follows:

This function can only filter some sensitive sql commands, like id=1, we still need to filter them simply.

The main implementation code is as follows:

if (!get_magic_quotes_gpc())
{
if (!empty($_GET))
{
$_GET  = addslashes_deep($_GET);
}
if (!empty($_POST))
{
$_POST = addslashes_deep($_POST);
}
$_COOKIE   = addslashes_deep($_COOKIE);
$_REQUEST  = addslashes_deep($_REQUEST);
}
function addslashes_deep($value)
{
if (empty($value))
{
return $value;
}
else
{
return is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value);
}
}

I hope this article is helpful to everyone's PHP programming.


Related articles: