Server Side Include
Asked Answered
M

4

2

Is it possible to use a server side include to access files that are outside of the server?

If not what are some other options to do this?

Mealworm answered 10/8, 2009 at 15:26 Comment(2)
I am trying to access information from a txt file that would be located outside the folder in a drive, for people to be able to upload info onto that file, and it could show up on the website, without the site having to be publishedMealworm
wow, I did not hear about SSI since a looooong time...Rutty
Q
3

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.

Quaff answered 10/8, 2009 at 15:29 Comment(0)
C
3

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.

Cowshed answered 10/8, 2009 at 20:39 Comment(0)
P
1

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');
?>
Pitchblende answered 10/8, 2009 at 15:29 Comment(0)
D
0

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

<!--# include virtual="http://www.stackoverflow.com/" -->
Dyslexia answered 10/8, 2009 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.