Snoopy.class.php Download Method/step
The first type: Using the Snoopy class to implement a simulated login
1. Download a Snoopy.class.php file on the Web
2. Code implementation:
<?PHPSet_time_limit(0);require"Snoopy.class.php";$snoopy=NewSnoopy ();$snoopy->referer= ' You want to impersonate the domain name of the login ';//Example: http://www.baidu.com/$snoopy->agent= "Define browser root";$post[' username '] = ' login account ';//According to the site you want to simulate the specific value of the name of the transfer to set$post[' password '] = ' login password ';//According to the site you want to simulate the specific value of the name of the transfer to set$url= ' You want to simulate the domain name of the login, data submission address ';//URL address of the login data submission$snoopy->submit ($url,$post);$snoopy->fetch ("You want to simulate the domain name of the login");//the page data you want to getEcho $snoopy->results;//output results, login successful
The second type: using the Curl function to simulate landing
1. Code implementation: storing Cookies
<?PHPSet_time_limit(0);$cookie _file=Tempnam('./tmp ', ' Cookie ');//tmp directory first created, set cookie file$curl=curl_init ();$login _url= ' You want to simulate the login domain, data submission address ';$curlPost= "Usename= login account &password= login password";//According to the site you want to simulate the specific value of the name of the transfer to setcurl_setopt ($ch, Curlopt_url,$login _url);//when enabled, the header file information is output as a data streamcurl_setopt ($curl, curlopt_header,0);//set whether to output page contentcurl_setopt ($curl, curlopt_returntransfer,1); curl_setopt ($curl, curlopt_post,1);//set the request send mode, post or get,curlopt_post or Curlopt_getcurl_setopt ($curl, Curlopt_postfields,$curlPost); curl_setopt ($curl, Curlopt_cookiejar,$cookie _file);//Save CookiesCurl_exec ($curl);//ExecutionCurl_close ($curl);//Close
2. Realize the analog landing
$curl=curl_init ();$login _url2= "You want to simulate the domain name of the login"; curl_setopt ($curl, Curlopt_url,$login _url2);//submit a login URLcurl_setopt ($curl, curlopt_header,0); curl_setopt ($curl, curlopt_returntransfer,0); curl_setopt ($curl, Curlopt_cookiefile,$cookie _file);//Read CookiesCurl_exec ($curl);//ExecutionCurl_close ($curl);//Close
PHP implementation of the Curl and Snoopy class simulation landing method