Page 1 of 1

[SOLVED] remote include + passing back information

Posted: Tue Jul 13, 2004 8:25 am
by tomek
two servers: A and B
local.php runs on server A
remote.php runs on server B

I need to invoke romote.php from within local.php and I need to pass back information from remote.php to local.php

local.php on server A:

Code: Select all

<?php

$var_local = include 'http://www.serverb.com/folder/remote.php';

echo $var_local;

?>
remote.php on server B:

Code: Select all

<?php

$var_remote = 'test';

return $var_remote;

?>
local.php should output: test
but instead it outputs: 1
(the 1 simply indicates that the include was successfull)

here's the php documentation: http://www.php.net/manual/en/function.include.php
Handling Returns: It is possible to execute a return() statement inside an included file in order to terminate processing in that file and return to the script which called it. Also, it's possible to return values from included files. You can take the value of the include call as you would a normal function. This is not, however, possible when including remote files unless the output of the remote file has valid PHP start and end tags (as with any local file). You can declare the needed variables within those tags and they will be introduced at whichever point the file was included.
so it should work I think...

I also tried:

local.php on server A:

Code: Select all

<?php

include 'http://www.serverb.com/folder/remote.php';

echo $var_remote;

?>
server A and B are both Linux with php > 4.3 and both have allow_url_fopen 'on'

what's wrong - or do you know another way to pass information back to local.php ?

thank you!

Posted: Tue Jul 13, 2004 9:35 am
by kettle_drum
Use another file function to get the page such as fopen(), file_get_contents(), file() or readfile().

Posted: Tue Jul 13, 2004 9:52 am
by tomek
what I want to do is something like a remote procedure call

Posted: Tue Jul 13, 2004 10:10 am
by tomek
problem solved thanks!!!