To convert a data obtained through URL to post variables
I need to read the result of a form which uses POST action type for submission. So, can I convert a variable obt开发者_运维百科ained through GET variable to POST and then I can simply read the contents using file_get_contents().
Please help me in getting the data using this method or through some alternate method if possible.
file_get_contents can be used to perform POST requests by using stream_context_create:
$options = array('http'=>array(
'method'=>'POST',
'header'=>'Content-type: application/x-www-form-urlencoded',
'content'=>'var1=a&var2=b'
)
);
echo file_get_contents('http://somesite.com/someform/', false, stream_context_create($options));
All parameters passed into your PHP from a form will be populated in the superglobal $_POST
.
If you're uncertain as to whether the parameter will be given via GET or POST, you can use the superglobal $_REQUEST
精彩评论