New Coder Posted December 9, 2009 Share Posted December 9, 2009 Hello all, I have some web pages that use the following from a form to input into a mssql db: function fix_quotes($str) { $fix_str=stripslashes($str); $quote = array("\""); $quote_new = array("\"\""); $fix_str = str_replace($quote, $quote_new, $fix_str); return $fix_str; } $item = (! get_magic_quotes_gpc ()) ? addslashes ($_POST['item']) : $_POST['item']; $item = fix_quotes($item); to handle apostrophe's and double quotes. We have just got a new website and it's throwing an error message because we have get_magic_quotes_gpc = on and says we should turn it off. Now presumably if I turn it off the other web page will not like the inserts. I was wondering what an alternative would be? is it as simple as: function fix_quotes($str) { $fix_str=stripslashes($str); $quote = array("\""); $quote_new = array("\"\""); $fix_str = str_replace($quote, $quote_new, $fix_str); return $fix_str; } $item = $_POST['item']; $item = fix_quotes($item); Or am going to run into other issues? It seems to work fine but I don't understand fully to just go ahead with it. Many Thanks Link to comment https://forums.phpfreaks.com/topic/184513-magic-quotes/ Share on other sites More sharing options...
Mchl Posted December 9, 2009 Share Posted December 9, 2009 This line $item = (! get_magic_quotes_gpc ()) ? addslashes ($_POST['item']) : $_POST['item']; checks if magic quotes are enabled, and if no, it does what magic quotes would do. So you should not change this line, and you should not notice any change when turning magic_quotes off. Link to comment https://forums.phpfreaks.com/topic/184513-magic-quotes/#findComment-974060 Share on other sites More sharing options...
New Coder Posted December 9, 2009 Author Share Posted December 9, 2009 Thanks for your speedy reply. So I'm 100% safe to turn it off? Link to comment https://forums.phpfreaks.com/topic/184513-magic-quotes/#findComment-974159 Share on other sites More sharing options...
Mchl Posted December 9, 2009 Share Posted December 9, 2009 At least as far as this specific fragment of code is concerned. There might be other places, that do not have this kind of checking. Link to comment https://forums.phpfreaks.com/topic/184513-magic-quotes/#findComment-974169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.