首先,让我展示一下我的代码:
index . php
<?php
$id = 123456;
include("https://secure.example.com/log.php");
?>
log.php
<?php
echo $id;
?>
这个简单的代码理论上应该在index.php
上显示123456,正确吗?然而,我什么也没得到。我只能假设这是因为我试图通过https连接包含文件,但实际情况是这样的吗?index.php
不在安全服务器上。
我在php.ini
中打开了以下设置:
allow_url_include = 1
allow_url_fopen = 1
使用以下代码检查包装器:
var_dump(stream_get_wrappers());
给我一个数组显示https
:
array(12) {
[0]=> string(5) "https"
[1]=> string(4) "ftps"
[2]=> string(13) "compress.zlib"
[3]=> string(14) "compress.bzip2"
[4]=> string(3) "php"
[5]=> string(4) "file"
[6]=> string(4) "glob"
[7]=> string(4) "data"
[8]=> string(4) "http"
[9]=> string(3) "ftp"
[10]=> string(4) "phar"
[11]=> string(3) "zip"
}
从手册开始,始终阅读手册:
如果目标服务器将目标文件解释为PHP代码,则可以使用HTTP GET使用的URL请求字符串将变量传递给包含的文件。严格来说,这与包含文件并让它继承父文件的变量范围不同;脚本实际上是在远程服务器上运行的,然后结果被包含到本地脚本中。
index.php
<?php
$id = 123456;
include("https://secure.example.com/log.php");
?>
日志。txt或log。php使用<?php echo '<'.'?php' echo $id; ?'.'>';
,如scragar.
<?php
echo $id;
?>
这里的大问题是,您在https服务器上暴露了文件的源代码-至少部分。您需要这样做,以便能够在驻留服务器之前远程解析其内容。
我建议采用一种完全不同的方法。
使用SSH连接到https服务器。这是一种从不同服务器正确获取数据的常见且安全的方法。没有风险配置,没有源代码暴露给公众。
另一种替代方法是实现SOAP/REST或简单的RPC,就像您请求https服务器并以json返回结果一样,这也没有风险。
尝试打开一些错误报告,看看实际发生了什么:
<?php
error_reporting (E_ALL);
ini_set ("display_errors", 1);
$id = 123456;
include("https://secure.example.com/log.php");
?>
EDIT:是的,正如我现在所看到的,真正的问题可能是您不包括log.php的源,而是它的输出。所以可能没有错误报告。