PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #14165 include() needs an example for cross-server http inclusion of <?php?> code.
Submitted:21 Nov 2001 2:38pm UTC Modified: 17 Feb 2004 3:54pm UTC
From:steve at petabit dot com Assigned to:irchtml
Status:Closed Category:Documentation problem
Version:4.0.5 OS:Linux
View/Vote Developer Edit Submission

[21 Nov 2001 2:38pm UTC] steve at petabit dot com
Related to bug 14164:

All workarounds I have tried to pass variable data
back from a remotely include()d or require()d
script have failed.

Arrays and strings don't appear to be passed back in
the include()'s return value, it will only pass back
integers.

If anyone sees another way to do this please help!

I will keep looking and post a followup here and to the
manual if I find a workaround.

Steve Rapaport
[21 Nov 2001 2:46pm UTC] brianlmoon@php.net
Please do not ask the same question twice in the bug system.
[21 Nov 2001 3:47pm UTC] steve at petabit dot com
This is not the same as 14164.

Thanks for the quick response, Brian.
I appreciate that the remote file is
parsed remotely, and so the var spaces
are on different machines.

Here's a rephrase of 14165:
Given that it *is* possible to pass
variable values to a remotely INCLUDE()d file
using GET-style syntax, 
HOW DOES ONE GET ANYTHING BACK?
Include appears only to return a single integer,
at best.

The remotely included file is calling a database
and retrieving values.  How does the calling
file access them?

[21 Nov 2001 3:55pm UTC] bate@php.net
Hi,

what are you means with remote?

include("http://www.mysite.com/phpscript.php");
Dont work. the .php are parsed befor and you cant get
source to your script. If you need content from a 
database so print's it as csv and use the output in your
script.

http://www.php.net/csv

-- Marco

Btw. Ask this type of question on the general or dev mailing list.
[21 Nov 2001 4:35pm UTC] steve at petabit dot com
Dear Brian, Marco et al:
Sorry to be persistent, but I am pretty sure that
my postings have been misunderstood, and the last
reply I just got from Marco confirms it.

I'm hoping once you understand the question, the
"bogus" nature of the question will go away.

According to the php "include()" manual, and
in my own experience, it is perfectly valid to
request that a remote file be executed as php, 
using include() or require().  One need only
compile using "URL fopen wrappers": (manual quotes in [[[ ]]])

[[[If "URL fopen wrappers" are enabled in PHP (which they are in the
default configuration), you can specify the file to be include() ed
using an URL instead of a local pathname. See Remote files and fopen()
for more information.
]]]

It is also possible to pass variables to the include()ed
file:

[[[ If the require() ed file is called via HTTP using the fopen
wrappers, and if the target server interprets the target file as PHP
code, variables may be passed to the require() ed file using an URL
request string as used with HTTP GET. This is not strictly speaking the
same thing as require() ing the file and having it inherit the parent
file's variable scope; the script is actually being run on the remote
server and the result is then being included into the local script. ]]]

SO:
The missing feature/doc is:
How do I get the require()ed file to pass back some string information?

I can't use the HTTP GET-style request string, or even the return()
function
within an include() (because it only returns an integer).

I don't think this is a bogus request, it seems to me to be a logical
extension of the URL request idea.  If it's currently impossible, I'm
looking for a workaround.  

Marco's suggestion to print out the database using cvs doesn't change
anything, since I still can't pass a string back.

Best regards,

Steve Rapaport.

[21 Nov 2001 5:01pm UTC] sniper@php.net
Maybe if you added some example script here (which you think
should work) we might understand what you mean?

And note that include/require don't return anything.
They are language constructs, not functions.

--Jani
[21 Nov 2001 5:32pm UTC] steve at petabit dot com
Okay, there's some simple sample code at bug 14164. 

Basic idea is that I have 2 machines, one public,
one firewalled and non-routed.  The public one should
be able to access the database on the private one, but
nobody else should.

Thanks for the attention!

Steve
[6 Aug 2003 9:09pm UTC] tim at pmedia dot be
Allow me to rephrase Steve's problem described in #14165 again as I'm
experiencing the same trouble.

