Page 1 of 1

Include via http

Posted: Fri Sep 16, 2005 4:01 am
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

Posted: Fri Sep 16, 2005 4:47 am
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.

Posted: Fri Sep 16, 2005 4:51 am
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?

Posted: Fri Sep 16, 2005 5:01 am
by UndpUndo
thanxs, raghavan20. that worked a treat!!

Posted: Fri Sep 16, 2005 5:08 am
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.

Posted: Fri Sep 16, 2005 5:43 am
by UndpUndo
thanks Noob,

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