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

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
nickspick
Forum Newbie
Posts: 7
Joined: Fri Oct 08, 2004 6:34 am
Location: Brighton, UK

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

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
nickspick
Forum Newbie
Posts: 7
Joined: Fri Oct 08, 2004 6:34 am
Location: Brighton, UK

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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?
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post 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
nickspick
Forum Newbie
Posts: 7
Joined: Fri Oct 08, 2004 6:34 am
Location: Brighton, UK

Post 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
nickspick
Forum Newbie
Posts: 7
Joined: Fri Oct 08, 2004 6:34 am
Location: Brighton, UK

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

meaby time for the OP to lookup what webservices are ;)
Post Reply