PHP in the Curl HTTPS Skip SSL authentication error

Source: Internet
Author: User
Tags openssl version
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:


    1. 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)

    2. 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

    3. When
    4. 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:


    1. 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)

    2. 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

    3. When
    4. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.