PHP using tesseract Identification code, and analog login, verification code error

Source: Internet
Author: User
The code is as follows:


  "; $curl = Curl_init (); $timeout = 5;curl_setopt ($curl, Curlopt_url, $login _url); curl_setopt ($curl, Curlopt_ Returntransfer, 1); curl_setopt ($curl, Curlopt_connecttimeout, $timeout); curl_setopt ($curl, curlopt_cookiejar,$ Cookie_file); Obtain a cookie and store $contents = curl_exec ($curl); Curl_close ($curl);//3. Remove the verification code echo "Cookie gets completed, retrieving verification code ...
"; $curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $verify _code_url); curl_setopt ($curl, Curlopt_cookiejar, $ Cookie_file);//Save Cookiecurl_setopt ($curl, Curlopt_cookiefile, $cookie _file);//Use Cookiecurl_setopt ($curl, Curlopt_ HEADER, 0); curl_setopt ($curl, Curlopt_returntransfer, 1); $img = Curl_exec ($curl); Curl_close ($curl); $codename = time () ; $fp = fopen ("/home/wwwroot/default/tesseract/test/images/$codename. png", "w"), echo "", Fwrite ($fp, $img); Fclose ($fp );//Start Identification Verification code echo "Verification code check out completed, is sleeping, is identifying the verification code ...
";p assthru ("/usr/bin/tesseract/home/wwwroot/default/tesseract/test/images/$codename. png/home/wwwroot/default/ tesseract/test/images/$codename "); $code = file_get_contents ("./images/$codename. txt "); echo" Verification code successfully removed: $code
"; Echo" is preparing to impersonate the login ...
"; $post _url =" http://210.32.33.91:8080/reader/redr_verify.php ";//For security, here the password is not provided. $post = "number=1111111&passwd=111111&captcha= $code &select=cert_no&returnurl="; $curl = Curl_init () ; curl_setopt ($curl, Curlopt_url, $post _url); curl_setopt ($curl, Curlopt_header, false); curl_setopt ($curl, Curlopt_ returntransfer,1); curl_setopt ($curl, Curlopt_postfields, $post) curl_setopt ($curl, Curlopt_cookiejar, $cookie _file ); curl_setopt ($curl, Curlopt_cookiefile, $cookie _file), $result =curl_exec ($curl); Curl_close ($curl); Echo str_ Replace (' captcha.php ', ' http://210.32.33.91:8080/reader/captcha.php ', $result);

Reply content:

The code is as follows:


  "; $curl = Curl_init (); $timeout = 5;curl_setopt ($curl, Curlopt_url, $login _url); curl_setopt ($curl, Curlopt_ Returntransfer, 1); curl_setopt ($curl, Curlopt_connecttimeout, $timeout); curl_setopt ($curl, curlopt_cookiejar,$ Cookie_file); Obtain a cookie and store $contents = curl_exec ($curl); Curl_close ($curl);//3. Remove the verification code echo "Cookie gets completed, retrieving verification code ...
"; $curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $verify _code_url); curl_setopt ($curl, Curlopt_cookiejar, $ Cookie_file);//Save Cookiecurl_setopt ($curl, Curlopt_cookiefile, $cookie _file);//Use Cookiecurl_setopt ($curl, Curlopt_ HEADER, 0); curl_setopt ($curl, Curlopt_returntransfer, 1); $img = Curl_exec ($curl); Curl_close ($curl); $codename = time () ; $fp = fopen ("/home/wwwroot/default/tesseract/test/images/$codename. png", "w"), echo "", Fwrite ($fp, $img); Fclose ($fp );//Start Identification Verification code echo "Verification code check out completed, is sleeping, is identifying the verification code ...
";p assthru ("/usr/bin/tesseract/home/wwwroot/default/tesseract/test/images/$codename. png/home/wwwroot/default/ tesseract/test/images/$codename "); $code = file_get_contents ("./images/$codename. txt "); echo" Verification code successfully removed: $code
"; Echo" is preparing to impersonate the login ...
"; $post _url =" http://210.32.33.91:8080/reader/redr_verify.php ";//For security, here the password is not provided. $post = "number=1111111&passwd=111111&captcha= $code &select=cert_no&returnurl="; $curl = Curl_init () ; curl_setopt ($curl, Curlopt_url, $post _url); curl_setopt ($curl, Curlopt_header, false); curl_setopt ($curl, Curlopt_ returntransfer,1); curl_setopt ($curl, Curlopt_postfields, $post) curl_setopt ($curl, Curlopt_cookiejar, $cookie _file ); curl_setopt ($curl, Curlopt_cookiefile, $cookie _file), $result =curl_exec ($curl); Curl_close ($curl); Echo str_ Replace (' captcha.php ', ' http://210.32.33.91:8080/reader/captcha.php ', $result);

