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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.