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!
php tremote includes need help
Moderator: General Moderators
Re: php tremote includes need help
shouldn't it be like this?
Code: Select all
include 'http://192.168.x.x/functions.php';
Re: php tremote includes need help
No, that is just a variation of syntax.
Just as:
<?php
print "hello world";
print ("hello world");
?>
They both work
Just as:
<?php
print "hello world";
print ("hello world");
?>
They both work
Re: php tremote includes need help
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.
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.