Jump to content

Recommended Posts

I made the following function to validate info being sent to my database:

 

function valid($text){
$text = str_replace(" ","", $text);
	if (empty($text))
		return false;

$text = eregi_replace("([a-z0-9]+)","",$text);

if (empty($text))
	return true;
else
	return false;
}

 

would this be enough or would I still need to use mysql_real_escape_string() for some reason?

It only allows lowercase and numbers, unless I'm missing something?

Link to comment
https://forums.phpfreaks.com/topic/169436-mysql_real_escape_string-question/
Share on other sites

Unfortunately, hexadecimal encoded characters can be used to inject sql (you can inject things like single-quotes without supplying actual single-quotes by using hexadecimal), so things like the following (harmless examples) would get past the eregi_replace code that was posted  -

 

0x274d7953514c27

0x275061756c27

 

Unfortunately, hexadecimal encoded characters can be used to inject sql (you can inject things like single-quotes without supplying actual single-quotes by using hexadecimal), so things like the following (harmless examples) would get past the eregi_replace code that was posted  -

 

0x274d7953514c27

0x275061756c27

 

 

Yeah, but even:

 

INSERT INTO foo (bar) VALUES ('0x275061756c27');

 

Wouldn't work (from an attacker's point of view). If you've made sure that your string only contains alphanumeric characters and you delimit the string in quotes there is no way any SQL injection vulnerability would be possible.

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.