Forum Moderators: coopster
$query = "SELECT * FROM users where Uname = '".mysql_real_escaep_string($_POST['username'])."'";
Hope this explains a little. You may also want to refer to Database Security [us2.php.net] from php.net.
Good luck!
That is one aspect of the issue, however I was looking for a more generic solution which could be plugged into the form processing code, like:
function sanitize_input ($UserInput){// replace newlines with strings
// add/remove slashes
// check and eliminate any malicious characters
// mysql_real_escape the input if reqired
// return the input in an optional different array
}
which could then be used in a form processing script like so:
$f_user_input = sanitize_input($_POST);
$query = $db->query("select * from database.table where username like '$f_user_input[name]'");
essentially all the filtering, checking happens inthe function..
Thanks in advance...
I use a generic solution for my CMS. Nice and easy, but I base64 encoode any data that's from the public to my DB (such as web forms) to stop SQL injection and so on!
It can be done very easily, but it's just finding the time to do it! ++ when you write it yourself, you know it inside and out, whereas if someone else writes it for you, there's always that awkwardness with knowing what to do and how to use it!
well to be honest, unless you are highly proficient with data washing I really don't think this is the best idea. The benefit of using a predefined class is that you have the advantage of someone else's vast experience.
It is very difficult for someone who isn't proficient at this to not know all the eventualities you need to code for.
I suggest that for any sanitation class/function you use, you read it to understand exactly what it is doing. I also suggest you log all failures to better analyze what data is getting denied and why.