0

Possible Duplicate:
“slash before every quote” problem

I am passing messages between different parts of my php application using code that looks like this:

$msg='"'.$_REQUEST['site'].'" modified.';
header('Location: sites.php?msg='.$msg);
exit();

The code that picks it up on the other end look like this:

<?php if (isset($_GET['msg'])) {echo '<p><em>'.$_GET['msg'].'</em></p>';}?>

In my development environment, the output looks like this: "Some site" modified. In my production environment, the output looks like this: \"Some site\" modified.

This leads me to believe that it is a difference in the settings in the php.ini between the environments. I've searched until my eyeballs are blistered, but I can't find the difference. What gets passed in the url looks like this:

sites.php?msg="Some site" modified

If I put this code:

$msg=htmlspecialchars($msg);

between the variable assignment and header call above, the url looks like this:

sites.php?msg=&quot;Some site&quot; modified.

But no message is displayed in either environment. I also have a similar problem if $_REQUEST['site'] contains an ampersand.

Can anyone explain what is going on here, and how to fix it?

Community
  • 1
  • 1
JDycus
  • 21
  • 2
  • 1
    You probably have magic quotes enabled on your production environment. Check this out http://php.net/manual/en/security.magicquotes.php – NoBBy Aug 24 '12 at 07:46
  • I had previously turn off magic quotes, so I assumed that wasn't the problem. The answer came back so resoundingly magic quotes, that I thought I'd check it again. This application is actually installed on a subdomain on my site and magic quotes defaulted to on for that subdomain. Doh! Thanks for the help. Curious to see if it breaks my wordpress installation on that subdomain when I turn it off... – JDycus Aug 24 '12 at 08:33

3 Answers3

1

The config is called magic_quotes_gpc

xdazz
  • 158,678
  • 38
  • 247
  • 274
1

You Have Magic Quotes enabled set them disabled in PHP.INI.

Raab
  • 34,778
  • 4
  • 50
  • 65
-1

Use stripslashes: http://php.net/manual/en/function.stripslashes.php

<?php if (isset($_GET['msg'])) {echo '<p><em>'.stripslashes($_GET['msg']).'</em></p>';}?>
Tom Naessens
  • 1,827
  • 22
  • 38