endl wrote:I would like to know more about these injection techniques to protect myself. Not sure I completely understand.
Well unless you're using MySQLi or PDO and utilizing the prepared queries, you need to sanitize all user-supplied data (that inclues GET, POST, COOKIE, and even some of the data from the $_SERVER array) before using it in a SQL query. The [man]mysql_real_escape_string/man is the general way of doing this. I like to keep my code nice and clean by using [man]sprintf/man to build the query string:
$query = sprintf("INSERT INTO table1 (col1, col2, col3, col4) VALUES ('%s', '%s', %d, '%s')",
mysql_real_escape_string($_POST['field1']),
mysql_real_escape_string($_POST['field2']),
$_POST['field3'],
mysql_real_escape_string($_POST['field4'])
);
If you don't use sprintf() and the '%d' identifier for numbers, you could always cast them to integers/floats to sanitize them:
$id = (int)$_POST['id'];
// if a malicious script/user had sent "5 OR 1==1", $id now contains only 5
Essentially, you just want to prevent quotes, line breaks, and other characters from (intentionally or accidentally) altering or breaking your SQL queries.
endl wrote:If not through the browser then how?
Command line, other PHP scripts, a botnet, etc. etc. - browsers aren't the only way to interface with websites.
endl wrote:My input checks are pure server side as much as I know how to do no javascript.
Well it depends on what you mean by "check". If you strip out all non-alphanumeric characters for strings or any non-numeric characters for numeric values, then I guess you could consider the data already sanitized. Even so, I've always agreed that I'm "better safe than sorry" and have always sanitized external data before using it in SQL queries.