472,951 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

Is it possible to return a value other than true or false via an include over HTTP?

REFERENCE:
http://us4.php.net/manual/en/function.include.php
Example 16-7. include() through HTTP
Example 16-10. include() and the return() statement

--------------------
return.php
--------------------
<?php

$var = 'PHP';

return $var;

?>

--------------------
noreturn.php
--------------------
<?php

$var = 'PHP';

?>

--------------------
testreturns.php
--------------------
<?php

$foo = include 'http://www.domainwhatever.com/return.php';

echo $foo; // should print 'PHP', but only prints 1

$bar = include 'http://www.domainwhatever.com/noreturn.php';

echo $bar; // prints 1

?>
--------------------

So, is it possible to return a value other than true or false via an
include over HTTP? If not, is there another method of returning a value
from a remote PHP file or function? Thanks.

Jul 17 '05 #1
5 2101
Aeon Twilight wrote:
So, is it possible to return a value other than true or false via an
include over HTTP? If not, is there another method of returning a
value from a remote PHP file or function? Thanks.


Two things to remember here:

1. The allow_url_fopen directive should be enabled in the php.ini file
2. The remote code is parsed on the remote server before it's returned.

So, when the remote file prints "hello", you will see this as the output.
However, a return statement results in nothing when parsed on the remote
server. Only when used locally, you will able to store something in a
variable.

BTW, the integer is returned by the include construct to indicate success or
failure. With output buffering you can capture the output of the included
remote file in a variable without this indication:

ob_start();
include "http://...";
$content = ob_get_contents();
ob_end_clean();

print $content;
JW
Jul 17 '05 #2
Have you considered using SOAP? It seems like a better method of
RPC'ing over the web rather than your current methodology.

check out the Pear SOAP package: http://pear.php.net/package/SOAP

Jul 17 '05 #3
NC
Aeon Twilight wrote:

--------------------
return.php
--------------------
<?php
$var = 'PHP';
return $var;
?>

--------------------
noreturn.php
--------------------
<?php
$var = 'PHP';
?>

--------------------
testreturns.php
--------------------
<?php
$foo = include 'http://www.domainwhatever.com/return.php';
echo $foo; // should print 'PHP', but only prints 1
$bar = include 'http://www.domainwhatever.com/noreturn.php';
echo $bar; // prints 1
?>
--------------------

So, is it possible to return a value other than true or false
via an include over HTTP?


Why do you need to return anything? All variables in the
included code become available in the including code after
the include(). So you can simply write:

include 'http://www.domainwhatever.com/return.php';
echo $var; // should print 'PHP'

Cheers,
NC

Jul 17 '05 #4
NC (nc@iname.com) wrote:
: Aeon Twilight wrote:
: >
: > --------------------
: > return.php
: > --------------------
: > <?php
: > $var = 'PHP';
: > return $var;
: > ?>
: >
: > --------------------
: > noreturn.php
: > --------------------
: > <?php
: > $var = 'PHP';
: > ?>
: >
: > --------------------
: > testreturns.php
: > --------------------
: > <?php
: > $foo = include 'http://www.domainwhatever.com/return.php';
: > echo $foo; // should print 'PHP', but only prints 1
: > $bar = include 'http://www.domainwhatever.com/noreturn.php';
: > echo $bar; // prints 1
: > ?>
: > --------------------
: >
: > So, is it possible to return a value other than true or false
: > via an include over HTTP?

: Why do you need to return anything?

Perhaps just because the manual says you can?

However, http://us4.php.net/include/ says "[1] This is not, however,
possible when including remote files [2] 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. "

To me that's not clear whether section [2] means you can do it as long as
you output the tags, or whether section [2] says you can't but there is a
workaround, which it then descibes. (and which is also mentioned below).

You could try "echo'ing" the <?php and ?> tags to see if that changes
anything. something like
<?php echo '<?php'; $var='XXX'; echo '?>' ?> though if it works at
all then you may have to play with some combinations of syntax to find the
one that works (assuming it works at all).

All variables in the
: included code become available in the including code after
: the include(). So you can simply write:

: include 'http://www.domainwhatever.com/return.php';
: echo $var; // should print 'PHP'

: Cheers,
: NC
--

This space not for rent.
Jul 17 '05 #5
"Aeon Twilight" <rb**********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
REFERENCE:
http://us4.php.net/manual/en/function.include.php
Example 16-7. include() through HTTP
Example 16-10. include() and the return() statement

--------------------
return.php
--------------------
<?php

$var = 'PHP';

return $var;

?>

--------------------
noreturn.php
--------------------
<?php

$var = 'PHP';

?>

--------------------
testreturns.php
--------------------
<?php

$foo = include 'http://www.domainwhatever.com/return.php';

echo $foo; // should print 'PHP', but only prints 1

$bar = include 'http://www.domainwhatever.com/noreturn.php';

echo $bar; // prints 1

?>
--------------------

So, is it possible to return a value other than true or false via an
include over HTTP? If not, is there another method of returning a value
from a remote PHP file or function? Thanks.


Exactly what are you trying to accomplish here? Your approach is probably
flawed, as there is no valid reason to include an URL for most intents and
purposes.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Fabri | last post by:
Is it possible, as IE does in Windows Update, to ask onbeforeunload if the user want really close window (or tab) clicking on close (X) of the window? This window isn't opened by window.open....
0
by: dag | last post by:
Hi! I would like to do an overlap window, over my main window (of my application), with a Progress Bar. Exactly when I push a button of my application I want show a window, with a Progress bar,...
24
by: trint | last post by:
add them into one PrintDocument: PrintDocument pd1 = new PrintDocument(); PrintDocument pd2 = new PrintDocument(); PrintDocument pdCombined = new PrintDocument(); pdCombined = pd1 + pd2;...
10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
8
by: Jordi Rico | last post by:
Hi, I've made the next inherited class in Visual Studio 2005: Public Class LabelEx Inherits System.Windows.Forms.Label Sub New() MyBase.New() Me.ForeColor = Color.Black Me.AutoSize = False...
7
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function...
2
by: sbettadpur | last post by:
Hi everybody, Hi iam strugling with more than one submit buttons with in one form here is my code <form method="post" action="Offer.php" name='issueFrm' onSubmit="return fullOfferfields();">...
9
by: igor.tatarinov | last post by:
Hi, I am pretty new to Python and trying to use it for a relatively simple problem of loading a 5 million line text file and converting it into a few binary files. The text file has a fixed format...
6
by: tgnelson85 | last post by:
Hello, C question here (running on Linux, though there should be no platform specific code). After reading through a few examples, and following one in a book, for linked lists i thought i would...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.