2014-11-27 7 views
0

PHP와 Curl을 사용하여 HTTPS 서버에 연결하려고했습니다. 나는 어떤 오류나 반응을 얻지 못한다.PHP Curl HTTPS에 연결하지 않았습니다.

$options = array(
    CURLOPT_RETURNTRANSFER => true,  // return web page 
    CURLOPT_HEADER   => true, // return headers 
    CURLOPT_FOLLOWLOCATION => true,  // follow redirects 
    CURLOPT_ENCODING  => "",  // handle all encodings 
    CURLOPT_USERAGENT  => "spider", // who am i 
    CURLOPT_AUTOREFERER => true,  // set referer on redirect 
    CURLOPT_CONNECTTIMEOUT => 120,  // timeout on connect 
    CURLOPT_TIMEOUT  => 120,  // timeout on response 
    CURLOPT_MAXREDIRS  => 10,  // stop after 10 redirects 
    CURLOPT_SSL_VERIFYPEER => true, 
    CURLOPT_SSL_VERIFYHOST => 2, 
    CURLOPT_CAINFO   => 'ca.pem' 
); 

$ch = curl_init("https://www.google.com"); 
curl_setopt_array($ch, $options); 

var_dump(curl_exec($ch)); 
var_dump(curl_getinfo($ch)); 
var_dump(curl_errno($ch)); 
var_dump(curl_error($ch)); 

출력은 예상대로 내가 http://www.google.com에 URL을 변경하는 경우

bool(false) 
array(22) { 
    ["url"]=> 
    string(23) "https://www.google.com/" 
    ["content_type"]=> 
    NULL 
    ["http_code"]=> 
    int(0) 
    ["header_size"]=> 
    int(0) 
    ["request_size"]=> 
    int(0) 
    ["filetime"]=> 
    int(-1) 
    ["ssl_verify_result"]=> 
    int(0) 
    ["redirect_count"]=> 
    int(0) 
    ["total_time"]=> 
    float(0.004288) 
    ["namelookup_time"]=> 
    float(0.004212) 
    ["connect_time"]=> 
    float(0.006157) 
    ["pretransfer_time"]=> 
    float(0) 
    ["size_upload"]=> 
    float(0) 
    ["size_download"]=> 
    float(0) 
    ["speed_download"]=> 
    float(0) 
    ["speed_upload"]=> 
    float(0) 
    ["download_content_length"]=> 
    float(-1) 
    ["upload_content_length"]=> 
    float(-1) 
    ["starttransfer_time"]=> 
    float(0) 
    ["redirect_time"]=> 
    float(0) 
    ["certinfo"]=> 
    array(0) { 
    } 
    ["redirect_url"]=> 
    string(0) "" 
} 
int(77) 
string(0) "" 

이 스크립트는 구글의 페이지를 반환합니다. 쉘에서 컬을 실행하고 https 사이트로 이동할 수 있습니다. 오류나 다른 출력물이 제시되지 않아서 무엇을 시도해야할지 모르겠습니다.

컬 버전 7.38.0 PHP 버전 당신은 curl_error()에서 오류 메시지를 확인하려고한다 5.3.29

답변

1

입니다. http://www.php.net/curl_error

또한 Curl에는 https 인증서를 인증 할 수있는 오래된 파일이있을 수 있습니다.

curl_setopt($ch, CURLOPT_SSLVERSION, 3); 

최신 SSL 버전이 사용되었는지 확인하기 : http://curl.haxx.se/ca/cacert.pem

그리고 사용에 새가있다.

이 설정 :

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 

도 작동합니다.

그러나 이는 보안 위험을 의미합니다. '프로덕션'서버에서는 사용하지 마십시오.

관련 문제