php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #18000 localized http header request includes variable scope
Submitted: 2002-06-26 14:17 UTC Modified: 2002-06-26 16:06 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: code at 4arrow dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.1.2 OS: UNIX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
15 + 28 = ?
Subscribe to this entry?

 
 [2002-06-26 14:17 UTC] code at 4arrow dot com
A PHP file that includes a local file via a HTTP header request usign the full and absolute local URL (http and domain) is seen as a local call from with the server and treated as a separate session and PHP parser run from the existing PHP run that the include is beign requested within.

This changes the $_SERVER['REMOTE_ADDR'] variant to the $_SERVER['SERVER_ADDR'] variant which is technically accurate but practically useless.

Also all exisitng sessions or cookies are no longer available to the included local file because calling it via a absolute URI caused a http header request which I suppose creates a new session and extraneous server load. How about viewing absolute URIs in their context, if they are on the same domain/server to bear that in mind for the benefit of the developer?

Now, I understand the need for a unique header request to reset new env variables but at the same time options are a good thing. How about both? A full URI can call both a local php file that retains the variables scope of its parent as well as one that doesn't or even better yet a new unique version prefix is added to the new HTTP header request and its created env variables and it is not viewed in isolation but as a part of an existing process. 

The request feature is to be able to call a absolute URL http://4arrow.com/test/test/php within an existing PHP script both on the same domain name and server name that has access to all the preset variables above it as well as unique variables within as a new unique HTTP request, lastly after it all variables from before it are also still available.

Basically to retain the variable scope across absolute HTTP requests within local scripts that call local uris.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-26 14:31 UTC] rasmus@php.net
This made absolutely no sense to me.  If someone else can make sense of this, feel free to unbogus it.

What in the world do you mean by, "A PHP file that includes a local file via a HTTP header request" ?

As in header('Location: http://local.domain/file.php') ?

That is a client-side redirect which means the remote browser is going to make a completely separate request which may or may not come back to the same process or even the same physical server in a load-balanced architecture.  Expecting any sort of variable persistency across client-side redirects is rather silly.  This is what sessions are for.
 [2002-06-26 14:38 UTC] code at 4arrow dot com
Rasmus the HTTP header request is used in all PHP methods that request a file with a HTTP or full LINK even if it is local.

Such as fopen(), file(), readfile(), include, require, include_once, require_once. All of these can include files with a absolute URI.

FYI, Sessions don't persist from one http session to another even inside the same domain when one file is included within another via a absolute url.
 [2002-06-26 14:48 UTC] rasmus@php.net
I don't understand why you call this a header http request, but whatever.  So you want 
include 'http://local.domain/file.php'
to act like
include 'file.php'
if local.domain happens to be the a local domain?  Seems to me like this is something that you should be checking at the application level.  Why use a url when the file is local?  We could add a check, but it would add extra dns calls to every url file operation and I don't think it is worth it.
 [2002-06-26 14:50 UTC] rasmus@php.net
Oh, and to get your sessions to persist across a url file open, simply pass your SID along.
 [2002-06-26 15:00 UTC] code at 4arrow dot com
You're right about the additional load it would add and yes you can pass variables via the Query string.

For me the feature request is more technical in nature than cosmetic patches will cover.

When you execute a script and during its run I include'http://samedomain/file.php' There are limitations of scope that are placed on the included local file in comparison to its parent file which to me seems unecessary.

This ruins the code flow for me, practically and mentally.

I wonder if this is part of the child process limitation in PHP?
 [2002-06-26 15:03 UTC] rasmus@php.net
But you still haven't answered why you are doing:
include 'http://samedomain/file.php';
This makes no sense to me.  Why go through HTTP when the file is local?

 [2002-06-26 15:15 UTC] code at 4arrow dot com
Specifically, for me as I said it is about code flow and options.

Really as simple as that. Having the ability to include a file with its full URI that makes a new header request without losing variable scope (locally) of the previous header request it is inside of would be beneficial to me and my php development by allowing me to gain more freedom and options.

Options I think is the key word that this would create for me. Variables give me options losing them in middle of a run takes away my options.

If there were to be any considertion for something like this, I would suggest a PREFIX optional argument that would prepend the newly created ENV variables from the new and second header request within the same domain.

Maybe you're not clear on what I am suggesting.

I am requesting the ability to include a full URL and a new header request within an existing header request on the same domain, same script execution run, that enables me to have two or more sets of unique and shared variables without losing variable scope.
 [2002-06-26 15:25 UTC] rasmus@php.net
Oh, I understand what you are asking for, it just still makes absolutely no sense to me.  Why would you incur the overhead of an unneccesary HTTP request just for code flow?  Wrap your include function yourself then.

function my_include($url) {
    $a = parse_url($url);
    if($a['host'] == $_SERVER['SERVER_NAME'] {
        $file = $_SERVER['DOCUMENT_ROOT'].$a['path'];
    } else $file = $url;
    include $file;
}

my_include('http://localdomain/file.php');

That's all.  Building this into PHP doesn't make any sense to me.
 [2002-06-26 15:33 UTC] code at 4arrow dot com
Its just a feature request not a direct order.

The feature request is not how to do includes but rather how to maintain the integrity of variable scopes when including a new http header request (while wanting all those new variables) inside an existing header request (while maintaining all those existing variables into the new header request).

This is not something you can code hack to replicate it is an intrinsic sub request or child process that would establish user defined optional prefix based env variable differentials.
 [2002-06-26 16:06 UTC] rasmus@php.net
But if you turn the include into a normal file-system based include as I illustrated in my_include() then variables are maintained.  Locally included files share the same scope as the script doing the inclusion.  I see no use for what you are asking for, sorry.
 [2002-06-26 16:14 UTC] code at 4arrow dot com
No biggie, I was planning on porting my development to Zope eventually anyways.

Thanks for your attention to detail and quick responses.
 [2002-06-26 19:28 UTC] norny at yahoo dot com
I agree with rasmus not to build it into php.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 09:01:31 2024 UTC