[PHP]
Class Curl {
/*
* Get method get access to specified address
* @param the address to be accessed by the string URL
* @param the storage address of a string cookie cookie, no cookie is sent
* @return string curl_exec () gets the information
* @author Andy
**/
Public function Get ($url, $cookie = ")
{
Initializing a Curl session
$curl = Curl_init ($url);
Do not display header information
curl_setopt ($curl, Curlopt_header, 0);
The information obtained by CURL_EXEC () is returned as a file stream, rather than as a direct output.
curl_setopt ($curl, Curlopt_returntransfer, 1);
Use Auto Jump
curl_setopt ($curl, curlopt_followlocation, 1);
if (!empty ($cookie)) {
The file name that contains the cookie data, the format of the cookie file can be in Netscape format, or just plain HTTP header information is stored in the file.
curl_setopt ($curl, Curlopt_cookiefile, $cookie);
}
Set Referer automatically
curl_setopt ($curl, Curlopt_autoreferer, 1);
Perform a Curl session
$tmp = curl_exec ($curl);
Turn off the Curl session
Curl_close ($curl);
return $tmp;
}
/*
* Post mode impersonation request specified address
* @param the specified address of the string URL request
* @param the array params request with the
* #patam A string cookie cookie to store the address
* @return string curl_exec () gets the information
* @author Andy
**/
Public Function post ($url, $params, $cookie)
{
$curl = Curl_init ($url);
curl_setopt ($curl, Curlopt_header, 0);
A check of the source of the certification certificate, 0 means that the validity of the certificate is blocked from checking.
curl_setopt ($curl, Curlopt_ssl_verifypeer, false);
Check that the SSL encryption algorithm exists from the certificate
curl_setopt ($curl, Curlopt_ssl_verifyhost, 1);
Simulates a user-used browser that contains a string of "user-agent" headers in an HTTP request.
curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent ');
Send a regular POST request, type: application/x-www-form-urlencoded, just like the form submitted.
curl_setopt ($curl, Curlopt_post, 1);
The information obtained by CURL_EXEC () is returned as a file stream, rather than as a direct output.
curl_setopt ($curl, Curlopt_returntransfer, 1);
Use Auto Jump
curl_setopt ($curl, curlopt_followlocation, 1);
Set Referer automatically
curl_setopt ($curl, Curlopt_autoreferer, 1);
Cookie Address
curl_setopt ($curl, Curlopt_cookiejar, $cookie);
All data is sent using the "POST" action in the HTTP protocol. To send a file,
Precede the file name with the @ prefix and use the full path. This parameter can be passed urlencoded after the string
Similar to ' para1=val1¶2=val2& ... ' or using a field name as a key value, the field data is an array of values
If value is an array, the Content-type header will be set to Multipart/form-data.
curl_setopt ($curl, Curlopt_postfields, Http_build_query ($params));
$result = curl_exec ($curl);
Curl_close ($curl);
return $result;
}
/**
* Remote Download
* @param string $remote remote picture address
* @param string $local the locally saved address
* @param string $cookie The optional parameter of the cookie address is determined by
* On certain websites where cookies are required to download images on the site
* So you need to add a cookie
* @return void
* @author Andy
*/
Public Function Reutersload ($remote, $local, $cookie = ") {
$CP = Curl_init ($remote);
$fp = fopen ($local, "w");
curl_setopt ($CP, Curlopt_file, $fp);
curl_setopt ($CP, Curlopt_header, 0);
if ($cookie! = ") {
curl_setopt ($CP, Curlopt_cookiefile, $cookie);
}
Curl_exec ($CP);
Curl_close ($CP);
Fclose ($FP);
}
}
Class Curl {
/*
* Get method get access to specified address
* @param the address to be accessed by the string URL
* @param the storage address of a string cookie cookie, no cookie is sent
* @return string curl_exec () gets the information
* @author Andy
**/
Public function Get ($url, $cookie = ")
{
Initializing a Curl session
$curl = Curl_init ($url);
Do not display header information
curl_setopt ($curl, Curlopt_header, 0);
The information obtained by CURL_EXEC () is returned as a file stream, rather than as a direct output.
curl_setopt ($curl, Curlopt_returntransfer, 1);
Use Auto Jump
curl_setopt ($curl, curlopt_followlocation, 1);
if (!empty ($cookie)) {
The file name that contains the cookie data, the format of the cookie file can be in Netscape format, or just plain HTTP header information is stored in the file.
curl_setopt ($curl, Curlopt_cookiefile, $cookie);
}
Set Referer automatically
curl_setopt ($curl, Curlopt_autoreferer, 1);
Perform a Curl session
$tmp = curl_exec ($curl);
Turn off the Curl session
Curl_close ($curl);
return $tmp;
}
/*
* Post mode impersonation request specified address
* @param the specified address of the string URL request
* @param the array params request with the
* #patam A string cookie cookie to store the address
* @return string curl_exec () gets the information
* @author Andy
**/
Public Function post ($url, $params, $cookie)
{
$curl = Curl_init ($url);
curl_setopt ($curl, Curlopt_header, 0);
A check of the source of the certification certificate, 0 means that the validity of the certificate is blocked from checking.
curl_setopt ($curl, Curlopt_ssl_verifypeer, false);
Check that the SSL encryption algorithm exists from the certificate
curl_setopt ($curl, Curlopt_ssl_verifyhost, 1);
Simulates a user-used browser that contains a string of "user-agent" headers in an HTTP request.
curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent ');
Send a regular POST request, type: application/x-www-form-urlencoded, just like the form submitted.
curl_setopt ($curl, Curlopt_post, 1);
The information obtained by CURL_EXEC () is returned as a file stream, rather than as a direct output.
curl_setopt ($curl, Curlopt_returntransfer, 1);
Use Auto Jump
curl_setopt ($curl, curlopt_followlocation, 1);
Set Referer automatically
curl_setopt ($curl, Curlopt_autoreferer, 1);
Cookie Address
curl_setopt ($curl, Curlopt_cookiejar, $cookie);
All data is sent using the "POST" action in the HTTP protocol. To send a file,
Precede the file name with the @ prefix and use the full path. This parameter can be passed urlencoded after the string
Similar to ' para1=val1¶2=val2& ... ' or using a field name as a key value, the field data is an array of values
If value is an array, the Content-type header will be set to Multipart/form-data.
curl_setopt ($curl, Curlopt_postfields, Http_build_query ($params));
$result = curl_exec ($curl);
Curl_close ($curl);
return $result;
}
/**
* Remote Download
* @param string $remote remote picture address
* @param string $local the locally saved address
* @param string $cookie The optional parameter of the cookie address is determined by
* On certain websites where cookies are required to download images on the site
* So you need to add a cookie
* @return void
* @author Andy
*/
Public Function Reutersload ($remote, $local, $cookie = ") {
$CP = Curl_init ($remote);
$fp = fopen ($local, "w");
curl_setopt ($CP, Curlopt_file, $fp);
curl_setopt ($CP, Curlopt_header, 0);
if ($cookie! = ") {
curl_setopt ($CP, Curlopt_cookiefile, $cookie);
}
Curl_exec ($CP);
Curl_close ($CP);
Fclose ($FP);
}
}
http://www.bkjia.com/PHPjc/477445.html www.bkjia.com true http://www.bkjia.com/PHPjc/477445.html techarticle [PHP]? PHP class Curl {/* * Get access to the specified address * @param the address to be accessed by the string URL * @param the storage address of a string cookie cookie, without sending a cookie * @retu ...