Page 1 of 1
remote include() question
Posted: Fri Oct 03, 2003 3:04 pm
by Black Majic
Is there any way I can have a file hosted remotely which executes a query on the filesystem of the remote server, then return a variable to the calling script?
somthing like...
Code: Select all
include("http://11.22.33.44/remotefile.php") // reads file, returns $fileContents
Posted: Fri Oct 03, 2003 5:22 pm
by qads
Posted: Fri Oct 03, 2003 7:57 pm
by JAM
Uhm...
http://se.php.net/manual/en/function.include.php wrote:
If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using an URL (via HTTP or other supported wrapper - see Appendix I for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using an URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.
Posted: Fri Oct 03, 2003 7:59 pm
by Cruzado_Mainfrm
why don't u use the file() function?
i think is $array = file('
http://www.thesite.com/page.html');
and then you use the explode function to extract the lines...
Posted: Fri Oct 03, 2003 8:06 pm
by volka
edit: oops, I'm way too slow
include() returns what the interpreted code of the included file returns.
Code: Select all
<?php // whatSoEver.php
$dirlisting = array();
$dh = opendir('.');
while($de = readdir($dh))
$dirlisting[] = $de;
return $dirlisting;
?>
Code: Select all
<?php
$dirlisting = include('./whatSoEver.php');
print_r($dirlisting);
?>
this will print the array returned by whatSoEver.php
But if you querry a document on another server (via url_wrappers) the script will already be parsed there.
Your script does not get any php code it can parse. But you can print something that the local script can parse as php-code
Code: Select all
<?php // whatSoEver.php
$dirlisting = array();
$dh = opendir('.');
while($de = readdir($dh))
$dirlisting[] = base64_encode($de);
echo '<'."?php return '" .serialize($dirlisting) ."'; ?".'>';
?>
Code: Select all
<?php
$returnValue = include('http://your.serv.er/whatSoEver.php');
$dirlisting = unserialize($returnValue);
$dirlisting = array_map('base64_decode', $dirlisting);
print_r($dirlisting);
?>
Posted: Fri Oct 03, 2003 8:08 pm
by Black Majic
the remote script is written to take some constants, and check them against constants on the remote side
then it *should* return a few vars as links to update if the client versions are different from the server versions.