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
Switch to threaded view of this topic Create a new topic Submit Reply
Logic behind this? [message #171490] Thu, 06 January 2011 11:11 Go to next message
Modafanil is currently offline  Modafanil
Messages: 2
Registered: January 2011
Karma: 0
Junior Member
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.
Re: Logic behind this? [message #171491 is a reply to message #171490] Thu, 06 January 2011 11:35 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 06-01-11 12:11, Modafanil wrote:
> 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.
>
>
>

Did you look at example#3 on
http://www.php.net/manual/en/function.include.php

It says you can do it, when you specify an URL, and not a filename which
contains question marks.


For consistency, i dont see an advantage of specifying more parameters
to an 'include' or 'require'..

--
Luuk
Re: Logic behind this? [message #171492 is a reply to message #171490] Thu, 06 January 2011 11:54 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Jan 6, 11:11 am, "Modafanil" <inva...@email.com> wrote:
>
> 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?

Good news, you can!

$_SERVER and $_GET are super globals and are thus available in all
included files.
Re: Logic behind this? [message #171493 is a reply to message #171490] Thu, 06 January 2011 12:07 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Modafanil)

> 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'.

Correct.

> Wouldn't PHP be a more consistent language if it were possible to pass query
> strings during file inclusion

This is possible, but only if you include the file with an HTTP request,
which you don't really want (too expensive, too slow and maybe even a
security problem). A normal file include like above doesn't know about
query strings, because there's no server involved to interpret them.

> and then be able to access the parameters as
> maybe $_SERVER['QUERY_STRING'] or $_GET['message'] within the included file?

These superglobals are available everywhere.

Micha
Re: Logic behind this? [message #171494 is a reply to message #171491] Sun, 29 September 2013 16:00 Go to previous message
j80k-vpfc is currently offline  j80k-vpfc
Messages: 10
Registered: September 2013
Karma: 0
Junior Member
In article <v0mgv7-clc(dot)ln1(at)qqqqq(dot)xs4all(dot)nl>, Luuk(at)invalid(dot)lan (Luuk)
wrote:

> *From:* Luuk <Luuk(at)invalid(dot)lan>
> *Date:* Thu, 06 Jan 2011 12:35:30 +0100
>
> On 06-01-11 12:11, Modafanil wrote:
>> 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.
>>
>>
>>
>
> Did you look at example#3 on
> http://www.php.net/manual/en/function.include.php
>
> It says you can do it, when you specify an URL, and not a filename
> which
> contains question marks.
>
>
> For consistency, i dont see an advantage of specifying more
> parameters
> to an 'include' or 'require'..
>
> --
> Luuk
>
I'm not sure what use that is.. do you want to 'include' a chunk of code?
If that's the case, the variables are available without being passed
surely?
Alternatively, are you trying to include the /output/ of another script?

- Steve
Re: Logic behind this? [message #171503 is a reply to message #171491] Thu, 06 January 2011 21:46 Go to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Luuk wrote:
> On 06-01-11 12:11, Modafanil wrote:
>> 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.
>>
>>
>>
>
> Did you look at example#3 on
> http://www.php.net/manual/en/function.include.php
>
> It says you can do it, when you specify an URL, and not a filename which
> contains question marks.
>
>
> For consistency, i dont see an advantage of specifying more parameters
> to an 'include' or 'require'..
>
That is, after all what global variables are for :-)

Or even (gasp) private parameters passed to functions..
Re: Logic behind this? [message #171522 is a reply to message #171490] Fri, 07 January 2011 14:17 Go to previous message
Modafanil is currently offline  Modafanil
Messages: 2
Registered: January 2011
Karma: 0
Junior Member
"Modafanil" <invalid(at)email(dot)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.
Re: Logic behind this? [message #171525 is a reply to message #171522] Fri, 07 January 2011 16:09 Go to previous message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Jan 7, 2:17 pm, "Modafanil" <inva...@email.com> wrote:
> 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.

Only if REGISTER_GLOBALS is set on, which hopefully it isn't since
this is/was one of php's biggest security holes.
Re: Logic behind this? [message #171526 is a reply to message #171522] Fri, 07 January 2011 17:13 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/7/2011 9:17 AM, Modafanil wrote:
> "Modafanil"<invalid(at)email(dot)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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
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: 0
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
Re: Logic behind this? [message #171530 is a reply to message #171526] Fri, 07 January 2011 21:22 Go to previous message
Modafinil is currently offline  Modafinil
Messages: 3
Registered: January 2011
Karma: 0
Junior Member
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.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - 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.
Re: Logic behind this? [message #171531 is a reply to message #171530] Fri, 07 January 2011 21:39 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
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
==================
Re: Logic behind this? [message #171532 is a reply to message #171530] Fri, 07 January 2011 22:49 Go to previous message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Fri, 7 Jan 2011 13:22:25 -0800 (PST), Modafinil wrote:
> On Jan 8, 1:13?am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> 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.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================- Hide quoted text -
>>
>> - 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.

http://php.net/manual/en/function.getopt.php

You can use that to define optional parameters that (can) duplicate what
you'd otherwise have passed on a HTTP request. There's no
"REGISTER_GLOBALS" for this, so you don't even have to get used to it.

And, yeah, you'll want to sanitize the stuff coming in via the options
similar to how you'd sanitize the stuff coming in on a request.

--
The only thing I'd use on guinea-fowl is a shredder. Same with
peacocks. The sound of peacocks being shredded can't possibly be any
worse than the sound of peacocks not being shredded.
-- Tanuki
Re: Logic behind this? [message #171534 is a reply to message #171530] Sat, 08 January 2011 00:54 Go to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On 07/01/11 21:22, Modafinil wrote:

> 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.

assuming the function "functionName" is declared in file "filename":

<?php
require_once (filename);
$result = functionName(functionParams);
?>

is how some php coders might do it, myself included.

Jerry probably does it another way, because anything I'd do always seems
to meet with his disapproval.

Rgds

Denis McMahon
Re: Logic behind this? [message #171535 is a reply to message #171534] Sat, 08 January 2011 01:30 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/7/2011 7:54 PM, Denis McMahon wrote:
> On 07/01/11 21:22, Modafinil wrote:
>
>> 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.
>
> assuming the function "functionName" is declared in file "filename":
>
> <?php
> require_once (filename);
> $result = functionName(functionParams);
> ?>
>
> is how some php coders might do it, myself included.
>
> Jerry probably does it another way, because anything I'd do always seems
> to meet with his disapproval.
>
> Rgds
>
> Denis McMahon

Not at all. I do things according to good programming practices. This
is a good way of doing things.

I don't do things in a stoopid way - like you seem to do so often -
however. Which is why not only I, but any good programmer, will
disagree with you.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Logic behind this? [message #171538 is a reply to message #171532] Sat, 08 January 2011 02:54 Go to previous message
Modafinil is currently offline  Modafinil
Messages: 3
Registered: January 2011
Karma: 0
Junior Member
On Jan 8, 6:49 am, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> On Fri, 7 Jan 2011 13:22:25 -0800 (PST), Modafinil wrote:
>> On Jan 8, 1:13?am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>>> 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.
>
>>> --
>>> ==================
>>> Remove the "x" from my email address
>>> Jerry Stuckle
>>> JDS Computer Training Corp.
>>> jstuck...@attglobal.net
>>> ==================- Hide quoted text -
>
>>> - 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.
>
> http://php.net/manual/en/function.getopt.php
>
> You can use that to define optional parameters that (can) duplicate what
> you'd otherwise have passed on a HTTP request. There's no
> "REGISTER_GLOBALS" for this, so you don't even have to get used to it.
>
> And, yeah, you'll want to sanitize the stuff coming in via the options
> similar to how you'd sanitize the stuff coming in on a request.
>
> - Show quoted text -

Another interesting option for efficiently passing parameters to local
includes, and some valuable extra advice too!

M.
Re: Logic behind this? [message #171539 is a reply to message #171531] Sat, 08 January 2011 03:13 Go to previous message
Modafinil is currently offline  Modafinil
Messages: 3
Registered: January 2011
Karma: 0
Junior Member
On Jan 8, 5:39 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 1/7/2011 4:22 PM, Modafinil wrote:
>
> 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.
>

Sorry, the shortcut part was me thinking that I could append a
querystring to a script name being included from the local filesystem.
That obviously doesn't work unless you're doing a HTTP request, and by
the good advice I've been given, that sounds like something I want to
avoid (and my server won't let me do anyway).

>
> 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.
>

Oops, I checked the register_globals setting on my rented shared
server, and it is turned off. I misunderstood it's purpose, but think
it's to do with stuff that would ordinarily be found in super-globals,
being accessible as ordinary local variables. If I understand
correctly, It's setting doesn't affect visibility of variables in an
included script, that were in scope at the point in the parent where
the child was included.

M.
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Wed Dec 04 08:57:12 GMT 2024

Total time taken to generate the page: 0.26096 seconds