Here is the curl way, so we must first ensure that the Curl function library open: In the php.ini file, extension=php_curl.dll before the semicolon removed
Code on:
/**
* analog post for URL request
* @param string $url
* @param array $post _data
/function request_post ($url = ' ', $post _data = Array ()) {//url is required if the address does not require an argument, the If
(empty ($url)) {return
false;
}
if (!empty ($post _data)) {
$params = ';
foreach ($post _data as $k => $v)
{
$params. = "$k =". UrlEncode ($v). "&";
$params. = "$k =". $v. "&";
}
$params = substr ($params, 0,-1);
$ch = Curl_init ()///Initialize Curl
curl_setopt ($ch, Curlopt_url, $url);//crawl The specified page
curl_setopt ($ch, Curlopt_header, 0)//Set Header
curl_setopt ($ch, Curlopt_returntransfer, 1),//request result string and output to screen
curl_setopt ($ch, Curlopt_ POST, 1);//post Submission Mode
if (!empty ($post _data)) curl_setopt ($ch, Curlopt_postfields, $params);
$data = curl_exec ($ch);//Run Curl
curl_close ($ch);
return $data;
}
Test without parameters
Request_post (' http://www.baidu.com ');
With parameters
$post _data[' id ']= ' 1 ';
Request_post (' http://www.baidu.com ', $post _data);
</pre><pre>