This article is mainly to share with you PHP in the Curl HTTPS skip SSL authentication error analysis and solutions, hope to help everyone.
Function get($url = '', $cookie = ''){
$ch = curl_init();
Curl_setopt($ch, CURLOPT_URL, $url);
Curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Retrieve the information obtained by curl_exec() as a file stream instead of directly.
Curl_setopt($ch, CURLOPT_HEADER, 0);
Curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Check the source of the certificate
Curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // Check if the SSL encryption algorithm exists from the certificate
Curl_setopt($ch, CURLOPT_SSLVERSION, 2);//Set the SSL protocol version number
If($cookie){
Curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
Curl_setopt ($ch, CURLOPT_REFERER, 'https://wx.qq.com');
}
Curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
Curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $output = curl_exec($ch); if ( curl_errno($ch) ) return curl_error($ch);
Curl_close($ch); return $output;
}
The above method is the user Curl initiates HTTPS request function, curlopt_sslversion item is stipulated the SSL protocol version, the online code many say can be set to 1/2/3 but my test result is as follows:
-
is set to 1 o'clock in PHP 5.2.11, there will be an error as follows:
"Error:14077458:ssl routines:ssl23_get_ Server_hello:reason (1112) "
The reason for the error here is that your PHP version of OpenSSL is too low to upgrade your PHP to 5.3.60 (specifically higher than which version I did not test, should be as long as the OpenSSL version is greater than 0.9.8 version)
-
When set to 2, the error is as follows:
Linux environment Error: "SSL version range is not valid."
Windows environment Error: "OpenSSL is built without SSLV2 support"
This should be easier to understand that the version number of the SSL protocol is invalid
When
-
is set to 3, the error is as follows:
Linux Environment error: "Encountered end of file".
Windows environment error: "Unknown SSL protocol error in connection to login.wx.qq.com:443"
The cause of this error I thought it was because of the SSLV2 after I checked the data online. There is a security vulnerability with SSLV3, so the SSLV2 and SSLV3 protocol versions are no longer used, so we have an error when we set it to 3.
Function get($url = '', $cookie = ''){
$ch = curl_init();
Curl_setopt($ch, CURLOPT_URL, $url);
Curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Retrieve the information obtained by curl_exec() as a file stream instead of directly.
Curl_setopt($ch, CURLOPT_HEADER, 0);
Curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Check the source of the certificate
Curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // Check if the SSL encryption algorithm exists from the certificate
Curl_setopt($ch, CURLOPT_SSLVERSION, 2);//Set the SSL protocol version number
If($cookie){
Curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
Curl_setopt ($ch, CURLOPT_REFERER, 'https://wx.qq.com');
}
Curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
Curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $output = curl_exec($ch); if ( curl_errno($ch) ) return curl_error($ch);
Curl_close($ch); return $output;
}
The above method is the user Curl initiates HTTPS request function, curlopt_sslversion item is stipulated the SSL protocol version, the online code many say can be set to 1/2/3 but my test result is as follows:
-
is set to 1 o'clock in PHP 5.2.11, there will be an error as follows:
"Error:14077458:ssl routines:ssl23_get_ Server_hello:reason (1112) "
The reason for the error here is that your PHP version of OpenSSL is too low to upgrade your PHP to 5.3.60 (specifically higher than which version I did not test, should be as long as the OpenSSL version is greater than 0.9.8 version)
-
When set to 2, the error is as follows:
Linux environment Error: "SSL version range is not valid."
Windows environment Error: "OpenSSL is built without SSLV2 support"
This should be easier to understand that the version number of the SSL protocol is invalid
When
-
is set to 3, the error is as follows:
Linux Environment error: "Encountered end of file".
Windows environment error: "Unknown SSL protocol error in connection to login.wx.qq.com:443"
The cause of this error I thought it was because of the SSLV2 after I checked the data online. There is a security vulnerability with SSLV3, so the SSLV2 and SSLV3 protocol versions are no longer used, so we have an error when we set it to 3.