ridz
(Me)
1
Hi,
My server does not allow to use fopen. I need help to use curl instead. Any help is appreciated. Thanks.
$stream = fopen($url, 'rb', false, $context);
$responseContent = stream_get_contents($stream);
$responseHeaders = $http_response_header;
fclose($stream);
jacmoe
(Jacob Moena)
2
quickrep
(Quickrepvn)
3
In this case I think you should use CURL better.
hemendra
(Hemendra Singh)
5
function get_response( $url, $post_params )
{
$channel = curl_init();
curl_setopt($channel, CURLOPT_URL, $url);
curl_setopt($channel, CURLOPT_RETURNTRANSFER, true);
curl_setopt($channel, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($channel, CURLOPT_TIMEOUT, 5);
curl_setopt($channel, CURLOPT_ENCODING, "gzip");
curl_setopt($channel, CURLOPT_VERBOSE, true);
curl_setopt($channel, CURLOPT_POST, true); //set POST request to TRUE
curl_setopt($channel, CURLOPT_POSTFIELDS, $post_params); //set post params
curl_setopt($channel, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201');
curl_setopt($channel, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($channel, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$output = curl_exec($channel);
curl_close( $channel );
return $output;
}
$url = "http://www.stackoverflow.com";
$post_params = "YOUR_FIELDS";
$response = get_response($url, $post_params);
echo $response;