Sithu
Sithu

Reputation: 4862

Calling included remote functions and variables

I'm trying to include a remote file from one of LAN pcs using include, allow_url_fopen = On and allow_url_include = On.

One local PC (let's say pc2), I have remote.php, which contains:

<?php
echo $var_on_pc1; // this doesn't output
$remote_var = 'Var on pc2';

function square($num){ 
    return $num * $num;
}    
?>

In my PC (let's say pc1), I have test.php, which consists of this:

<?php
$var_on_pc1 = 'Var on pc1'; 

include "http://pc2/path/to/remote.php";

echo $remote_var; // this doesn't output
echo square(4); // this got error
?>

When I run the script test.php, i got the error:

"Fatal error: Call to undefined function: square() in path/to/test.php on line 7.

What happened? I thought I could call the included functions and variables and vice versa?
If I cannot implement this, what is the best way?

I have no security concern because I use this locally for temporary development.

Upvotes: 0

Views: 44

Answers (1)

deceze
deceze

Reputation: 522636

Type http://pc2/path/to/remote.php into your browser and see what you get. PHP gets exactly the same.

If the PHP file is being processed by the web server at pc2, you likely get zilch in that file, because the code as been processed. You'd need to configure the other server to not process the PHP file and serve its raw source code instead.

This is not a good idea overall.

Upvotes: 4

Related Questions