php - 从安全的 SSL 路径调用和运行这个 php curl 函数的“正确方法”是什么?
问题描述
我一直在仔细查看这段代码,它不是由我创建的,一旦你从安全的 SSL 路径调用它并在整个过程中使用安全路径,它就会停止工作。我添加了几行以希望解决 SSL 问题,但没有成功。无法联系创建此内容的原始人,因此我希望我只是遗漏了一些我不理解的东西。
我不使用 PHP,所以我希望更多地了解为什么在通过 SSL 路径调用它时它不起作用。我确实四处寻找答案,但没有找到适合这个问题的答案。
该文件使用非 SSL 路径(即http://www.example.com/sub/filename.php )运行时确实存在零问题,但是当我通过此 url https调用文件来运行文件时,我得到的只是 False : //www.example.com/sub/filename.php。
php日志显示了这一点。
[16-Aug-2019 15:05:35 UTC] PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
[16-Aug-2019 15:05:35 UTC] PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
[16-Aug-2019 15:05:35 UTC] PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
[16-Aug-2019 15:05:35 UTC] PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
提前感谢您的帮助。
<?php
error_reporting(0);
ini_set("display_errors", 0);
$DEBUG = false;
if($DEBUG) { echo "<h1>From Data File {$_GET['s']}</h1>"; }
$info = file_get_contents($_SERVER['DOCUMENT_ROOT']."/_tempfiles/_ses/{$_GET['s']}");
list($url,$vars,$header) = explode("||^||",$info);
unlink($_SERVER['DOCUMENT_ROOT']."/_tempfiles/_ses/{$_GET['s']}");
if(preg_match("|\r\n|",$header)) {
$theaders = explode("\r\n",$header);
}
else {
$theaders = explode("\n",$header);
}
foreach($theaders as $t) {
if(trim($t) != '') {
list($field,$value) = explode(':',$t);
if(trim($field) != 'Host') {
$headers[] = trim($t);
}
}
}
if($DEBUG) {
echo "<H1>URL</H1>{$url}";
echo "<H1>Headers Array (w/Host removed)</H1>";
var_dump($headers);
echo "<H1>Vars</H1>{$vars}";
echo "<H1>Content Length Validation</H1>".strlen($vars);
echo "<h1>Output From Remote URL below line:</h1>";
echo "<HR>";
}
$ch = curl_init();
// Configure curl for website
curl_setopt($ch, CURLOPT_URL,$url);
// Turn on SSL certificate verfication
curl_setopt($curl, CURLOPT_CAPATH, "/home/domain/unc/cacert.pem");
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars);
if(isset($headers) && is_array($headers) && count($headers) > 0) {
//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
// 1 second for a connection timeout with curl
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
// Try using this instead of the php set_time_limit function call
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
echo $server_output;
?>
解决方案
我提供的代码似乎工作正常。我只需要检查该软件也传递 var 字符串的返回路径。因此,感谢您的帮助,希望这可以帮助其他有同样问题的人。
推荐阅读
- docusignapi - DocuSign:签名库 v3.0.0
- javascript - 在整个项目的javascript中用加号替换逗号
- indexing - Solr:创建远程 solr 核心时出错
- django - _io.BytesIO' 对象没有小文件的属性“名称”
- javascript - 如何使用 for 循环创建多个进度条?
- reporting-services - SSRS 呈现为 pdf 始终将日期显示为 MM/DD/YYYY
- python - 文件名中带有空格的python中的单词计数
- google-bigquery - BigQuery:它是否支持 UDAF?
- vba - 将预定义的 excel 函数应用于 VBA for 循环数组以创建新函数
- javascript - 解析错误Javascript