FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Logic behind this?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Logic behind this? [message #171527 is a reply to message #171522] Fri, 07 January 2011 17:18 Go to previous message
Helmut Chang is currently offline  Helmut Chang
Messages: 22
Registered: September 2010
Karma:
Junior Member
Am 07.01.2011 15:17, schrieb Modafanil:

> Okay, I've had a good look at the PHP manual as suggested, and my needs
> appear less complex than originally thought. It seems I can customise the
> behavior of local included scripts, and pass them parameters, simply by
> setting some variable values. Variables that are in scope within the parent
> script at the point of child inclusion, are also visible in the outer-most
> division of scope within the included PHP script. I set $message = 'this'
> and then include the sub-script, and can then read $message anywhere outside
> of functions in the included file.

And also the other way round. Any varibale, set in the included script
in global scope, is also available afterwards in the script, that included.

Simply said: an include works like as if the content of the included
file replaces the include statement:

scriptA.php:

<?php
$var1 = 'Foo';
include 'scriptB.php';
var_dump($var2);
?>

scriptB.php:

<?php
var_dump($var1);
$var2 = 'Bar';
?>

becomes to:

<?php
$var1 = 'Foo';
// Here's the content of scriptB.php
var_dump($var1);
$var2 = 'Bar';

var_dump($var2);
?>

> Including either local or remote PHP script files with a HTTP request looks
> interesting. It appears that any query string pairs that you append to the
> inclusion URI, become available as local variables within the included
> script. That makes sense, as the $_GET and $_SERVER superglobals are then
> preserved, and not clobbered by any sub-script inclusion.

I'm not sure, what you mean... But it doesn't make sense to me: The
$_GET, $_POST, $_SERVER, etc. superglobals shouldn't be manipulated by
the script, they should only be read, And of course they should be
available in the whole scope of the running script (which include includes).

> I'm a little confused about how inclusion of remotely located PHP scripts
> works, though.

It works in that way, that PHP acts as an HTTP client in this case: PHP
makes a GET-request(and therefore, of course the $_GET-parameters are
available to the included script) to the HTTP server for the specified
URL and replaces the include-statement with the *response* of the
server. And that's the important point:

In this case, you don't include the script, just the output of it, sent
back by the server!

You could include any type of ressource, reachable via HTTP this way.
But you always will get only the response of the server. And that's the
cause, why your above statement about remote file inclusion doesn't make
much sense to me.

HTH, Helmut
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: the changeover to mysqli
Next Topic: [urgent] need solution of Questions, in context of PHP5
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 15:08:30 GMT 2024

Total time taken to generate the page: 0.03865 seconds