给定url(https://127.0.0.1:8443/example.html<-是的,它是安全连接)正在检查用户是否已登录(通过jboss服务器),如果是,则他有权访问某些内容。
当我登录并尝试在浏览器中运行这个url时,一切都很好,jboss logger显示用户已经登录,但当我从php脚本()调用file_get_content(url)http://127.0.0.1/test/check<-codeigniter url,下面的代码)用户总是在jboss中注销。不知道为什么。
我也尝试过curl库,但没有成功。
public function check(){
echo 'begin';
// $total_rows = file_get_contents('https://127.0.0.1:8443/example.html?shopId=121');
$total_rows = $this->getUrl('https://127.0.0.1:8443/example.html', '121');
print_r($total_rows);
echo 'end';
}
function getUrl($url, $shopId ='') {
$post = 'shopId=' . $shopId;
$ch = curl_init();
// curl_setopt($ch, CURLOPT_PORT, 8443);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."/../../files/cacert.pem");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Secure Content-Type: text/html; charset=UTF-8"));
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: 127.0.0.1:8443'));
$ret = curl_exec($ch);
curl_error ($ch );
curl_close($ch);
return $ret;
}
简而言之:这不是web的工作方式。
当您在浏览器中输入https://example.com
并登录时,浏览器会收到一个cookie并登录。
当你从一个完全不相关的服务器(即使该服务器在同一台机器上)获取URL https://example.com
时,这是一个来自新客户端的完全不同的请求,你将相应地而不是登录。这与你打开另一个浏览器(如Firefox和Chrome)一样;您不会同时自动登录。