模拟登录飞信,验证码怎么弄,提示验证码错误,我用curl取到表单的cookie也不行
表单
<?php
$cokie=dirname(__FILE__).'/cokie.ck';
@unlink($cokie);
$curl = curl_init('
http://f.10086.cn/im/login/login.action');
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cokie);
curl_setopt($curl, CURLOPT_POST, 1);
$file = curl_exec($curl);
curl_close($curl);
preg_match_all('/<img src="\/im\/systemimage\/verifycode(.*).png\?tp=im5"/Ui',$file,$match);
$id=$match[1][0];
echo '<form method="post" action="yz.php">手机号:<input name="m" type="text"/>
密码:<input name="pass" type="password"/>
输入验证码:<input name="captchaCode" type="text"/>
<img src="
http://f.10086.cn/im/systemimage/verifycode'.$match[1][0].'.png?tp=im5" alt="图片测试"><input type="hidden" name="loginstatus" value="4"/><input type="hidden" name="id" value="'.$id.'4"/>
<input type="submit" value="提交"></form>';
?>
处理
<?php
header('Content-Type: text/html; charset=utf8');
$cookie=dirname(__FILE__).'/cookie.ck';
$cokie=dirname(__FILE__).'/cokie.ck';
@unlink($cookie);
$post['m']=$_POST['m'];
$post['pass']=$_POST['pass'];
$post['captchaCode']=$_POST['captchaCode'];
$post['loginstatus']=$_POST['loginstatus'];
$curl = curl_init('
http://f.10086.cn/im/login/inputpasssubmit1.action');
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
curl_setopt( $curl,CURLOPT_COOKIEFILE, $cokie);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
$result = curl_exec($curl);
curl_close($curl);
echo $result;
?>
为了防止图片被缓存,可以给图片加一个参数如'verifycode.png?t='.time()
http://hu60.cn/wap/0wap/addown.php/jumpimg.php.gz
$file=file_get_contents('http://f.10086.cn/im/login/login.action');
preg_match_all('/<img src="\/im\/systemimage\/verifycode(.*).png\?tp=im5"/Ui',$file,$match);
$cokie=dirname(__FILE__).'/cokie.ck';
@unlink($cokie);
$url='http://f.10086.cn/im/systemimage/verifycode'.$match[1][0].'.png?tp=im5';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cokie);
curl_setopt($curl, CURLOPT_POST, 1);
$img = curl_exec($curl);
curl_close($curl);
file_put_contents('img.png',$img);
<img src="地址?t=<?php echo time();?>"/>
你的浏览器对验证码进行了非正常的缓存,而解决问题的最简单办法就是每次都生成一个不同的地址。