PHP crawler (CURL) analog login get cookies and then use cookies to view your personal center

Source: Internet
Author: User

<!--Curl's advanced use--><?PHP//analog Login Get cookie saved to PCHeader("content-type:text/html; Charset=utf-8 ");/*$cookie _file = Tempnam (' d:/', ' Cookie ');*/$cookie _file= ' D:/demo.txt ';$login _url= "http://www.php-z.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=lj0cc& Inajax=1 ";/*$post _fields= "ormhash=354c7225&referer=http://www.php-z.com/&loginfield=username&username= Chenglin1994&password=chenglin1994&questionid=0&answer= ";*/$post _fields=Array(' ormhash ' = ' 354c7225 ', ' referer ' = ' http://www.php-z.com/', ' Loginfield ' = ' username ', ' username ' = ' chenglin1994 ', ' password ' = ' chenglin1994 ' ', ' questionid ' = ' 0 ', ' answer ' = ');//Submit a login form request$ch=curl_init ($login _url); curl_setopt ($ch, curlopt_header,0); curl_setopt ($ch, curlopt_returntransfer,1); curl_setopt ($ch, curlopt_post,1); curl_setopt ($ch, Curlopt_postfields,$post _fields); curl_setopt ($ch, Curlopt_cookiejar,$cookie _file);//Store cookie data that is received after submissionEchoCurl_exec ($ch); Curl_close ($ch);//use cookies to view your personal center$url= ' Http://www.php-z.com/home.php?mod=space&do=friend ';$ch=curl_init ($url); curl_setopt ($ch, curlopt_header,0); curl_setopt ($ch, curlopt_returntransfer,1); curl_setopt ($ch, Curlopt_cookiefile,$cookie _file);//Use the cookie data obtained after submission to make parameters$contents=curl_exec ($ch); Curl_close ($ch);Echo $contents;

Excellent articles about Curl

PHP Curl Cookie Access Example (Standard capture program) and camouflage

19326893

19326893

PHP Curl application to implement the simulation login and capture the use of the method of explanation

Http://www.cnblogs.com/Zjmainstay/p/php-curl.html

PHP crawler (CURL) analog login get cookies and then use cookies to view your personal center

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.