简体   繁体   English

使用SSL时发生PHP Curl错误

[英]PHP Curl Error when using SSL

I am trying to use the WHMCS API to connect a third party script to it. 我正在尝试使用WHMCS API将第三方脚本连接到它。 I have created the third party's script as follows, however, when I try to connect to my site using HTTPS, I get this error: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol 我创建了如下的第三方脚本,但是,当我尝试使用HTTPS连接到我的站点时,出现此错误:error:140770FC:SSL例程:SSL23_GET_SERVER_HELLO:未知协议

If I use HTTP, I get a 404 error. 如果使用HTTP,则会收到404错误。 The code is as follows (and yes, that is my actual domain, since I figured the SSL's specifics might matter): 代码如下(是的,这是我的实际域,因为我认为SSL的细节可能很重要):

$email = $_GET["email"];
$password = $_GET["password"];
if(filter_var($email, FILTER_VALIDATE_EMAIL) && strlen($password) > 0) {
    $postfields["username"] = $apiusername;
    $postfields["password"] = $apipassword;
    $postfields["action"] = "validatelogin";
    $postfields["email"] = $email;
    $postfields["password2"] = $password;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://tfdidesign.com/accounts/includes/api.php");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 100);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);   
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    $data = curl_exec($ch);
    if(curl_error($ch))
        echo(curl_error($ch));
    curl_close($ch);     
    $data = explode(";",$data);
    foreach ($data AS $temp) {
        $temp = explode("=",$temp);
        $results[$temp[0]] = $temp[1];
    }
}
else
    die("INVALID_CREDENTIALS");

Define the ssl version for your curl(it can be 2 or 3): 为curl定义ssl版本(可以是2或3):

curl_setopt($curl, CURLOPT_SSLVERSION,3);

Also try to use this one: 也尝试使用此方法:

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM