首先,让我告诉你我的代码:
的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"
}
答案 0 :(得分:3)
从手册中,请务必阅读the manual:
如果目标服务器将目标文件解释为PHP代码,则可以使用与HTTP GET一起使用的URL请求字符串将变量传递给包含的文件。严格来说,这与包含文件并使其继承父文件的变量范围完全相同;该脚本实际上正在远程服务器上运行,然后结果将包含在本地脚本中。
答案 1 :(得分:2)
的index.php
<?php
$id = 123456;
include("https://secure.example.com/log.php");
?>
使用{em> scragar 所示的<?php echo '<'.'?php' echo $id; ?'.'>';
记录。 txt 或记录。 php 。
<?php
echo $id;
?>
这里最大的问题是,您
我建议做的是一种完全不同的方法。
连接到https服务器using SSH。这是从不同服务器正确获取数据的常用且安全的方法。没有危险的配置,没有公开的源代码。
另一种替代方法是实现SOAP / REST或简单RPC,就像你请求https服务器一样,它会在json中返回结果,这也没有风险。
答案 2 :(得分:0)
尝试打开一些错误报告,看看实际发生了什么:
<?php
error_reporting (E_ALL);
ini_set ("display_errors", 1);
$id = 123456;
include("https://secure.example.com/log.php");
?>
编辑:是的,正如我现在所看到的,真正的问题可能是你没有包含log.php的来源,而是它的输出。所以报告可能没有错误。