PHP利用curl获取验证码,发送cookie二次抓取
- <?php
-
- $CookieFile=tempnam("./tmep","beast");
- if(isset($_GET["img"])){
- $url = 'http://www.phpfensi.com/phper/php.htm';//验证码code
- $ch = curl_init($url);
- curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);
- curl_exec($ch);
- curl_close($ch);
- exit();
- }
- if(isset($_POST['d'])){
- $b=$_POST[d];
- $p="waybillNo=1721269381&inputcode=".$b;
- $ch = curl_init();
-
- curl_setopt($ch,CURLOPT_URL, "http://www.phpfensi.com");
- curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);
- curl_setopt($ch,CURLOPT_COOKIEFILE, $CookieFile);
- 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:
- curl_setopt($ch,CURLOPT_COOKIEFILE, $CookieFile);
- 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{
- ?>
- <form id="form1" name="form1" method="post" action="">
- <img src="?img=true" /><!--由服务器端取图片内容并输出-->
- <input type="text" name="d" />
- <input type="submit" name="button" id="button" value="提交" />
- </form>
- <?php }
- ?>
|