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 #171531 is a reply to message #171530] Fri, 07 January 2011 21:39 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 1/7/2011 4:22 PM, Modafinil wrote:
> On Jan 8, 1:13 am, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> On 1/7/2011 9:17 AM, Modafanil wrote:
>>
>>
>>
>>
>>
>>> "Modafanil"<inva...@email.com> wrote in message
>>> news:EI2dnfk9sY4pPrjQnZ2dnUVZ_sSdnZ2d(at)westnet(dot)com(dot)au...
>>>> I tried to include one PHP file from within another one that is running on
>>>> a webserver:
>>
>>>> require_once('test.php?message=this');
>>
>>>> Without the query string the inclusion works fine. Add the query string,
>>>> however, and the server refuses with 'can't find a matching file or
>>>> directory'.
>>
>>>> Wouldn't PHP be a more consistent language if it were possible to pass
>>>> query strings during file inclusion, and then be able to access the
>>>> parameters as maybe $_SERVER['QUERY_STRING'] or $_GET['message'] within
>>>> the included file?
>>
>>>> I'd be interested to hear from anyone that can rationalise the current
>>>> file inclusion functions' behavior.
>>
>>>> M.
>>
>>> 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.
>>
>>> That then solves the question of why PHP doesn't support passing query
>>> strings to files included from a local filesystem. There's simply no need.
>>
>>> 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 a little confused about how inclusion of remotely located PHP scripts
>>> works, though. I can't seem to grasp which machine the script runs on? I
>>> could do with a few pointers here, as I couldn't seem to follow the manual's
>>> explaination.
>>
>>> M.
>>
>> PHP scripts run on the server, so if you request a PHP script from
>> another server, it will run on the remote. You will get only the output
>> from that script, just as if you were to request it from a browser.
>>
>> But rather than set variables before including the script, check out
>> functions and passing parameters to them. It makes your code much more
>> maintainable and reliable.
>>
>> - Show quoted text -
>
> Yep, wanting to send querystrings to included local PHP files was my
> shortcut to calling included files' functions, and supplying them with
> parameters. Thinking about it, that might be a tidier solution than
> using parent script variables, that appear as globals in the included
> script, as parameter containers. I can't guarantee that
> REGISTER_GLOBALS will always be enabled, though it appears to be on
> the server I'm using, and included file functions may be called more
> than once. It seems you only get one shot at running code in the
> global scope, when executing it by inclusion from a parent script.
>
> M.

It's not a sort cut - it has significant overhead because it makes a
call to the server, requiring the server to initialize another PHP
environment for the new request, process the request and return the
output to the originating script.

This vs. a simple call to the file system to include the new script.

And you do NOT want register_globals to be set - it's a huge security
hole and is being removed altogether in PHP 6. If I were on a server
with it enabled, I'd be looking for another hosting company.

Also, you can include scripts - but they will be executed where they are
included. Functions are so much better in many ways.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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: Thu Nov 28 09:17:14 GMT 2024

Total time taken to generate the page: 0.04185 seconds