Welling Posted December 20, 2008 Share Posted December 20, 2008 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 More sharing options...
RussellReal Posted December 20, 2008 Share Posted December 20, 2008 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 More sharing options...
Welling Posted December 21, 2008 Author Share Posted December 21, 2008 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 More sharing options...
DeanWhitehouse Posted December 21, 2008 Share Posted December 21, 2008 Use addslashes(); and mysql_real_escape_string(); and then when you recall the data use stripslashes(); to remove the slashes Link to comment https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/#findComment-720711 Share on other sites More sharing options...
Welling Posted December 21, 2008 Author Share Posted December 21, 2008 Ehh.. I think you haven't understood it, maybe if I use addslashes(); and mysql_real_escape_string(); and magick quotes on I will get \\\\\\\' adn \\\\\\\". My question was if doing stripslashes() before mysql_real_escape_string() was secure... Link to comment https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/#findComment-720750 Share on other sites More sharing options...
DeanWhitehouse Posted December 21, 2008 Share Posted December 21, 2008 It is but why would you want to remove the slashes first :s You can always disable magic quotes Link to comment https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/#findComment-720752 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 .htaccess file, add a line php_flag magic_quotes_gpc off Link to comment https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/#findComment-720754 Share on other sites More sharing options...
Welling Posted December 21, 2008 Author Share Posted December 21, 2008 Yes, but If I don't disable magic quotes I must do the stripslashes() Then without magic quotes, stripslashes() isn't needed neither before and after insert in the DB? Link to comment https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/#findComment-720755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.