PHP Curl Landing and get content class, please master to see how to use it
Business requirements:
The ability to automate Web page login via PHP script to get the content of the landing page.
Now on the Internet to find the following this program, but in the process of verification found not successful, please show the Master to see, thank you.
Class CURL
{
var $cookie _file; Set cookie file save path and file name
var $loginurl;//Land address
var $actionstr;//Login parameters
function __construct ()
{
$this->cookie_file=dirname (__file__). " /cookie_ ". MD5 (basename (__file__)).". TXT ";
if (!file_exists ($this->cookie_file))
{//Detect if a cookie exists
$str = $this->vget (' Jroam '); Get login Random values
Preg_match ("/name=\" formhash\ "value=\" (. *?) \ "/is", $str, $hash); Extract login random values
$this->vlogin ($this->loginurl, $this->actionstr); Login to get cookies
}
}
function Vlogin ($url, $data) {///impersonation login Get cookie functions
$curl = Curl_init (); Start a Curl session
curl_setopt ($curl, Curlopt_url, $url); The address to be accessed
curl_setopt ($curl, Curlopt_ssl_verifypeer, 0); Examination of the source of the certification certificate
curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check that the SSL encryption algorithm exists from the certificate
curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulating the browser used by the user
curl_setopt ($curl, curlopt_followlocation, 1); Use Auto Jump
curl_setopt ($curl, Curlopt_autoreferer, 1); Set Referer automatically
curl_setopt ($curl, Curlopt_post, 1); Send a regular POST request
curl_setopt ($curl, Curlopt_postfields, $data); Post-Submitted packets
curl_setopt ($curl, Curlopt_cookiejar, $this->cookie_file); File name for storing cookie information
curl_setopt ($curl, Curlopt_cookiefile, $this->cookie_file); Read the cookie information stored above
curl_setopt ($curl, Curlopt_timeout, 30); Setting a timeout limit to prevent a dead loop
curl_setopt ($curl, Curlopt_header, 0); Displays the contents of the header area returned
curl_setopt ($curl, Curlopt_returntransfer, 1); Gets the information returned as a file stream
$tmpInfo = curl_exec ($curl); Perform actions
if (Curl_errno ($curl)) {
Echo ' Errno '. Curl_error ($curl);
}
Curl_close ($curl); Turn off the Curl session
return $tmpInfo; Return data
}
function Vget ($url) {//Simulate Get content function
$curl = Curl_init (); Start a Curl session
curl_setopt ($curl, Curlopt_url, $url); The address to be accessed
curl_setopt ($curl, Curlopt_ssl_verifypeer, 0); Examination of the source of the certification certificate
curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check that the SSL encryption algorithm exists from the certificate
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.