Bluehost.com Web Hosting $6.95

include-problem

This is a discussion on include-problem within the PHP General forums, part of the PHP Programming Forums category; Hi! I'm having a problem with including files. What I want to achieve is to execute a PHP-script ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-01-2003
Victor spång arthursson
 
Posts: n/a
Default include-problem

Hi!

I'm having a problem with including files. What I want to achieve is to
execute a PHP-script on another server, and then to include the result
(which will be XML-output) in another PHP-script (currently on my local
computer).

On the server I have the file http://server.com/test/echo.php with the
content

---
<?php
echo 'xyz';
?>
---

Locally I've a file with the following content:

---
<?php
echo "!!!";
include ("http://server.com/test/echo.php");
echo "???";
?>
---

I was expecting the output from my locally testfile to be something
like:

---
!!!???
---

but rather it is

---
!!!xyz???
---

I've also tried with a $fp = readfile("http…") with the same result,
which is output of the echo-statement in the remote file which I am
expecting to be evaluated remotely.

How can I do to include the PHP-script and have it to be ran before it
is included?

Sincerely

Victor
Reply With Quote
  #2 (permalink)  
Old 12-01-2003
Sophie Mattoug
 
Posts: n/a
Default Re: [PHP] include-problem

Victor Spång Arthursson wrote:

> Hi!
>
> I'm having a problem with including files. What I want to achieve is
> to execute a PHP-script on another server, and then to include the
> result (which will be XML-output) in another PHP-script (currently on
> my local computer).
>
> On the server I have the file http://server.com/test/echo.php with the
> content
>
> ---
> <?php
> echo 'xyz';
> ?>
> ---
>
> Locally I've a file with the following content:
>
> ---
> <?php
> echo "!!!";
> include ("http://server.com/test/echo.php");
> echo "???";
> ?>
> ---
>
> I was expecting the output from my locally testfile to be something like:
>
> ---
> !!!???
> ---
>
> but rather it is
>
> ---
> !!!xyz???
> ---
>
> I've also tried with a $fp = readfile("http…") with the same result,
> which is output of the echo-statement in the remote file which I am
> expecting to be evaluated remotely.
>
> How can I do to include the PHP-script and have it to be ran before it
> is included?
>
> Sincerely
>
> Victor



This is a perfectly normal behaviour ! See www.php.net/include to
understand what this function does. (comparing to www.php.net/require)

Hope this helps,

--
Cordialement,
---------------------------
Sophie Mattoug
Développement web dynamique
sophie@mattoug.net
---------------------------
Reply With Quote
  #3 (permalink)  
Old 12-01-2003
Rasmus Lerdorf
 
Posts: n/a
Default Re: [PHP] include-problem

On Mon, 1 Dec 2003, Sophie Mattoug wrote:
> Victor Spång Arthursson wrote:
>
> > Hi!
> >
> > I'm having a problem with including files. What I want to achieve is
> > to execute a PHP-script on another server, and then to include the
> > result (which will be XML-output) in another PHP-script (currently on
> > my local computer).
> >
> > On the server I have the file http://server.com/test/echo.php with the
> > content
> >
> > ---
> > <?php
> > echo 'xyz';
> > ?>
> > ---
> >
> > Locally I've a file with the following content:
> >
> > ---
> > <?php
> > echo "!!!";
> > include ("http://server.com/test/echo.php");
> > echo "???";
> > ?>
> > ---
> >
> > I was expecting the output from my locally testfile to be something like:
> >
> > ---
> > !!!???
> > ---
> >
> > but rather it is
> >
> > ---
> > !!!xyz???
> > ---
> >
> > I've also tried with a $fp = readfile("http…") with the same result,
> > which is output of the echo-statement in the remote file which I am
> > expecting to be evaluated remotely.
> >
> > How can I do to include the PHP-script and have it to be ran before it
> > is included?
> >
> > Sincerely
> >
> > Victor

>
>
> This is a perfectly normal behaviour ! See www.php.net/include to
> understand what this function does. (comparing to www.php.net/require)


It's perfectly normal, yes, but it has nothing to do with include vs.
require.

I guess I don't really understand the question. I assume you realize that
an include 'http://server.com/file.php' is going to send an HTTP request
to server.com asking for file.php and if server.com is configured to
execute php for file.php then what will come back across the wire is the
result of php running the script in file.php. As such, when you do:

echo '!!!';
include 'http://server.com/file.php';
echo '???';

you will of course see: !!!xyz??? because that is exactly what you have
asked it to do. Print !!!, then send an HTTP request to server.com and
include the output of that script right here, and finally print out ???.
So I don't understand why this output is surprising you and I don't
understand your question about expecting it to be evaluated remotely.
file.php was of course evaluated remotely on server.com. If file.php had
written something to the filesysts, for example, then that something would
be on server.com not on your server.

