Server Side Include

倾然丶 夕夏残阳落幕 提交于 2019-12-06 14:34:27

Use cURL to get data outside of the domain. If you want to then execute the data you receive, go ahead and eval() it. But, be forewarned that this will get the 'output' of the page. Meaning if it is an executed page like a '.php' page, you will get the data that comes out as a result of it being processed.

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

The same is true for file_get_contents(), and fopen()

If you wanted to grab the 'actual' contents of the file, you would want to set up a proxy of sorts on the other server. (You can't do it on your server because then it would be a security flaw in how server-side-scripting works).

<?php

// Read the requested file out
readfile($_GET['file']);

That will give you the contents of any file you request:

http://test.com/handler.php?file=handler.php

But, if anyone else finds it, it could be dangerous.

You don't mention the server software but I'll assume Apache, where SSI is provided by the mod_include module. The include element does not allow remote files. However, you have exec, which allows to execute any external tool; you can use it to call wget or any other command of your choice.

However, it might not be so complicate. If you can mount the remote directory in the local system, you can create a plain symlink and use a regular include.

Or, as already suggested, PHP is really simple to use.

You can do something like file_get_contents() or fopen() to do this in php, e.g.

<?php
    echo file_get_contents('http://www.example.com/include');
?>

Yes, nginx's server side includes can use any full url eg:

<!--# include virtual="http://www.stackoverflow.com/" -->
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!