Hi didnt know whether to post this on the Coding section since it will contain code but here goes !
I am currently finishing off a project and as i was creating this project I became more and more aware of the dangers of SQL Injection but since i didnt fully understand how to fully prevent it I left the issue for "do it when im finished"
Well now i am finished its come time to do it.
From my basic understanding , the only way someone can "hack" your website without being in the database itself is through
1) the use of textboxes
2) wherever $_request wants something from the URL
I presume any information entered through the use of radio buttons/checkbox/drop down is safe since its pre-defined by the website ? might be wrong ??
Now what im wondering is , is there a php function which can eliminate or severely reduce the risk of SQL injection ?
At first i used
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
But to my surprise i was told this type of function would actually help SQL injection cause it would remove in-built protection.
I have been looking around the net for snippets of code and found things like
If (!get_magic_quotes_gpc())
{
$searchterm = addslashes($searchterm);
}
But again im not really sure this would actually help.
Basically what im asking for is advice on how to stop SQL injection where the only 'leak' can come from string varibles in textboxs and again strings from URL .
If you can help at all it would be much appreciated.