http://thisismedia.c...njection-in-ph/
Prevent SQL Injection with PHP
#1
Posted 28 March 2011 - 12:59 PM
http://thisismedia.c...njection-in-ph/
#2
Posted 28 March 2011 - 01:26 PM
Cabbage, on 28 March 2011 - 12:59 PM, said:
http://thisismedia.c...njection-in-ph/
Very nice topic, but technally a simple function as below would prevent injections quite well
function clean_data($data){
global $mysqli;
return mysqli_real_escape_string(trim(htmlentities($data,ENT_QUOTES,'UTF-8')));
}
then use that on any data going into mysql
also filtering things that require int only to int only
$id = $_GET['id'];
$id = preg_replace('#[^0-9]#i', '', $id);
This post has been edited by webdesigner93: 28 March 2011 - 01:27 PM
#3
Posted 28 March 2011 - 01:48 PM
webdesigner93, on 28 March 2011 - 01:26 PM, said:
function clean_data($data){
global $mysqli;
return mysqli_real_escape_string(trim(htmlentities($data,ENT_QUOTES,'UTF-8')));
}
then use that on any data going into mysql
also filtering things that require int only to int only
$id = $_GET['id'];
$id = preg_replace('#[^0-9]#i', '', $id);
I was going to write about casting to integers etc but I'm trying to keep it simple. Add it to the tutorial in the comments if you wish, might help someone using it
#4
Posted 28 March 2011 - 02:14 PM
Cabbage, on 28 March 2011 - 01:48 PM, said:
I will deff do that
#5
Posted 29 March 2011 - 11:36 AM
webdesigner93, on 28 March 2011 - 02:14 PM, said:
Well at work we've been asked to blog a few times a week so the company appears more social. Should be able to keep a regular blog and get paid for the pleasure
#6
Posted 29 March 2011 - 08:54 PM
Cabbage, on 28 March 2011 - 12:59 PM, said:
http://thisismedia.c...njection-in-ph/
Well written article. However, just use PHP PDO. PDO binding does this for you and with pdo binding SQL injections are near on impossible.
#7
Posted 30 March 2011 - 04:13 AM
Avera, on 29 March 2011 - 08:54 PM, said:
I think personally prepared statements are a lazy way of doing things, and can also get people out of the habit of filtering there data properly, not just for sql statements but for app security in general, plus mysql_real_escape_string does a good job of preventing most sql injects without the extra work of binding params ect..
Help


















