Join the forums now, and start posting to receive access to our Scripts Vault!
I've been looking at ways to prevent this and the most common I can see is the add slash function, what do you think and what do you use?
Don't bother trying to escape user input
Quote from: pirategaspard on June 30, 2011, 07:05:49 AMDon't bother trying to escape user inputOnly in context of the SQL if using prepared statements! and be careful about thatGenerally never trust anything that's received from user (from forms, urls, http headers, anything)... actually, many people say never trust any input, thus not even your files or database - because for example you can escape input by prepared statements in SQL context, but if you print it out then, user can sneak in some JS script - so always escape/validate
addslashes is fine, but it is recommended to use mysql_real_escape_string instead (prevents SQL injection for some exotic charsets).
Also very important thing, make sure integers are integers (or just make a dirty "a='var'" so everything is treates as a string). You need it to prevent integer injection which does not require slashes. Example "WHERE a=$var" hack: "$var=5 OR 0" if you do "WHERE a='$var'" it won't work; of course properly would be to make "$var=(int)$_GET['var']" instead.
Quote from: Chris on June 30, 2011, 07:31:58 AMaddslashes is fine, but it is recommended to use mysql_real_escape_string instead (prevents SQL injection for some exotic charsets).How is it fine then if it prevents only something?
So for every query you execute it must go to the sql server to validate then return and then you submit the prepared query and get your result.
Unlike the mysql extension, mysqli does not provide a separate function for opening persistent connections. To open a persistent connection you must prepend p: to the hostname when connecting.
Obviously there will be no speed benefit if you only use a query once however.
Edit: hadn't researched persistent connections before, but PHP manual says you can do them with mysqli as of 5.3Unlike the mysql extension, mysqli does not provide a separate function for opening persistent connections. To open a persistent connection you must prepend p: to the hostname when connecting.
Which is why everyone should test for there own usage. I was simply pointing out the pitfalls of mySQLi extension which is not the panacea many point it out to be. For our games this simply is not the case as you have hundreds of players playing 4 different games and games unlike other site are equal to write operations as they are to read which really plays havoc with the query cache.