Include via http

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
UndpUndo
Forum Newbie
Posts: 7
Joined: Fri Sep 16, 2005 3:42 am
Location: UK

Include via http

Post by UndpUndo »

Hi,

I'm trying to include a file via http. The remote file is querying a db on the remote server and returning the results.I am then trying to get the result assigned to a vairiable and use it within my local script.

I can echo out the results in the remote file [ the echo is in the remote file] and this works fine, however i want to return a variable that holds the output. When i do this I only get '1' returned even when i test a very simple file??

here is some code

remotefile.php
<?php

$myVar = 'test return value';

return $myVar;

?>

local script:
<?php

$myResult = include' http://www.otherdomain.com/remotefile.php';

echo $myResult;

?>

the echo in the last script always returns 1??

any ideas?

thanks
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

include as you can see in the PHP manual it evaluates a PHP doc and includes into the current file.
it does not read the contents into any variable.
you should consider using file_get_contents() or file();
read posting rules for using appropriate tags to wrap your code.
UndpUndo
Forum Newbie
Posts: 7
Joined: Fri Sep 16, 2005 3:42 am
Location: UK

Post by UndpUndo »

thanks,

the problem i have is that i need to query the db on the remote server and return the results.

will get file_get_contents() of file allow me to do that?
UndpUndo
Forum Newbie
Posts: 7
Joined: Fri Sep 16, 2005 3:42 am
Location: UK

Post by UndpUndo »

thanxs, raghavan20. that worked a treat!!
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

PHP Manual wrote:

Code: Select all

return.php 
<?php 

$var = 'PHP'; 

return $var; 

?> 

noreturn.php 
<?php 

$var = 'PHP'; 

?> 

testreturns.php 
<?php 

$foo = include 'return.php'; 

echo $foo; // prints 'PHP' 

$bar = include 'noreturn.php'; 

echo $bar; // prints 1 

?>
$bar is the value 1 because the include was successful. Notice the difference between the above examples. The first uses return() within the included file while the other does not.
UndpUndo
Forum Newbie
Posts: 7
Joined: Fri Sep 16, 2005 3:42 am
Location: UK

Post by UndpUndo »

thanks Noob,

but my remote file is already using a return. :)
Post Reply