-Rasmus
Reply With Quote
  #4 (permalink)  
Old 12-01-2003
Wouter Van Vliet
 
Posts: n/a
Default RE: [PHP] include-problem

Rasmus Lerdorf wrote:
> On Mon, 1 Dec 2003, Sophie Mattoug wrote:
>> Victor Spång Arthursson wrote:
>>
>>> Hi!
>>>
>>> I'm having a problem with including files. What I want to achieve is
>>> to execute a PHP-script on another server, and then to include the
>>> result (which will be XML-output) in another PHP-script (currently
>>> on my local computer).
>>>
>>> On the server I have the file

> http://server.com/test/echo.php with
>>> the content
>>>
>>> ---
>>> <?php
>>> echo 'xyz';
>>>>
>>> ---
>>>
>>> Locally I've a file with the following content:
>>>
>>> ---
>>> <?php
>>> echo "!!!";
>>> include ("http://server.com/test/echo.php");
>>> echo "???";
>>>>
>>> ---
>>>
>>> I was expecting the output from my locally testfile to be something
>>> like:
>>>
>>> ---
>>> !!!???
>>> ---
>>>
>>> but rather it is
>>>
>>> ---
>>> !!!xyz???
>>> ---
>>>
>>> I've also tried with a $fp = readfile("http…") with the same result,
>>> which is output of the echo-statement in the remote file which I am
>>> expecting to be evaluated remotely.
>>>
>>> How can I do to include the PHP-script and have it to be ran before
>>> it is included?
>>>
>>> Sincerely
>>>
>>> Victor

>>
>>
>> This is a perfectly normal behaviour ! See www.php.net/include to
>> understand what this function does. (comparing to
>> www.php.net/require)

>
> It's perfectly normal, yes, but it has nothing to do with include vs.
> require.
>
> I guess I don't really understand the question. I assume you
> realize that an include 'http://server.com/file.php' is going
> to send an HTTP request to server.com asking for file.php and
> if server.com is configured to execute php for file.php then
> what will come back across the wire is the result of php
> running the script in file.php. As such, when you do:
>
> echo '!!!';
> include 'http://server.com/file.php';
> echo '???';
>
> you will of course see: !!!xyz??? because that is exactly
> what you have asked it to do. Print !!!, then send an HTTP
> request to server.com and include the output of that script
> right here, and finally print out ???.
> So I don't understand why this output is surprising you and I
> don't understand your question about expecting it to be
> evaluated remotely.
> file.php was of course evaluated remotely on server.com. If
> file.php had written something to the filesysts, for example,
> then that something would be on server.com not on your server.
>
> -Rasmus


You can use the output buffer functions to catch the "xyz" into a var:

<?php
print "!!!";
ob_start();
include 'http://server.com/test/echo.php';
$XML = ob_get_clean(); // or use ob_get_contents(); and ob_end_clean() for
PHP < 4.3
print "???";

print '[Between this you'll get your XYZ]';
print $XML;
print '[Between this you'll get your XYZ]';
?>

Hope it helps ya,
Wouter
Reply With Quote
  #5 (permalink)  
Old 12-01-2003
Rasmus Lerdorf
 
Posts: n/a
Default RE: [PHP] include-problem

On Mon, 1 Dec 2003, Wouter van Vliet wrote:
> <?php
> print "!!!";
> ob_start();
> include 'http://server.com/test/echo.php';
> $XML = ob_get_clean(); // or use ob_get_contents(); and ob_end_clean() for
> PHP < 4.3
> print "???";
>
> print '[Between this you'll get your XYZ]';
> print $XML;
> print '[Between this you'll get your XYZ]';
> ?>


Or just use file_get_contents() which would be more efficient than using
output buffering for this.

-Rasmus
Reply With Quote
  #6 (permalink)  
Old 12-02-2003
Wouter Van Vliet
 
Posts: n/a
Default RE: [PHP] include-problem

On maandag 1 december 2003 15:23 Rasmus Lerdorf told the butterflies:
> On Mon, 1 Dec 2003, Wouter van Vliet wrote:
> > <?php
> > print "!!!";
> > ob_start();
> > include 'http://server.com/test/echo.php';
> > $XML = ob_get_clean(); // or use ob_get_contents(); and
> > ob_end_clean() for PHP < 4.3 print "???";
> >
> > print '[Between this you'll get your XYZ]'; print $XML; print
> > '[Between this you'll get your XYZ]'; ?>

>
> Or just use file_get_contents() which would be more efficient
> than using output buffering for this.
>
> -Rasmus


yes, probably. But isn't file_get_contents(); only implemented from php4.3
... might wanna try

join('', file());

or

$fd = fopen($FileName, 'r');
fread($fd, filesize($fd));

if you're running an older version.

-me.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:08 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0