PHP uses curl to obtain the verification code (sending a cookie for secondary capture)

Source: Internet
Author: User
Tags curl
The code is as follows: Copy code

<? Php
$ CookieFile = tempnam ("./tmep", "beast ");
If (isset ($ _ GET ["img"]) {
$ Url = 'http: // www.111cn.net/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.111cn.net ");
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.111cn.net );
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 {
?>
<Form id = "form1" name = "form1" method = "post" action = "">
<! -- Obtain and output the image content from the server -->
<Input type = "text" name = "d"/>
<Input type = "submit" name = "button" id = "button" value = "submit"/>
</Form>
<? Php}
?>
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.