Ayush
Ayush

Reputation: 42450

json_decode works on localhost but not on webserver

I have a JS function that passes a json string to a PHP script via GET using JSON.stringify.

The JSON decodes in the PHP end just fine when on my localhost, but as soon as I moved it to my webserver, it stopped working. Further analysis revealed that my webserver was adding \ (slashes) to the JSON string and according to JSONLint.com, the string with slashes is invalid JSON.

The JSON on my webserver shows up like this:

{\"Product\":\"Walnut Pastry\",\"Size\":\"Slice\",\"Quantity\":\"2\",\"Price\":0}

Why does this happen on my webserver, and what can I do to escape the strings? I tried json_decode(str_replace('/','',$_GET['json']),true); but that didn't work either

Upvotes: 3

Views: 665

Answers (1)

Pauly
Pauly

Reputation: 299

It appears that you have magic quotes on. Read Magic Quotes

Also you should take note of the warning on the manual page, and then turn it off.

Upvotes: 4

Related Questions