1

您好我想在我的 php 文件中包含一个外部 .php 文件。

这个 .php 文件在我的页面中需要一些变量声明。

我尝试使用 file_get_contents 但它只是呼应里面的行。

试过:

function getter($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

echo getter('www.somehting.com/phpfile.php');

-还是行不通

也试过:

$code = file_get_contents($url);
eval($code);

无论如何我可以在不更改 config.ini 的情况下执行此操作吗?

我可以在应该包含该文件的页面上访问 .htaccess。

该文件位于不同的服务器“机架空间”上。

谢谢你。

4

2 回答 2

1

You cannot include an external php file, unless the .php file is outputing the php source. Otherwise you will just get the interpreted php file from the external source.

The only thing you can do is output the .phps (source) so that you can access the actually code. Like I said above, you would be accessing the processed / interpreted php file, which would do you no good.

If you have access to the other server, you can try outputing the file.phps instead of file.php

于 2012-11-12T17:57:27.623 回答
0

如果您通过网址在外部服务器上加载文件,Apache 将在 php 完成后显示该页面。

所以它会返回

Hello world!

代替

<?php
echo 'Hello world!';
?>

但是,您可以尝试使用ftp 连接连接到外部服务器并检索您想要的文件。这将要求您具有对其托管服务器的管理员访问权限。

于 2012-11-12T18:04:26.667 回答