0

指定されたURL ( https://127.0.0.1:8443/example.html <- はい、安全な接続です ) は、ユーザーが (jboss サーバーによって) ログインされているかどうかをチェックしています。

ログインしてブラウザでこのURLを実行しようとすると、すべて問題なく、jboss ロガーはユーザーがログインしていることを示しますが、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;
}
4

1 に答える 1

1

要するに、それはウェブの仕組みではありません。

ブラウザに入っhttps://example.comてログインすると、ブラウザは Cookie を受け取り、ログインします。

まったく関係のないサーバーからURL を取得するhttps://example.comと (そのサーバーが同じマシン上にある場合でも)、それは新しいクライアントからのまったく別の要求であり、それに応じてログインされません。別のブラウザーを開いた場合と同じです。 (たとえば、Firefox と Chrome); 両方で自動的にログインするわけではありません。

于 2012-08-24T14:26:28.203 に答える