Re: sanitizing/security

From: Date: Sun, 19 Dec 2004 04:11:33 +0000
Subject: Re: sanitizing/security
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-204670@lists.php.net to get a copy of this message
On Sat, 2004-12-18 at 22:50, Sebastian wrote: > just a question, what is the best way to sanitize your scripts when you're > using $_GET or $_REQUEST in a query? > > eg, i usually just do: > > if(is_numeric($_REQUEST['id'])) > { > mysql_query("SELECT id FROM table WHERE > id=".intval($_REQUEST['id']).""); > } > > what about when the GET is text? just use htmlspecialchars? > just looking for some advice to help keep my apps secure. For numeric values that I don't care about the value itself, only that it's numeric: $qString = "SELECT * FROM table where id = ".(0 + $_GET['someVar'])." " Binary operators are almost twice as fast as function calls. As for text... addSlashes() for mysql database if I'm using the raw mysql functions (which I don't do if I have a choice), otherwise I use the database layer's quote function which takes into consideration the database type. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#204670) next »