欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

php模拟ssl登录https网站

程序员文章站 2022-03-17 16:18:33
...
<?php



# //Post的地址

$url='https://us.etrade.com/login.fcc';
#
# //目标来源页面
$referer='https://us.etrade.com/e/t/pfm/portfolioview?portfolio=A6756-2892&_formtarget=portfoliolist&traxui=ac_combo';
#
# //如果目标网站需要登录,可以在这里写入模拟的Cookie值
$cookie_file='G:/cookies.txt';
#
# //将$post_data中写入你所截取的数据包,可以使用Winsock Expert截取数据包
$post_data='PASSWORD=****&USER=****&TARGET=/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;

?>