Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are escape characters being added to the value of the hidden input

Tags:

json

html

php

<body>
  <div> <?= $_POST['msg'] ?> </div>
  <form id="frm" method="post">
    <input type="hidden" name='msg' value='{"field0": "Im a string", "field1": 84, "field3": "so am I"}' />
    <input type="submit" value="test" />
  </form>
</body>

When the form is posted, the following string is displayed between the div tags.

{\"field0\": \"Im a string\", \"field1\": 84, \"field3\": \"so am I\"}

Why are the escape characters being added? Are they being added by the PHP server or the web client? Can I do anything to prevent this?

Someone already mentioned the PHP function stripslashes. I'm using it for now but I want to get rid of the slashes all together.

like image 343
Lawrence Barsanti Avatar asked Dec 30 '22 21:12

Lawrence Barsanti


1 Answers

Check whether your PHP configuration has magic_quotes_gpc activated, in such case the PHP server automatically adds slashes to GET/POST/cookie values...

like image 68
instanceof me Avatar answered Jan 12 '23 00:01

instanceof me