You should be getting the data from the $_POST
server variable, not the $_REQUEST
eg.
(isset($_POST)) {
$postData = $_POST['post_data'];
}
$_REQUEST
doesn’t force you to figure out if the variable came from GET, POST, COOKIES, etc. It’s useful for debugging scripts or when the variable might come form one of several sources. For instance you might have form information coming from a form (POST) or form a link (GET).
There are security considerations, however, since $_REQUEST
captures data from several sources including cookies, so there’s a potential for misbehavior if someone gets clever and you’re not careful.
In order to use the posted JSON (JavaScript Object Notation) data in PHP you can use json_decode()
eg.
$postData = json_decode( $_POST['post_data'] );
Then, for example, to access the variables you would need to use:
_wpnonce – $postData[0]->value
_wp_http_referer – $postData[1]->value
user_ID – $postData[2]->value
Or, if you wanted to return a tidier array that is more readable, you could use this on the json_decoded $postData
:
$tidy_array = array();
foreach ( $postData as $object ){
$tidy_array[$object->name] = $object->value;
}
Then you could access the data like so:
$tidy_array['_wpnonce']
$tidy_array['_wp_http_referer]
$tidy_array['user_ID']