2016/1/25 14:51 Update

Linux words captcha directory, cookies directory to write permission
You step-by-step debugging, see how your program produces the result is how much, the picture is how many,


Code in: Https://github.com/rainwsy/sf/tree/master/library-OCR-login

Update:
You should
1. Save the verification code, in comparison with the text results,
2. Compare the consistency of each session_id
3.curlopt_cookiejar the first time to use the time to save session_id on the back of the operation with Curlopt_cookiefile to read session_id, in fact, you can compare the next few requests to return to the header of the session _ID is consistent
My verification Code recognition results:

Wrote a demo:

Point out a few questions, get the session in the verification code to obtain the step together to get OK, there is no need to first get the session and then fetch the verification code,
When I see my account password hidden, I think this is for the alumni to answer?


  Getcaptcha ();/* Start landing */$username = ' username '; $passwd = ' password '; $postArray = [' number ' = = $username, ' passwd ' + $pas SWD, ' captcha ' = ' $captcha, ' select ' = ' cert_no ', ' returnUrl ' + ']; $postData = Http_build_query ($post    Array); Echo post ($LOGINURL, $postData, $cookie _file), function get ($url, $cookie _file, $isCookiesSave = False) {//initialization    $curl = Curl_init ($url);    $header = Array (); $header [] = ' user-agent:mozilla/5.0 (Windows NT 6.1) applewebkit/537.36 (khtml, like Gecko) chrome/42.0.2311.90 safari/53    7.36 ';    curl_setopt ($curl, Curlopt_httpheader, $header);    Do not output header header information curl_setopt ($curl, Curlopt_header, 0); if ($isCookiesSave) {curl_setopt ($curl, Curlopt_cookiejar, $cookie _file);//Store Cookies} else {Curl_set    Opt ($curl, curlopt_cookiefile, $cookie _file);    }//Save to string instead of output curl_setopt ($curl, Curlopt_returntransfer, 1);    Whether to crawl the page after the jump curl_setopt ($curl, curlopt_followlocation, 1); $info = curl_exec ($curl);   Curl_close ($curl); return $info;}    Function post ($url, $data, $cookie _file) {//Initialize $curl = Curl_init ($url);    $header = Array (); $header [] = ' user-agent:mozilla/5.0 (Windows NT 6.1) applewebkit/537.36 (khtml, like Gecko) chrome/42.0.2311.90 safari/53    7.36 ';    curl_setopt ($curl, Curlopt_httpheader, $header);    Do not output header header information curl_setopt ($curl, Curlopt_header, 0);    Save to string instead of output curl_setopt ($curl, Curlopt_returntransfer, 1);    curl_setopt ($curl, Curlopt_cookiefile, $cookie _file);    POST Data curl_setopt ($curl, Curlopt_post, 1);    Request Data curl_setopt ($curl, Curlopt_postfields, $data);    Whether to crawl the page after the jump curl_setopt ($curl, curlopt_followlocation, 1);    $response = curl_exec ($curl);    Curl_close ($curl); return $response;}

Online comment is low recognition rate

  • Related Article

    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.