Jump to content

magic quotes


New Coder

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.