如何从URL-external-php-file获取'echo'内容

1 php get external

我在2个不同的服务器上有2个文件:

file1.php - 驻留在站点1 - 我传递一个参数,并且脚本echo-ed答案依赖于(是函数)传递的参数 - everithink在我通过浏览器访问文件时是可以的

   http://site1.com/file1.php?parameterValue
Run Code Online (Sandbox Code Playgroud)

file2.php - 驻留在站点2上 - file2必须向file1.php发送一个参数并从中获取echo-ed输出作为变量.

我尝试用3种不同的方式做到这一点,但没有人工作.

方式1. -------

function get_data($url)
{
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}  

$f="http://site1.com/file1.php?parameterValue";
$returned_content = get_data($f);
echo "=== $returned_content ===";exit;
Run Code Online (Sandbox Code Playgroud)

方式2. -------

$f="http://site1.com/file1.php?parameterValue";
$returned_content='';
$file = fopen ($f, "r");
if (!$file) {
    echo "<p>Unable to open remote file.\n";
    exit;
    }
while (!feof ($file))  $returned_content.= fgets ($file, 1024);
fclose($file);
echo "=-= $returned_content =-=";exit;
Run Code Online (Sandbox Code Playgroud)

方式3. -------

$f="http://site1.com/file1.php?parameterValue";
$returned_content=implode('',file($f));
echo "=-= $returned_content =-=";exit;
Run Code Online (Sandbox Code Playgroud)

但是$ returned_content是空字符串...

有谁能够帮我?提前致谢!

斯托伊奇

tim*_*dev 5

如果你尝试会发生什么:

<?PHP
$f="http://site1.com/file1.php?parameterValue";
$data = file_get_contents($f);
echo $data;
Run Code Online (Sandbox Code Playgroud)