Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access POST data in PHP?

Tags:

http

post

php

People also ask

How can you access form data sent to PHP via a POST request?

How to retrieve form data sent via GET. When you submit a form through the GET method, PHP provides a superglobal variable, called $_GET. PHP uses this $_GET variable to create an associative array with keys to access all the sent information ( form data ). The keys is created using the element's name attribute values.

How can we access the data sent through the URL with the POST method in PHP?

The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure. The PHP provides $_POST associative array to access all the sent information using POST method.

What is POST data in PHP?

PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post".

What is $_ GET and $_ POST in PHP?

$_GET is an array of variables passed to the current script via the URL parameters. $_POST is an array of variables passed to the current script via the HTTP POST method.


Read from php://input. For example, you could use:

$rawdata = file_get_contents('php://input');

or

$rootNode = simplexml_load_file('php://input');

The alternative, using $HTTP_RAW_POST_DATA, works, too - but it's slower and needs the PHP configuration always_populate_raw_post_data.


Try the $HTTP_RAW_POST_DATA variable or the php://input stream.


http://us.php.net/manual/en/reserved.variables.httprawpostdata.php

$HTTP_RAW_POST_DATA should be available assuming the content-type of the request was not multipart/form-data


$HTTP_RAW_POST_DATA

or

php://input


You probably want to use the PHP input. Something like

$postText = trim(file_get_contents('php://input'));