PHP implementation of the Curl and Snoopy class simulation landing method

Source: Internet
Author: User

Snoopy.class.php Download Method/step
  1. The first type: Using the Snoopy class to implement a simulated login

    1. Download a Snoopy.class.php file on the Web

  2. 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

  3. 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

  4. 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

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.