Jump to content

mysql_real_escape_string


mbrown

Recommended Posts

Is mysql_real_escape_string the only thing i should use to prevent sql injection when i am validating a log in like the following

 

$username = mysql_real_escape_string($_POST['username'];
$password = mysql_real_escape_string($_POST['password'];

 

what else can i do?

Link to comment
Share on other sites

no it is not the only thing

 

 

Google good injection prevention techniques as there are plenty of resources the key is you need to look at a few things

 

1) What is the garbage comming in?  What format what format should it be how can it come in wrong

2) Where is the garbage in getting stored (Update or Insert here)

3) When the garbage is commin out how is it being using (echo/print integer modification eval)

 

 

Link to comment
Share on other sites

Hey there,

 

Hmm I would also suggest using htmlspecialchars(), personally I always use a function:

<?php
function db_protect($string) {
  return htmlspecialchars(mysql_real_escape_string($string));
}
?>

 

But you have to think about where will the data be sent from, what format will it come in and what will it be used for.

Link to comment
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.