.
Home > MySQL, PhP, Tech > Sanitize MySQL Inputs

Sanitize MySQL Inputs

November 13th, 2009 Leave a comment Go to comments

SQL injection attack
Prepare the data so that when it gets added to your SQL query it doesn’t break the server ( Defence SQL injection attack ).
When a form has been submitted via GET or POST all data is stored in the global array:
$_GET , $_POST, $_REQUEST and $_COOKIE.

<?php

function sanitize(&$t){
$t = array_map(‘trim’, $t);
$t = array_map(’stripslashes’, $t);
$t = array_map(‘mysql_real_escape_string’, $t);
}

function sanitize_input() {
sanitize($_POST);
sanitize($_GET);
sanitize($_REQUEST);
sanitize($_COOKIE);
}

sanitize_input();

?>

sanitize_input() will check all global arrays like $_GET, $_POST, $_REQUEST, $_COOKIE, allow only valid data!

  1. No comments yet.
  1. No trackbacks yet.

GoCache - ByREV-Cache v1.0 - live served in : 0.689165 sec