Jump to content

SQL Injection.. Your opinion..


ataria

Recommended Posts

This is what I have so far.


[code]
<?php

// database connection.
function protect($input)
{
$input = mysql_real_escape_string($input);
$input = eregi_replace("%","",$input);
$input = eregi_replace("--","",$input);
$input =htmlspecialchars(mysql_real_escape_string($input));

return $input;
}

$_COOKIE = array_map("protect",$_COOKIE);
array_map('mysql_real_escape_string', $_POST);
array_map('mysql_real_escape_string', $_GET);

?>
[/code]

Is there anything I need to add?
or, is it good enough?

Link to comment
Share on other sites

mysql_real_escape_string() already does the necessary escaping.  As long as you use that string inside single quotes, you will be fine.

There's no need for the other lines.

You might need to urldecode() your input first as well, depending on what type of input it is.

[code=php:0]$escaped_input = mysql_real_escape_string(urldecode($_POST['input']));
$sql = "INSERT INTO table VALUES ('$escaped_input')";[/code]
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.