Jump to content

Recommended Posts

Now, I'm ussing this function to escape the variables I use in MySQL queries:

function escape($texto) {
$texto = trim($texto) ;
$texto = htmlspecialchars($texto) ;
return $texto ;
}

And It seems it works well (If it isn't secure, say me, please!).

The problem is when I want to insert HTML code in the DB, I have tried with mysql_real_escape_string() but " and ' are \" and \' when I show the html later and I must do something like:

$html = str_replace("\\'", "'", $html);
$html = str_replace("\\\"", "\"", $html);

But I think this shouldn't be the best way to do it. What do you think? any other way to do it?

Link to comment
https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/
Share on other sites

inserting into a database.. you should always make sure to use mysql_real_escape_string.. ' and " are used by malicious users for an attack known as SQL Injection..

 

to remove the slashes later..

 

stripslashes() will do the trick

Link to comment
https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/#findComment-720453
Share on other sites

I have tried to do stripslashes() before mysql_real_escape_string() and now, I don't need stripslashes() later to show the result because the \ aren't in the DB.

Is this because magick quotes are on and without magick quotes people don't need to use stripslashes() never?

Link to comment
https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/#findComment-720700
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.