Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.