测试了一个晚上 还是找不出 问题, 验证码我也保存了 , Coookie 我也保存了 可是带着 cookie 和 data 提交 总出现 验证码错误,大神帮忙看看 到底哪里出错了,这大半夜的码代码不容易啊。。。。
测试链接
http://v.milog.cn/1.php
测试帐号 eoo 123456
1.php 代码
<?php
header ("content-Type: text/html; charset=utf-8");
$cookie_file = './cookie.txt';
//这是验证码地址
$verify_code_url = '
http://dnszc.ml/index.php?m=Public&a=verify';
$curl = curl_init ();
curl_setopt ($curl,CURLOPT_URL,$verify_code_url );
curl_setopt ($curl,CURLOPT_COOKIEJAR,$cookie_file );
curl_setopt ($curl, CURLOPT_HEADER,false );
curl_setopt ($curl,CURLOPT_RETURNTRANSFER,true );
$img = curl_exec ($curl );
curl_close ($curl );
//保存验证码
file_put_contents ("verifyCode.jpg",$img );
echo<<<HTML
<form action="2.php" method="post">
<p>帐号<input type="text" name="name"></p>
<p>密码<input type="password" name="password"></p>
<p>验证<input type="text" name="var"><img src="verifyCode.jpg"/></p>
<p><input name="submit" type="submit" value="登录"></p>
</form>
HTML;
?>
2.php 代码
<?php
if ($_POST['submit']){
print_r ($_POST );
//POST 登录地址
$login_url='http://dnszc.ml/index.php?m=Login&a=logining';
//POST 参数
$str_data="name={$_POST['name']}&password={$_POST['password']}&verify={$_POST['var']}";
$ch=curl_init ();
curl_setopt ($ch,CURLOPT_URL,$login_url );
curl_setopt ($ch,CURLOPT_HEADER,true );
curl_setopt ($ch,CURLOPT_TIMEOUT,5 );
curl_setopt ($ch,CURLOPT_POST,true );
curl_setopt ($ch,CURLOPT_POSTFIELDS,$str_data );
//curl_setopt ($ch,CURLOPT_HTTPHEADER,$header );
curl_setopt ($ch,CURLOPT_COOKIEFILE,$cookie_file );
//curl_setopt ($ch,CURLOPT_PROXY,"202.194.101.150:80");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER,false );
curl_exec ($ch );
}