Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
346 views
in Q2A Core by
I was having issues with words containing apostrophes like Bob's and quotes like "QUOTES".  I was getting slashes like it was escaping and found the logic for magic quotes may be reversed.

I have inverted the logic in qa-base.php and it seems to work, but this may be a bad solution.  Would someone please confirm.

This works (extracted from qa-base.php):


    function qa_gpc_to_string($string)
/*
    Return string for incoming GET/POST/COOKIE value, stripping slashes if appropriate
*/
{
    //return get_magic_quotes_gpc() ? stripslashes($string) : $string;
    return get_magic_quotes_gpc() ? $string : stripslashes($string);
}
   

    function qa_string_to_gpc($string)
/*
    Return string with slashes added, if appropriate for later removal by qa_gpc_to_string()
*/
{
    //return get_magic_quotes_gpc() ? addslashes($string) : $string;
    return get_magic_quotes_gpc() ? $string : addslashes($string);
}
by
That seems odd, since if you have magic_quotes_gpc on, you would need to remove the slashes. What version of PHP are you using?
by
Not sure if I implied magic_quotes_gpc was on. It is off on my machine running iis 7.5 and php 5.2

1 Answer

0 votes
by
Interesting. It's not so much that the logic was reversed, but rather that your server appears to be adding the slashes, even though get_magic_quotes_gpc() was returning 0. So you could just have removed the branch completely, and hard-coded the calls to stripslashes(..) and addslashes(..) respectively.

One other thought - perhaps there's some quoting going on at the database connection, not on the web site, and this is the cause of the problem.
...