Join the forums now, and start posting to receive access to our Scripts Vault!
working on some code and wondering if player key/ID used on your games are most of the time numeric and if you have a guess of the % of alphanumeric ones?
Not that I'm lazy but it's a bit of pain to modify and complete sql injections protects if I need to change
Use SQL placeholders/parameters and you don't have to worry about SQL injection. Period. No matter what you change. It's 20-freaking-10 and there is no excuse for trying to escape strings instead of using placeholders.
Quote from: dsheroh on February 08, 2010, 05:57:56 AMUse SQL placeholders/parameters and you don't have to worry about SQL injection. Period. No matter what you change. It's 20-freaking-10 and there is no excuse for trying to escape strings instead of using placeholders.Woo hoo! Another advocate of better security! In MySQL this is called "prepared statements" look it up, you'll be glad you did. Oh, and welcome to 2005. lol +1 dsher.
I know it's really off topic and all, but i went to that page to learn about well what it said since i'm always up for making myself more secure. and it reminded me of when i first saw the comic, i had no idea that it was really saying what it was. Till, i looked up sanitizing your inputs and came to mysql injection. Which was a little thing i saw on hackthissite. And also wow dsheroh. Never heard of that site before or new that anything like that existed... i just thought sanitizing the input was a good measure.
Quote from: 133794m3r on February 09, 2010, 12:19:48 PMI know it's really off topic and all, but i went to that page to learn about well what it said since i'm always up for making myself more secure. and it reminded me of when i first saw the comic, i had no idea that it was really saying what it was. Till, i looked up sanitizing your inputs and came to mysql injection. Which was a little thing i saw on hackthissite. And also wow dsheroh. Never heard of that site before or new that anything like that existed... i just thought sanitizing the input was a good measure.You never heard of bobby-tables.com before because it's fairly new. IIRC, Andy just set it up within the last month or so.
Unfortunately using prepared statements requires the use of the mysqli extension. Normally this would not be a problem, however, mysqli does NOT support persistent connections. Without careful testing just saying "use mysqli and prepared statements" could put someone in a database nightmare depending on there server setup and what they are pulling for traffic.
Secondly although the security is superior with prepared statements you have to know what the server is doing. When you prepare a statement that is one trip to the db server, then you execute the statement and that is another trip to the db server. So now you've doubled your load to the database server.
And also what code said, i doubt it'll be right for me though then until i get a nice stable playerbase set up, since 2 database connections per page request is definately going to put a hamper on my performance.
Quote from: codestryke on February 09, 2010, 01:21:34 PMUnfortunately using prepared statements requires the use of the mysqli extension. Normally this would not be a problem, however, mysqli does NOT support persistent connections. Without careful testing just saying "use mysqli and prepared statements" could put someone in a database nightmare depending on there server setup and what they are pulling for traffic.http://bobby-tables.com/php.html now shows examples for using prepared statements in PHP under the mysqli, ADODB, ODBC, and PDO extensions. Do all of those options fail to support persistent connections? (And, for that matter, does PHP really only give access to persistent connections at the database library level? When I think about persistent db connections for web apps in Perl, I generally think of them being managed by apache, not by DBI. But, then, I generally think in terms of persistent applications rather than persistent db connections anyhow...)Quote from: codestryke on February 09, 2010, 01:21:34 PMSecondly although the security is superior with prepared statements you have to know what the server is doing. When you prepare a statement that is one trip to the db server, then you execute the statement and that is another trip to the db server. So now you've doubled your load to the database server.If you only use each prepared statement once, sure. But database-intensive apps generally run basically the same query several times, differing only in WHERE clause conditions or values to INSERT/UPDATE, all of which can be parameters for a pre-prepared statement. Reuse the prepared statement and the number of trips to the database only increases to n+1, not 2n.Also take into account that, even if you don't explicitly prepare the statement before executing it, the server still has to implicitly prepare it. By reusing the prepared statement, you avoid repeating that overhead and will, in most cases, reduce the overall load on the database server.Quote from: 133794m3r on February 10, 2010, 08:06:45 AMAnd also what code said, i doubt it'll be right for me though then until i get a nice stable playerbase set up, since 2 database connections per page request is definately going to put a hamper on my performance.You misunderstood his second point. Doing a separate prepare, then execute requires an additional request to the database server, not an additional connection.
Also my main worry for this is that i've yet to benchmark any of this on my server yet so i have no idea what type of performance i should expect. And if it can only do let's say 20 requests per second, and if i have 200 players online(also a high estimation for this purpose and a man can dream), and if they're randomly clicking around doing things. This'd mean that i currently with x number of requests per page be able to serve y people. If it's 2x the amount of requests. Then that'd mean that i'd only be able to server y/2 number of people per second which would then result in decreased performance which may then make them leave my game.