您好,欢迎访问一九零五行业门户网

PHP中Curl https跳过ssl认证报错

本文主要和大家分享php中curl https跳过ssl认证报错问题分析及解决办法,希望能帮助到大家。
function get($url = '', $cookie = ''){   $ch = curl_init();   curl_setopt($ch, curlopt_url, $url);   curl_setopt($ch, curlopt_returntransfer, 1); //将curl_exec()获取的信息以文件流的形式返回,而不是直接输出。   curl_setopt($ch, curlopt_header, 0);   curl_setopt($ch, curlopt_ssl_verifypeer, 0); // 对认证证书来源的检查   curl_setopt($ch, curlopt_ssl_verifyhost, 0); // 从证书中检查ssl加密算法是否存在   curl_setopt($ch, curlopt_sslversion, 2);//设置ssl协议版本号   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; }

上面方法是用户curl发起https请求的功能,curlopt_sslversion项是规定ssl协议版本的,网上的代码很多都说可以设置成1/2/3但是我测试的结果如下:
设置成1时在php 5.2.11版本中会有如下报错:
     “error:14077458:ssl routines:ssl23_get_server_hello:reason(1112)”
    此处报错的原因是你的php中openssl的版本过低解决办法是升级你的php到5.3.60(具体是高于哪个版本我没有测试,应该只要openssl版本大于0.9.8版本就可以的)
设置成2时会有如下报错:
    linux环境报错:”ssl version range is not valid.”
    windows环境报错:”openssl was built without sslv2 support”
    这个应该比较容易理解就是ssl协议的版本号已经无效
设置成3时会有如下报错:
    linux环境报错:”encountered end of file”.
    windows环境报错:”unknown ssl protocol error in connection to login.wx.qq.com:443 ”
    出现这个错误的原因网上查资料之后我认为是由于sslv2和sslv3存在安全漏洞所以微信已经不再使用sslv2和sslv3协议版本,所以我们设置成3时会出现错误。
function get($url = '', $cookie = ''){   $ch = curl_init();   curl_setopt($ch, curlopt_url, $url);   curl_setopt($ch, curlopt_returntransfer, 1); //将curl_exec()获取的信息以文件流的形式返回,而不是直接输出。   curl_setopt($ch, curlopt_header, 0);   curl_setopt($ch, curlopt_ssl_verifypeer, 0); // 对认证证书来源的检查   curl_setopt($ch, curlopt_ssl_verifyhost, 0); // 从证书中检查ssl加密算法是否存在   curl_setopt($ch, curlopt_sslversion, 2);//设置ssl协议版本号   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; }

上面方法是用户curl发起https请求的功能,curlopt_sslversion项是规定ssl协议版本的,网上的代码很多都说可以设置成1/2/3但是我测试的结果如下:
设置成1时在php 5.2.11版本中会有如下报错:
     “error:14077458:ssl routines:ssl23_get_server_hello:reason(1112)”
    此处报错的原因是你的php中openssl的版本过低解决办法是升级你的php到5.3.60(具体是高于哪个版本我没有测试,应该只要openssl版本大于0.9.8版本就可以的)
设置成2时会有如下报错:
    linux环境报错:”ssl version range is not valid.”
    windows环境报错:”openssl was built without sslv2 support”
    这个应该比较容易理解就是ssl协议的版本号已经无效
设置成3时会有如下报错:
    linux环境报错:”encountered end of file”.
    windows环境报错:”unknown ssl protocol error in connection to login.wx.qq.com:443 ”
    出现这个错误的原因网上查资料之后我认为是由于sslv2和sslv3存在安全漏洞所以微信已经不再使用sslv2和sslv3协议版本,所以我们设置成3时会出现错误。
相关推荐:
nginx环境下配置php使用的ssl认证(https)
以上就是php中curl https跳过ssl认证报错的详细内容。
其它类似信息

推荐信息