Jump to content


Can you help me


4 replies to this topic

#1 dungiis

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 02 December 2006 - 12:13 AM

How to fix sql injection !
Anyone has that function ! Please suggetion for me
thank guys

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 02 December 2006 - 12:33 AM

I swear, people have forgotten how to type and click 'search' nowadays...
http://www.pixel2lif...%20injection/1/

I personally use this function on any information to be placed into a query.

function safe_query($value){
		if(get_magic_quotes_gpc()) $value = stripslashes($value);
		if(!is_numeric($value)) $value = "'".mysql_real_escape_string($value, $this->conn)."'";
		return $value;
	}

Example.
$query = mysql_query("SELECT * FROM `members` WHERE `username` = ".safe_query($_POST['username'])." AND `password` = ".safe_query($_POST['password'])." LIMIT 1") or die(mysql_error());

Real simple stuff.

#3 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 02 December 2006 - 12:44 AM

As much as I love your example with your function. Your query isn't the safest =/.

SELECT * FROM users WHERE LOWER(userName) = '".mysql_real_escape_string(strtolower(($_POST['userName']))."' LIMIT 1

After running that query, you then compare the hash with their given password, thats proper user validation. Not criticizing, just making it safer coding community out there.

#4 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 02 December 2006 - 12:53 AM

That's not from my actual code, that was just an example I whiped up just then. ;)

Thanks for the suggestion of using LOWER though, I'd completely forgotten about that command. :)

#5 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 02 December 2006 - 03:32 AM

I always use to validat my stuff:

function mes($data) {

$data = mysql_real_escape_string(strip_tags(htmlspecialchars($data);
return $data;

}

Its qucik and simple.

Matt





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users