Home >Backend Development >PHP Tutorial >Program PHP development uses snoopy to simulate logging in to other websites with verification codes.

Program PHP development uses snoopy to simulate logging in to other websites with verification codes.

WBOY
WBOYOriginal
2016-07-25 09:13:301060browse
Realization requirements:
Get the session ID and verification code image of station A through snoopy, and display the login form on your website. After submission, snoopy submits the input information to station A to log in, and obtains the information inside for analysis.
(PS: ^_^Good php development learning exchange group: 256271784, verification: cxy, if you are interested, you can join and discuss together)
Get verification code and sessionid:

  1. //Get the picture
  2. $snoopy->fetch('http://www.a.com/imgcode.gif');
  3. //Analyze the sessionid from the header information
  4. preg_match ('/JSESSIONID=([w]+);/', $snoopy->headers[2],$sessionid);
  5. $jsessionid=$sessionid[1];
  6. $imgcode=base64_encode($snoopy- >results);
  7. //Display login form
  8. ?>















  9. Password< ;/th>
  10. Verification code




Copy code


Submit the form information to station A and display the post-login page:


  1. $snoopy->cookies['JSESSIONID']=post('jsessionid');
  2. $snoopy->submit('http://www.a.com/signin.html', $_POST);
  3. echo $snoopy->results;
Copy code


Summary of tips:
The obtained image binary code can be directly used in the src attribute of img through base64 encoding
Copy code





Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn