At 3/3/08 09:31 AM, phyconinja wrote:
Wouldn't it be safer to just use stripslashes() on the things you need to? Instead of using it on everything?
You obviously could, but before you use stripslashes you must check whether magic quotes are on or not, otherwise a perfectly legit user trying to use \' for some reason will end up not seeing his backslash. That adds another line of code to your script and can get very bloated after a while. I prefer my way of escaping everything and making sure your code is secure from the ground-up (that is using intval for id, mysql_real_escape_string for everything else). If you're like me, though, you've got a Database abstraction layer combined with a security layer that takes care of everything.
For example I don't need to run queries, I do
$posts = $db->fetchAll('topic_id',$_GET['topic_id']);
and I've got all the posts from the topic i need. The Security layer checks the datatype for the "topic_id" field in the database, and if it's of type INT I run intval() on the parameter. You have no idea how simple it makes coding websites, especially with a flexible template system:
//IN TEMPLATE
{{ foreach post }}
Date: {{ post.date_posted }}
User: <a href="profile.php?id={{ post.user_id }}">{{ post.user }}</a>
{{ end post }}
I love my custom framework :)