web analytics

How to read the RAW version of POST data in PHP?

Well when you submit data using a form or anyway and the method is POST then you get the submitted data in a super global array called $_POST. But the data in the $_POST will be slightly modified by PHP that you sometimes, as per your requirement, may not be the exact same thing you inserted. But there is also another way you can access the data in $_POST without any modification, that is the RAW version.

To test the modification first, let us submit a bit of HTML through a text box which is as follows,
<div class="php">
<span>Some Data Here</span>
</div>
But what I got in the $_POST array was this.

Array
(
[theInput] => <div class="php">
<span>Some Data Here</span>
</div>
)
Well, this is obviously not what I inserted. So how to get exactly what I inserted.
$phpRaw = file_get_contents('php://input');
$theInput = htmlspecialchars(urldecode($phpRaw));
Yeah, now I can get what I exactly inserted.

theInput=&lt;div class=&quot;php&quot;&gt;
&lt;span&gt;Some Data Here&lt;/span&gt;
&lt;/div&gt;

Here, theInput is the name of the textarea in the form that I submitted.

But there is a problem, what I got is a string containing all the submitted data, that is all index and values in an query string style, right? So how I can get the value of a given index from this string?

Well nothing to worry, read this, how to get variable value from URL query string in PHP? And use the second method described in the post which is Get variable’s value from string like the query part of an URL in PHP

Please follow and like us:
Pin Share
RSS
Follow by Email
Scroll to Top