Ok , so i have a.php on server #1 and b.php on server #2
let say that a.php contains :
<?php
$google = 'www.google.com';
?>
and b.php contains :
<?php
require('http://[server #1]/a.php');
echo $google;
?>
basically that won't work , how to make it work without editing php.ini ? :D
Using JSON, read the global variables and export them as a JSON string, the extract() is then used on the reciving side to restore the variables into the global scope.
config.php on server A
// Define your Variables
$google = 'www.google.com';
$string = 'foobar';
$int = 1;
$bool = true;
// JSON Export
echo json_encode(array_diff_key(get_defined_vars(),array_flip(array('_GET','_POST','_COOKIE','_FILES','_ENV','_REQUEST','_SERVER'))));
application.php on server B
// JSON Import
extract(json_decode(file_get_contents('http://www.domain.com/config.php'),true));
// Now test your Variables
var_dump($google); // Now the $google variable exists
var_dump($string);
var_dump($int);
var_dump($bool);
You can invent your own security mechanism into this code to suit your requirements. I would much prefer you consume a specific list of variables on both the transmit and receive end, this method of using get_defined_vars() and extract() is not ideal, but since you're targeting a specific URL that you're in control of your risk is minimized.
You simply can't access the source code of a remote php file on a different server. The best method would be to create an API sort of thing (set up a special key):
$secretkey = "stackoverflow";
if(isset($_GET['secretkey']) && $_GET['secretkey'] == $secretkey){
$google = "www.google.com";
//Either if a specific string is requested, then reveal that:
if(isset($_GET['req'])){
$request = $_GET['req'];
//reveal the value of string Google
if($request == "google"){
echo $google;
}
}else{
//Or reveal the whole source code if there is no specific request
show_source(__file__);
}
}else{
die("Access denied.");
}