[SOLVED] remote include + passing back information

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomek
Forum Newbie
Posts: 5
Joined: Mon Jul 12, 2004 3:51 pm

[SOLVED] remote include + passing back information

Post 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!
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Use another file function to get the page such as fopen(), file_get_contents(), file() or readfile().
tomek
Forum Newbie
Posts: 5
Joined: Mon Jul 12, 2004 3:51 pm

Post by tomek »

what I want to do is something like a remote procedure call
tomek
Forum Newbie
Posts: 5
Joined: Mon Jul 12, 2004 3:51 pm

Post by tomek »

problem solved thanks!!!
Post Reply