php - Get POST data from file_get_contents -
i followed this post see how pass data php's file_get_contents function can't seem data using:
$data = $_post['my_param']; // my_param name of parameter passed does know how value of parameter sent file_get_contents in script i'm calling file_get_contents?
thanks in advance
there example @ php.net http://php.net/manual/en/function.file-get-contents.php#102575
code:
<?php /** make http post request , return response content , headers @param string $url url of requested script @param array $data hash array of request variables @return returns hash array response content , headers in following form: array ('content'=>'<html></html>' , 'headers'=>array ('http/1.1 200 ok', 'connection: close', ...) ) */ function http_post ($url, $data) { $data_url = http_build_query ($data); $data_len = strlen ($data_url); return array ('content'=>file_get_contents ($url, false, stream_context_create (array ('http'=>array ('method'=>'post' , 'header'=>"connection: close\r\ncontent-length: $data_len\r\n" , 'content'=>$data_url )))) , 'headers'=>$http_response_header ); } ?> but in real application wouldn't use approach. suggest use curl instead.
simple example curl:
<?php $ch = curl_init(); // create curl handle $url = "http://www.google.com"; /** * https, there more options must define, these can php.net */ curl_setopt($ch,curlopt_url,$url); curl_setopt($ch,curlopt_post, true); curl_setopt($ch,curlopt_postfields, http_build_query(['array_of_your_post_data'])); curl_setopt($ch,curlopt_returntransfer, true); curl_setopt($ch,curlopt_connecttimeout ,3); //timeout in seconds curl_setopt($ch,curlopt_timeout, 20); // same here. timeout in seconds. $response = curl_exec($ch); curl_close ($ch); //close curl handle echo $response; ?> using curl, ur post parameters $_post 100% of times. have used curl in tens of projects, has never failed me before.
Comments
Post a Comment