Introduction: The first step of the collection forum is to simulate the landing, because each site login forms are different, authentication method is various, so directly submit user name password to login page is more cumbersome.
So we use cookies to simulate landing is undoubtedly the best shortcut.
Today we are dealing with a simulated discuz.net login:
- Object: Http://www.discuz.net
- Account Number: AC
- Password: 123456
Cut into the topic
Below, we use three steps to achieve the impersonation login operation, 1. Get login cookie,2. Impersonation request, 3. Jump to the target actual action page.
Preparatory work
First, we log in manually and record cookies.
dznet_cookietime=2592000;dznet_onlineusernum=7816;dznet_sid=qtlc87;dznet_auth=6bbecqrzgv4elinmlgu% 2flgzspzbrsaugo1l0obp6vqw5p0bceg0xd4slycm2ks%2fl0ycvyso7xp2z8gmaxkpdubxzcwft;checkpm=1
(Currently there are plug-in view cookies for mainstream browsing)
P1. Login with Snoopy emulation
//Loading class Librariesinclude("snoopy.php");//Actual Object$snoopy=NewSnoopy;//set the browser engine//(description: Is the browser information, in front of what browser you use to view the cookie, just use that browser information [PS: $_server can view the browser's information])$snoopy->agent = "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; TheWorld) ";//Set Source page$snoopy->referer = "http://www.discuz.net/";//Set Cookies$snoopy->rawheaders["COOKIE"]= "dznet_cookietime=2592000;dznet_onlineusernum=7816;dznet_sid=qtlc87;dznet_auth= 6bbecqrzgv4elinmlgu%2flgzspzbrsaugo1l0obp6vqw5p0bceg0xd4slycm2ks%2fl0ycvyso7xp2z8gmaxkpdubxzcwft;checkpm=1 ";//Crawl Posts Page$snoopy->fetch ("Http://www.discuz.net/post.php?action=newthread&fid=2&extra=page%3D1");//Output page ContentEcho $snoopy->results;
P2. Login with Curl emulation
//Login URL$url= "http://www.discuz.net/";//Browser engine$useragent= "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; TheWorld) ";//Cookies$cookie= "dznet_cookietime=2592000;dznet_onlineusernum=7816;dznet_sid=qtlc87;dznet_auth=6bbecqrzgv4elinmlgu% 2flgzspzbrsaugo1l0obp6vqw5p0bceg0xd4slycm2ks%2fl0ycvyso7xp2z8gmaxkpdubxzcwft;checkpm=1 ";//initializing a Curl object$ch=curl_init ();//set the request URLcurl_setopt ($ch, Curlopt_url,$url);//Set Cookiescurl_setopt ($ch, Curlopt_cookie,$cookie);//Set Source pagecurl_setopt ($ch, Curlopt_referer, "http://www.discuz.net/index.php");//Set return response header information [None] (Note: This setting is usually required to make the fertilizer for the next request.) )curl_setopt ($ch, Curlopt_header,false);//setting does not output to the browser (description: Direct return string, otherwise direct output)curl_setopt ($ch, Curlopt_returntransfer, 1);//setting up the browser enginecurl_setopt ($ch, Curlopt_useragent,$useragent);//Execute RequestCurl_exec ($ch);//Get page Content$tempCn= Curl_multi_getcontent ($ch);//Close ConnectionCurl_close ($ch);//Output page ContentEcho $tempCn;
Let's talk about it here today!
To be continued .....
This site article is for baby bus SD. Team Original, reproduced must be clearly noted: (the author's official website: Baby bus )
Reprinted from "Baby bus Superdo Team" original link: http://www.cnblogs.com/superdo/p/4792805.html
[PHP Automation-Advanced]004.snoopy VS CURL simulation discuz.net Login