PHP uses CURL to simulate logon. phpcurl simulates logon _ PHP Tutorial

Source: Internet
Author: User
PHP uses CURL to simulate logon, and phpcurl to simulate logon. PHP uses CURL to simulate logon. phpcurl simulates many simulated logon programs on the Internet, mostly running through service programs such as apache, after obtaining the verification code, PHP uses CURL to simulate logon. phpcurl simulates logon.

Many simulated login programs on the Internet are mostly run through service programs such as apache. after obtaining the verification code, they are displayed on the webpage and then filled in and POST the code. although it looks good, however, since simulated logon does not necessarily take a short time to complete the tasks after logon, this is subject to the maximum execution time of php, and some operations may have insufficient permissions.

This article provides a program example. The idea is to store the verification code as an image after obtaining the verification code, and then the program sleeps for 20 seconds. after 20 seconds, you can manually view the image, enter the verification code in the code.txt file, and the program will read the verification code of code.txt after 20 seconds of sleep. then, the program will log on with the verification code. The code is as follows:

/*** Simulate logon * // Initialization variable $ cookie_file = "tmp. cookie"; $ login_url =" http://xxx.com/logon.php "; $ Verify_code_url =" http://xxx.com/verifyCode.php "; Echo" obtaining COOKIE... \ n "; $ curlj = 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 the COOKIE and store $ contents = curl_exec ($ curl ); curl_close ($ curl); echo "the COOKIE is obtained. the verification code is being obtained... \ n "; // Retrieve the verification code $ curl = curl_init (); curl_setopt ($ curl, CURLOPT_UR L, $ verify_code_url); curl_setopt ($ curl, CURLOPT_COOKIEFILE, $ cookie_file); curl_setopt ($ curl, CURLOPT_HEADER, 0); curl_setopt ($ curl, expires, 1 ); $ img = curl_exec ($ curl); curl_close ($ curl); $ fp = fopen ("verifyCode.jpg", "w"); fwrite ($ fp, $ img ); fclose ($ fp); echo "verification code is obtained and completed. it is waiting for sleep. please enter the verification code in code.txt and save \ n" within 20 seconds; // stop running for 20 seconds sleep (20); echo "sleep complete, start to get the verification code... \ n "; $ code = file_get_contents (" code.txt "); echo" verification code Retrieved successfully: $ code \ n "; echo" preparing to simulate logon... \ n "; $ post =" username = maben & pwd = hahahaha & verifycode = $ code "; $ curl = curl_init (); curl_setopt ($ curl, CURLOPT_URL, $ url ); curl_setopt ($ curl, CURLOPT_HEADER, false); curl_setopt ($ curl, expires, 1); curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ post); curl_setopt ($ curl, CURLOPT_COOKIEFILE, $ cookie_file); $ result = curl_exec ($ curl); curl_close ($ curl); // The data obtained from the website obtained by packet capture. Determine if (substr_count ($ result, "logon successful") {echo "logon successful \ n" ;}else {echo "logon failed \ n"; exit ;} // OK, start doing what you want to do .....

The above is all the content of this article. I hope you will like it.

Many simulated login programs on the ghost Web mostly run through service programs such as apache. after obtaining the verification code, it is displayed on the webpage...

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.