2013-04-25 14 views
13

ich dieses Stück Code haben Abfragen mit curl zu starten:php curl: SSL_VERIFYPEER Option hat keine Wirkung

function curl_query($full_url, $username, $password, $payload) { 
    $additionalHeaders = ""; 
    $process = curl_init($full_url); 
    curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', $additionalHeaders)); 
    curl_setopt($process, CURLOPT_HEADER, 0); 
    curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password); 
    curl_setopt($process, CURLOPT_TIMEOUT, 30); 
    curl_setopt($process, CURLOPT_POST, 1); 
    curl_setopt($process, CURLOPT_POSTFIELDS, $payload); 
    curl_setopt($process, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($process, CURLOPT_MAXREDIRS, 4); 
    curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE); 
    $return = curl_exec($process); 
    if ($return === false) { 
     error_log("CURL error ".curl_error($process)); 
    } 
    return $return; 
} 

Die Option CURLOPT_SSL_VERIFYPEER auf false gesetzt ist, so kann ich Seiten mit selbstsignierten lesen Zertifikate. Jedoch, wenn ich diesen Code gegen eine https-URL auszuführen, bekomme ich einen Fehler:

CURL error SSL: certificate subject name 'localhost' does not match target host name '192.168.1.1', 

ich diesen Code auf einem CentOS 5 Server mit php53 Paket installiert laufen.

Vielen Dank im Voraus

Antwort

37

Fügen Sie die Option CURLOPT_SSL_VERIFYHOST

curl_setopt($process, CURLOPT_SSL_VERIFYHOST, FALSE); 

Ich erkennen, dass die Englisch-Version der PHP-Dokumentation fehlt diese wichtigen Informationen:

(von der Deutsch-Version übersetzt von das PHP-Handbuch)

CURLOPT_SSL_VERIFYHOST has to be set to true or false if CURLOPT_SSL_VERIFYPEER has been deactivated.

+0

Es hat funktioniert. Ich danke dir sehr. – facha

+0

Sie sind herzlich willkommen! – hek2mgl

+1

Wie offensichtlich. Es gibt sowohl ein 'CURLOPT_SSL_VERIFYHOST' ** als auch ein 'CURLOPT_SSL_VERIFYPEER'. Das habe ich vermisst; Das hat mich gerettet. Vielen Dank! –

Verwandte Themen