Jump to content

Input Validation


Omzy

Recommended Posts

Well, with strip_tags() you completely remove html tags, so there's not much point in using htmlspecialchars() as well.

 

mysql_real_escape_string is almost mandatory. If you don't use it, your query will break if you have a quote in the input. (unless magic quotes is on, but we all know that's stupid and should be turned off).

 

It also prevents sql injection, and goes one step further than addslashes(). For example, If I were to put 0x27 into your input, it would convert it to a single quote ('). addslashes wouldn't pick that up, but mysql_real_escape_string would, and escape it.

Link to comment
https://forums.phpfreaks.com/topic/159463-input-validation/#findComment-841394
Share on other sites

Basically the 'ID' is got from the URL construct and there is a form on the page, clicking Submit will POST that form and it gets processed in the script as:

 

if(isset($_POST['delete']))
{
$query="DELETE FROM table WHERE id='$_GET['id']'";
//run the mysql_query
}

 

So is this safe enough? All the IDs in the database are INTs, do I need to do any intval() check or anything else?

Link to comment
https://forums.phpfreaks.com/topic/159463-input-validation/#findComment-841626
Share on other sites

Well, if I put this is the url: &id=';DELETE FROM `sometable` WHERE'1'='1

Your query would then look like this:

$query="DELETE FROM table WHERE id='';DELETE FROM `sometable` WHERE'1'='1'";

So someone could potentially truncate, dump or delete one of your tables. You need to run mysql_real_escape_string() on EVERYTHING being used with a database. That would escape all single quotes in that statement, so it would work fine.

Link to comment
https://forums.phpfreaks.com/topic/159463-input-validation/#findComment-841652
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.