PHP uses curl to obtain the verification code (send a cookie to capture the code twice) _ PHP Tutorial

Source: Internet
Author: User
PHP uses curl to obtain the verification code (sending a cookie for secondary capture ). The powerful curl function in php may not be available yet. next I will introduce an instance used in the work to obtain the verification code using curl and create a cookie. the code below copies the powerful curl function in php, which may not be available to anyone. next I will introduce an instance used in the work to obtain the verification code using curl and create a cookie.
The code is as follows:

$ CookieFile = tempnam ("./tmep", "beast ");
If (isset ($ _ GET ["img"]) {
$ Url = 'http: // www. bKjia. c0m/phper/php.htm'; // verification code
$ Ch = curl_init ($ url );
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ CookieFile); // Save the returned cookie information to the file
Curl_exec ($ ch );
Curl_close ($ ch );
Exit ();
}
If (isset ($ _ POST ['D']) {
$ B = $ _ POST [d]; // verification code
$ P = "waybillNo = 1721269381 & inputcode =". $ B;
$ Ch = curl_init ();
// 2. set options, including URL
Curl_setopt ($ ch, CURLOPT_URL, "http://www.bKjia. c0m ");
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ CookieFile );
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ CookieFile); // send Cookie at the same time
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ p); // submit the query information.
$ S = curl_exec ($ ch );
Curl_close ($ ch );
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, http://www.bKjia. c0m );
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ CookieFile); // send Cookie at the same time
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ CookieFile );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ p); // submit the query information.
$ Bs = curl_exec ($ ch );
Echo $ bs; // output result
Curl_close ($ ch );
} Else {
?>

?>

Pipeline. the code is as follows...

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.