发新话题
打印

php ssl模式下模拟登录【测试通过】

php ssl模式下模拟登录【测试通过】

该功能在本地搭建的环境下可以正常登录,但应用到其他网站就不行,目前还没找到解决办法。
<?php
ini_set('session.cookie_domain', '.cainuo.cn'); // 这里我把本地的根域修改成抓取网站的根
@session_start();
# //Post的地址
$url="https://cainuo.com/do.php";
#
# //目标来源页面
$referer='https://cainuo.com/index.php';
#
# //如果目标网站需要登录,可以在这里写入模拟的Cookie值
$cookie_file='D:/Program Files/PHPnow/htdocs/cainuo/cookies.txt';
#
# //将$post_data中写入你所截取的数据包,可以使用Winsock Expert截取数据包
$post_data='password=555555&username=fangzhen&from=buy&style=34&product=mail163&savelogin=&selType=-1TARGET=/e/t/invest/socreateentry';
#
# //部分网站验证浏览器信息,可以在下面模拟浏览器,可以直接将USERAGENT复制到这里面
$useragent='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)';
#

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
//curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); //保存cookie
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); //发送cookie
curl_setopt($ch, CURLOPT_USERAGENT,$useragent);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_exec($ch);


curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt($ch, CURLOPT_URL,$referer);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); //保存cookie
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); //发送cookie
curl_setopt($ch, CURLOPT_USERAGENT,$useragent);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);

if($result==NULL){
    echo"Error:<br>";
    echo curl_errno($ch)."-".curl_error($ch)."<br>";
}

curl_close($ch);
print $result;
[ 本帖最后由 xiexie 于 2012-6-27 17:51 编辑 ]

TOP

测试通过

TOP

发新话题