使用cloudflare(完整SSL)向服务器发送PHP curl post请求有SSL错误和Blank SESSION Cookie

时间:2015-04-07 07:12:25

标签: php session ssl curl cloudflare

嗨,我现在正在做一个网站。这两个文件都在一个服务器和域中,我正在使用cloudflare来增加负载。我在cloudflare上使用Full SSL选项,因为我在服务器上购买了自己的SSL Geotrust。我已经将服务器上的卷曲升级到7.41.0。

一个php文件由函数

组成

功能文件:

<?php
function get_content($session){
    $endpoint = "https://sample.ph/php/resource.php";
    // Use one of the parameter configurations listed at the top of the post
    $params = array(
        "yel" => $session
    );

    $curl = curl_init();
    curl_setopt($curl,CURLOPT_URL,$endpoint);
    $strCookie = 'PHPSESSID='.$_COOKIE['PHPSESSID'];
    curl_setopt($curl, CURLOPT_COOKIE, $strCookie);
    curl_setopt($curl, CURLOPT_POST, 1); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_VERBOSE, true); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); 
    $postData = "";

    //This is needed to properly form post the credentials object
    foreach($params as $k => $v)
    {
       $postData .= $k . '='.urlencode($v).'&';
    }
    $postData = rtrim($postData, '&');

    curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60); 
    curl_setopt($curl, CURLOPT_HEADER, 0); // Don’t return the header, just the html
    curl_setopt($curl, CURLOPT_CAINFO,"/home/sample/public_html/php/cacert.pem"); // Set the location of the CA-bundle

    session_write_close();
    $response = curl_exec($curl);

    if ($response === FALSE) {
    return "cURL Error: " . curl_error($curl);
    }
    else{
    // evaluate for success response
    return $response;   
    }
    curl_close($curl);
}
?>

资源文件

<?php
session_start();

if(isset($_POST['yel'])){

$drcyt_key = dcrypt("{$_POST['yel']}");

  if($drcyt_key == $_SESSION['token']){
   echo "Success";

  }
}
?>

你觉得我怎么解决这个问题?

  1. SSL验证错误。在调试时有时我得到cURL错误:SSL证书问题,验证CA证书是否正常。详细信息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败

  2. 有时候我遇到了cURL错误:SSL对等证书或SSH远程密钥不正常

  3. 当我输入curl_setopt($ curl,CURLOPT_SSL_VERIFYPEER,true);假,这不是一个好主意; SESSION COOKIE在第一次加载时变得空白,这是第二个问题。

  4. 我希望你能帮助我。谢谢。

1 个答案:

答案 0 :(得分:0)

此问题在服务器上看起来是过时的证书捆绑包或过时的OpenSSL版本。您应该确保在计算机上拥有最新的根证书,并确保拥有最新版本的OpenSSL(包括PHP OpenSSL模块)。