<?php namespace app\common\library; class Curl { private $cookie_file; // 设置Cookie文件保存路径及文件名 private $cookie; function __construct($cookie = false,$cookie_file = '') { $this->cookie = $cookie; if($this->cookie == true){ $this->cookie_file = $cookie_file; } } function get($url) { // analog function content acquired $ curl = curl_init (); // start a session CURL curl_setopt ($ curl, CURLOPT_URL, $ url); // be accessed address curl_setopt ( $ curl , CURLOPT_SSL_VERIFYPEER, 0); // checking the certificate of origin curl_setopt ( $ curl , CURLOPT_SSL_VERIFYHOST, 0); // check the certificate in the presence or absence of SSL encryption curl_setopt ( $ curl , CURLOPT_USERAGENT, $ _SERVER [ 'the HTTP_USER_AGENT']); // simulated users browsing an IF ( the ini_get ( 'open_basedir') == '' && the ini_get ( 'safe_mode' == 'Off' )) { curl_setopt ( $ curl , CURLOPT_FOLLOWLOCATION,. 1); // Use automatically jump } curl_setopt ( $ curl , CURLOPT_AUTOREFERER,. 1); // automatically set the Referer curl_setopt ( $ curl , CURLOPT_HTTPGET,. 1); // send a request for a conventional Post IF ( $ the this -> == Cookie to true ) curl_setopt ( $ curl , CURLOPT_COOKIEFILE, $ the this -> cookie_file); // read the above information stored in the Cookie curl_setopt ($ curl, CURLOPT_TIMEOUT, 30 ); // set the timeout limit prevent infinite loop curl_setopt ( $ curl , CURLOPT_HEADER, 0); // Header content display area is returned curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 ); // acquired information returned as stream file $ tmpInfo = curl_exec ($ curl) ; // perform the operation if ( curl_errno ($ curl)) { echo 'Errno' curl_error ($ curl);. } curl_close ($ curl); // close cURL session return $ tmpInfo; // return data } function POST ( $ URL , $ data ) { / / analog data submission function $ curl = curl_init (); // start a session cURL curl_setopt ( $ curl , CURLOPT_URL to, $ URL ); // to access the address curl_setopt ( $ curl , CURLOPT_SSL_VERIFYPEER, 0); // for inspection certificate sources curl_setopt ( $ curl , CURLOPT_SSL_VERIFYHOST, 0); // Check whether there SSL encryption certificate from curl_setopt ( $ curl , CURLOPT_USERAGENT, $ _SERVER [ ' the HTTP_USER_AGENT ']); // simulated user's browser IF ( the ini_get (' open_basedir ') ==' '&& the ini_get (' safe_mode '==' Off ' )) { curl_setopt ( $ curl , CURLOPT_FOLLOWLOCATION,. 1); / / use automatically jump } curl_setopt ( $ curl, CURLOPT_AUTOREFERER,. 1); // automatically set the Referer curl_setopt ( $ curl , CURLOPT_POST,. 1); // send a request conventional Post curl_setopt ( $ curl , CURLOPT_POSTFIELDS, $ Data ); // packet submitted Post IF ( $ the this -> == Cookie to true ) curl_setopt ( $ curl , CURLOPT_COOKIEFILE, $ the this -> cookie_file); // read the above information stored in the Cookie curl_setopt ( $ curl , CURLOPT_TIMEOUT, 30); // set the timeout limits prevent infinite loop curl_setopt ( $ curl, CURLOPT_HEADER, 0); // Header content display area is returned curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER,. 1); // acquired information returned as stream file $ tmpInfo = the curl_exec ( $ curl ); // perform the operation IF ( curl_errno ( $ curl )) { echo 'Errno' curl_error (. $ curl ); } curl_close ( $ curl ); // key cURL session return $ tmpInfo ; // return data } function delcookie ( $ cookie_file ) {// delete the Cookie function @ unlink ( $ cookie_file ); // delete } }
Rookie Tutorial: https://www.runoob.com/php/php-ref-curl.html