Jump to content

Getting a variable back from an include on a remote server


Longlands

Recommended Posts

I have a script that needs to run a routine on a different server. The reason is so that I can update that small part of the code without users needing to install a script upgrade every so often.

 

It is easy enough to pass variables to the remote script:

 

include 'http://www.remotedomain.com/script.php?var=$var

 

The remote script calculates and creates an array, but try as I might, I haven't been able to get it to send the array back. I've tried using return($x); in accordance with what I've read in the PHP Manual, but it didn't seem to work.

 

Is this even possible?

 

Martin

 

Including a remote file is the same as browsing to it. You only get any output that is echoed. Using return() in an include file only has meaning if that file is included locally.

 

To get an array from the remote server would either require you to output "raw" php code, including the surrounding <?php and ?> tags  that sets the values in an array or to serialize the array, output the serialized string, capture it on the local server, and un-serialize it.

 

Edit: Using file_get_contents() instead of include() would make using the serialize/un-serialize method easier and safer.

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.