简体   繁体   English

使用cloudflare(完全SSL)到服务器的PHP curl发布请求具有SSL错误和空白会话Cookie

[英]PHP curl post request to server using cloudflare (Full SSL) has SSL error and Blank SESSION Cookie

Hi I'm doing a website right now. 嗨,我正在制作一个网站。 Both of these files is in one server and domain and I'm using cloudflare to boost the loading. 这两个文件都在一个服务器和域中,我正在使用cloudflare来增加负载。 I'm using Full SSL option on cloudflare because I bought my own SSL Geotrust on my server. 我在cloudflare上使用了完全SSL选项,因为我在服务器上购买了自己的SSL Geotrust。 I already upgraded my curl on the server to 7.41.0. 我已经将服务器上的curl升级到7.41.0。

One php file consist of the function 一个php文件包含以下功能

Function File: 功能文件:

<?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);
}
?>

Resource File 资源文件

<?php
session_start();

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

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

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

  }
}
?>

How do you think will I fix this? 您认为我将如何解决?

  1. The SSL Verification error. SSL验证错误。 Upon debugging sometimes I got cURL Error: SSL certificate problem, verify that the CA cert is OK. 有时在调试时出现cURL错误:SSL证书问题,请验证CA证书是否正常。 Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 详细信息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败

  2. Sometimes I got cURL Error: SSL peer certificate or SSH remote key was not OK 有时我出现cURL错误:SSL对等证书或SSH远程密钥不正确

  3. When I put curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); 当我把curl_setopt($ curl,CURLOPT_SSL_VERIFYPEER,true); to FALSE, which is not a good idea; 对于FALSE,这不是一个好主意; There comes a second problem for the SESSION COOKIE becoming blank on first load. SESSION COOKIE在第一次加载时变成空白还有第二个问题。

I HOPE YOU CAN HELP ME. 我希望你能帮助我。 THANK YOU. 谢谢。

This issue looks to be an outdated certificate bundle or outdated OpenSSL version on the server. 该问题似乎是服务器上的证书包已过期或OpenSSL版本已过期。 You should both ensure you have the latest root certificates on your computer and also ensure that you have the latest versions of OpenSSL (including the PHP OpenSSL module). 您既应确保计算机上具有最新的根证书,也应确保具有最新版本的OpenSSL(包括PHP OpenSSL模块)。

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

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