Page 1 of 1

Can a remote include() return values within a script?

Posted: Fri Oct 08, 2004 6:42 am
by nickspick
I have a script that accesses a page on a remote server using an include(); This remote page returns a value that I want the script to obtain. Is possible to get hold of the value without the remote page having to post it back to the site, ie. so that the value can be used with the same script.

Posted: Fri Oct 08, 2004 7:07 am
by twigletmac
If you are including a page, then any values in that page will be available to the page to which it is included. You would need to know the name of the variable storing the value and then you could use it.

Mac

Posted: Fri Oct 08, 2004 7:27 am
by nickspick
This is true on a local include ie. include("file.php"); but doesn't work if the file is on a remote server, ie. include("http://www.mysite.com/file.php");

The script that called it doesn't seem to be able to get the value

Nick

Posted: Fri Oct 08, 2004 7:39 am
by timvw
could you tell us how you return values by including them??????

the manual only says: The include() statement includes and evaluates the specified file.. but nowhere they talk about returning values?

Posted: Fri Oct 08, 2004 9:35 am
by AGISB
if you include a script you can simply use the variable name in the page that includes the script. You need to return nothing.

Lets say you include following script:

Code: Select all

<?php
$a = 101;
?>
You can then use $a on your page with the value of 101

Posted: Fri Oct 08, 2004 9:43 am
by nickspick
If the remote page contained

Code: Select all

$var="hello";
the following script would display the value of $var on the page:

Code: Select all

include("http://www.mysite.php?page.php");
echo $var;
BUT if you needed to use the value of $var within the local script you can't

Posted: Fri Oct 08, 2004 9:47 am
by nickspick
Sorry, if 'echo $var' was included in the remote script it WOULD display it but where it is it won't as it can't detect the variable in the remote script.

Posted: Fri Oct 08, 2004 10:19 am
by twigletmac
Maybe something like [php_man]CURL[/php_man] would be more appropriate as you can then work with a returned value. include() doesn't seem to offer that functionality with remote files.

Mac

Posted: Fri Oct 08, 2004 10:31 am
by feyd
remote pages would have to show their source code to see any internal variables. include and curl will only see the final rendered output.

Posted: Sat Oct 09, 2004 5:12 am
by twigletmac
curl could work with the output better than include though - I think that's what I were thinking at the time - also assumes that you have access to modify the output of the external file so that you can get the data you need outputted to be parsed .

Mac

Posted: Sat Oct 09, 2004 6:17 am
by timvw
meaby time for the OP to lookup what webservices are ;)