一、定义COOKIE存储路径
必须使用绝对路径
$COOKIE_jar = dirname(__FILE__)."/pic.COOKIE";
二、获取COOKIE
将COOKIE存入文件
$url = "http://1.2.3.4/"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEJAR, $COOKIE_jar); $cOntent= curl_exec($ch); curl_close($ch);
三、模拟浏览器获取验证码
该服务器验证码有漏洞,可以自己指定
取出COOKIE,一起提交给服务器,让服务器以为是浏览器打开登陆页面
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://1.2.3.4/getCheckpic.action?rand=6836.185874812305'); curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIE_jar); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $ret = curl_exec($ch); curl_close($ch);
四、POST提交
$post = "name=2&userType=1&passwd=asdf&loginType=1&rand=6836&imageField.x=25&imageField.y=7"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://1.2.3.4/loginstudent.action"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIE_jar); $result=curl_exec($ch); curl_close($ch);
五、到指定页面获取数据
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://1.2.3.4/accountcardUser.action"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,0); curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIE_jar); $html=curl_exec($ch); // var_dump($html); curl_close($ch);
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。