[求助]PHP Curl 模拟登录问题

如题,已登录进去了,且已查看到保存了cookie,但当使用cookie进入其它页面时有问题,看上去像是没有取到cookie.

<?php
echo "Hello World";
$cookie_file = dirname(__FILE__).'/cookie.txt';
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.stockmarket.aero/StockMarket/LoginAction.do");
curl_setopt ( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
// Do a POST
$data = array('username' => '***','password' => '***','group1' => 'signIn');
$data = http_build_query($data, '&');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ( $ch, CURLOPT_COOKIEJAR, $cookie_file);

$output = curl_exec($ch);
if ($output === FALSE) {
echo "cURL Error: " . curl_error($ch);
}
curl_close($ch);

//如果在此使用echo $output ,可得到登录进去后的页面。说明上面这一部分的代码已成功运行,而且已查看有最新的cookie.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.stockmarket.aero/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie_file); //怀疑此处没有取到cookie

$output2 = curl_exec($ch);

if ($output2 === FALSE) {
echo "cURL Error: " . curl_error($ch);
}
curl_close($ch);

echo $output2; //跳回登录界面,提醒还需再登录. 我以为能显示已登录的页面的。。。。问题在此。
?>

附cookie:

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

www.stockmarket.aero FALSE /StockMarket TRUE 0 JSESSIONID F513161730210CC2ED293F4C393CC3C9

你可能感兴趣的:(PHP,header,ssl,File,url,output)