hi i would like to know what steps you guys take to avoid php hacks such as sql injection, xss hacks.

This is a php function to avoid sql injection.

<?
function cleanQuery($string)
{
  if(get_magic_quotes_gpc())  // prevents duplicate backslashes
  {
  	$string = stripslashes($string);
  }
  if(phpversion() >= '4.3.0')
  {
    $string = mysql_real_escape_string($string);
  }
  else
  {
    $string = mysql_escape_string($string);
  }
  return $string;
}

// if you are using form data, use the function like this:
if (isset($_POST['itemID'])) $itemID = cleanQuery($_POST['itemID']);

// you can also filter the data as part of your query:
$sql = "SELECT * FROM items WHERE itemID = '".  cleanQuery($itemID)."'";

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.