Jump to content

How to inlcude php variable from remote file on server A to file on server B


monsterpot

Recommended Posts

I want to be able to include variables which I will set in a master file on a domain on server A and call that php file from many other files on other domains/servers.  I've tried a few methods but can only get the HTML contents of the remote file as the php is parsed first.

 

Tried file_get_contents() and jsut gets the html

Tried this snippet:

 

if (function_exists('curl_init')) {

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url); // where $url is the path to the remote php file

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $content = curl_exec($ch);

    curl_close($ch);

   

    echo "<p>$content</p>"; // echos the html okay, but when I try to echo the variables set in the remote file - blank

}

else echo 'No cURL library!';

 

 

 

I hope that kind of explains the problem - does anyone have any ideas?

A) Doing this will slow down the generation of every page since they have to wait the additional time for the request to get the remote values,

B) Any time the server with the remote values is down, all the other sites will be broken,

C) If you use the http: protocol, anyone who finds your remote site can get the values as well unless you add some security,

D) The second best way to do this would be to use the ftp: protocol to read the file,

E) The best way would be for the master server to ftp the files to the individual servers anytime the values get changed. The individual servers would get the values from their local copy of the file.

Hmmm...

 

I might just update the master file and use

 

$variable = $_GET['variable']; in each remote php file to get the variables via the querystring from the master file.  Just there's a lot of them.

 

I pass other variables that way but only 3 of them.

 

I have many bits of data I want to pass (up to 50) and through the querystring didn't seem the best way.

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.