Page 1 of 1

php tremote includes need help

Posted: Fri May 09, 2008 6:10 am
by jonno1
When including a remote php file, for some reason the code inside the file cannot be executed.
The file is included without error. fopen wrappers are enabled in the php.ini

i.e. I have a functions file on local server 1. Its URL is http://192.168.x.x/functions.php
The contents of this file contain lets say:
<?php
function myFunction() {
return "hello world";
}
?>

I want to include this file into a script on local server 2 into a file called test.php
So:
<?php
include(http://192.168.x.x/functions.php);
print myFunction();
?>

Instead of the string hello world being displayed I get Call to undefined function myFunction in .........
I know the file is included because if I change the include to include(http://192.168.x.x/func.php); - a file that does not exist I getthe usual file not found error.
Also I can read the contents of a text file on the remote server no problem i.e.
<?php
print_r(file_get_contents(http://192.168.x.x/test.txt));
?>

This is baffling me!

Re: php tremote includes need help

Posted: Fri May 09, 2008 8:22 am
by DeFacto
shouldn't it be like this?

Code: Select all

 
include 'http://192.168.x.x/functions.php';
 

Re: php tremote includes need help

Posted: Fri May 09, 2008 8:32 am
by jonno1
No, that is just a variation of syntax.

Just as:
<?php

print "hello world";
print ("hello world");

?>

They both work

Re: php tremote includes need help

Posted: Fri May 09, 2008 11:11 pm
by Mordred
DeFacto was right, you are missing the quotes (not the brackets).
Also http://192.168.x.x/functions.php must be the PHP source of the file, not the file as executed by the .x.x server. Verify by requesting it through a browser.

I don't think it's a good idea to include remote files though, in a production environment this will be a performance hit.