Home > Backend Development > PHP Tutorial > PHP uses curl to obtain verification code (send cookie for secondary capture)_PHP tutorial

PHP uses curl to obtain verification code (send cookie for secondary capture)_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:49:07
Original
1221 people have browsed it

I think you may not know the powerful function of curl in php. Now I will introduce an example of using curl to obtain verification codes at work and create cookies.

 代码如下 复制代码

$CookieFile=tempnam("./tmep","beast");
if(isset($_GET["img"])){
$url = 'http://www.bKjia.c0m/phper/php.htm';//验证码code
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);//把返回来的cookie信息保存在文件中
curl_exec($ch);
curl_close($ch);
exit();
}
if(isset($_POST['d'])){
$b=$_POST[d];//验证码
$p="waybillNo=1721269381&inputcode=".$b;
$ch = curl_init();
// 2. 设置选项,包括URL
curl_setopt($ch,CURLOPT_URL, "http://www.bKjia.c0m");
curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);
curl_setopt($ch,CURLOPT_COOKIEFILE, $CookieFile);//同时发送Cookie
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $p);//提交查询信息
$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);//同时发送Cookie
curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $p);//提交查询信息
$bs = curl_exec($ch);
echo $bs;//输出结果
curl_close($ch);
}else{
?>





?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632736.htmlTechArticleI think you may not know the powerful function of curl in php. Now I will introduce another one used in work. An example of using curl to obtain the verification code and create cookies. The code is copied as follows...
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template