When including a remote php-file (a php-file on another server) in a
script, that php-file is parsed (if server configured to) which
basically means the script is runned. 

The problem we experience is that the parsed script's return value(s)
defined at the end in a return() statement don't seem to arrive in the
original script. Steve reports only 'integers'. I have seen only a '1',
which is according the docs just the value returned if no return()
statement is used. 

If the 2 scripts are located on the same server, the problem doesn't
show up.
[8 Aug 2003 11:26am UTC] elmicha@php.net
If you use
  include('http://some_server/something.php');
something.php is executed on "some_server". It's impossible to return
strings with "return" from there.

But the output of http://some_server/something.php is included in your
script and executed there. So just make _the output_ of something.php a
valid php script which sets your variables - so you can use these
variables in your local script. E.g.:

<?php  // something.php on the remote server
echo '<?php $return_value = "a string"; ?>';
?>

On the local server:

<?php
  include('http://some_server/something.php');
  echo $return_value;
?>

As the manual explicitly mentions that you can use a return statement to
pass values from the included script, but does not mention that this
doesn't work via HTTP or FTP, I'd say this is a Documentation problem.
(I don't know what the manual said in 2001, maybe the return statement
could not be used in included files back then.)
[11 Jan 2004 9:27pm UTC] kennyt@php.net
It really doesn't imply anywhere that including a remote file will make
it inherit the scope -- in fact, it says that is not the case -- and the
'include' documentation explains that the data returned will be parsed
as is any included file. That is, if the page were "<?php echo '<?php
$foo = \'bar\';'; ?>", the calling script would execute that assignment
in its local scope. If you'd write a better explanation, I'll be happy
to commit it. But since you probably don't care anymore... :-)
[12 Jan 2004 12:25pm UTC] steve at petabit dot com
elmicha below has answered my question perfectly well and explained the
results I got too.

To my mind, this docbug should  be considered closed when elmicha's
explanation is included in the docs for include().

Thanks to all who replied,

Steve Rapaport
Steve at Petabit dot com
[17 Feb 2004 12:36pm UTC] irchtml@php.net
I believe the include() documentation is pretty clear on this issue:

"The include() statement includes and evaluates the specified file."

"When a file is included, the code it contains inherits the variable
scope of the line on which the include occurs. Any variables available
at that line in the calling file will be available within the called
file, from that point forward."

Status -> Closed.
[17 Feb 2004 3:02pm UTC] steve at petabit dot com
irchtml@php.net  you are an arrogant bastard aren't you?

If six people over 16 months have had to debate what an oversimplified
paragraph means, don't you think that "pretty clear" might not be an
appropriate way to describe said oversimplified paragraph?

Just because it's clear to you, doesn't make it clear.  In my case, the
only clear explanation I've seen is that from elmicha#phpdotnet earlier
in this thread.  

Tim and kenny have both seen that there's missing clarity with respect
to remote servers, and tried to understand and explain the implications
of your "perfectly clear" paragraph.

But those who have been concerned with trying to make themselves feel
smart (like you), or with trying to make me feel stupid for asking (like
brianlmoon), rather than actually thinking about the problem, simply
make me sad for the entire group of geeks to which I once belonged.  I
hope you're all replaced by low-paid Indian and Chinese programmers and
have to flip "pretty clear" hamburgers for a living.  

Have I been "pretty clear"?  Call me, you supercilious geek, and I'll
happily tell you off in person.

Steve Rapaport
Stockholm, Sweden
+46 70 643 9944
[17 Feb 2004 3:13pm UTC] irchtml@php.net
I'll be more than happy to add a note in the documentation.  Perhaps I
did overlook the fact that it needs more clarification, but that does
not warrant a personal attack.

Thanks for your report.
[17 Feb 2004 3:54pm UTC] irchtml@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation
better.

[7 Jun 2004 8:55am UTC] hobocat at hotmail dot com
The exact same script that works just fine using a domain name will fail
if I call the same file using the IP address of the same server?

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC