php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14341 include() html vs file system - variable scope
Submitted: 2001-12-04 14:32 UTC Modified: 2001-12-05 01:28 UTC
From: timneill at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.1.0 OS: FreeBSD
Private report: No CVE-ID: None
 [2001-12-04 14:32 UTC] timneill at hotmail dot com
hi, 

i have discovered a bug relating to the scope of variables surrounding and within include files. 

when i was using a http path for an include command, the include file could only see variables instantiated within the include file. all variables instantiated within the include could not be seen by the page calling the include.

however this was not the case when i used a relative path or absolute path using the file system. for example:

$rootFile = "/accounts/www73038/www/www.art-co-op.net/html";
$rootDir = "http://shell9.vhosting.com/www73038";

include(../../includes/inc_file); //-- works
include($rootFile. "/includes/inc_file); //-- works
include($rootHttp. "/includes/inc_file); //-- fails

i'm not sure whether this is by design (i'm new to php & in the process of reforming my evil microsoft ways). and i could not find mention of it in the documentation. 

if you would like to find more information regarding my server and environment:
http://shell9.vhosting.com/www73038/phpinfo.php

thank you,

tim neill.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-04 14:45 UTC] timneill at hotmail dot com
hi, 

i have discovered a bug relating to the scope of variables surrounding and within include
files. 

when i was using a http path for an include command, the include file could only see
variables instantiated within the include file. all variables instantiated within the
include could not be seen by the page calling the include.

however this was not the case when i used a relative path or absolute path using the file
system. for example:

$rootFile = "/accounts/www73038/www/www.art-co-op.net/html";
$rootDir = "http://shell9.vhosting.com/www73038";

include(../../includes/inc_file); //-- works
include($rootFile. "/includes/inc_file); //-- works
include($rootHttp. "/includes/inc_file); //-- fails

i'm not sure whether this is by design (i'm new to php & in the process of reforming
my evil microsoft ways). and i could not find mention of it in the documentation. 

if you would like to find more information regarding my server and environment:
http://shell9.vhosting.com/www73038/phpinfo.php

thank you,

tim neill.

 [2001-12-04 16:15 UTC] hholzgra@php.net
due to the missing 2nd quote i guess that you do not
include 

  "/includes/inc_file

but some php file with extension .php?

and shell9.vhosting.com is most likely configured
to parse and execute .php files?

so it deliveres 
only the *results* of executing the files in a
subrequest and not the verabtim content of the
requested files

try to rename your include files to something
like .txt or .inc or whatever your server will
deliver 'as is' and everything will work fine





 [2001-12-04 16:19 UTC] timneill at hotmail dot com
nope the missing quote is not it - that is simply a typo on my behalf.

also the summary should read:
include() http vs file system - variable scope

 [2001-12-04 17:32 UTC] hholzgra@php.net
but i still believe your files are parsed by the server
*before* delivery ... or can you prove the opposite?
 [2001-12-04 17:58 UTC] timneill at hotmail dot com
ok i created a directory on my server called test:

it contains 4 files:
test.php
test_relative.php
test_abs_file.php
test_abs_http.php
readme.txt (this)

this url demonstrates:
http://shell9.vhosting.com/www73038/test/test.php

here is the source code

/*--------------------------------------------------------------------
test.php
--------------------------------------------------------------------*/
<?php

//-- test.php

$rootHttp = "http://shell9.vhosting.com/www73038";
$rootFile = "/accounts/www73038/www/www.art-co-op.net/";

//-- these vars shall be called by the include files:
$top_relative = 1;
$top_abs_file = 1;
$top_abs_http = 1;

//-- relative path
include("test_relative.php");

//-- absolute path - using file system
include($rootFile . "/html/test/test_abs_file.php");

//-- absolute path - using http
include($rootHttp . "/test/test_abs_http.php");

echo("<br>\$inc_relative: $inc_relative");
echo("<br>\$inc_abs_file: $inc_abs_file");
echo("<br>\$inc_abs_http: $inc_abs_http");

?>

/*--------------------------------------------------------------------
test_relative.php
--------------------------------------------------------------------*/
<?php

//-- test_relative.php

$inc_relative = 1;

echo("<br>\$top_relative: $top_relative");

?>

/*--------------------------------------------------------------------
test_abs_file.php
--------------------------------------------------------------------*/
<?php

//-- test_abs_file.php

$inc_abs_file = 1;

echo("<br>\$top_abs_file: $top_abs_file");

?>

/*--------------------------------------------------------------------
test_abs_http.php
--------------------------------------------------------------------*/
<?php

//-- test_abs_http.php

$inc_abs_http = 1;

echo("<br>\$top_abs_http: $top_abs_http");

?>

please see the results for yourself on the above mentioned page. the variables are lost on the http.

it may simply be the hosting provider i have - the phpinfo() command may be seen:
http://shell9.vhosting.com/www73038/phpinfo.php

if i can help in any way - by altering the above mentioned files - to test other scenarios, please notify me and i'd be happy. if you would like my source i can zip it for you and send it over.

thanks very much,

tim.
 [2001-12-05 01:28 UTC] derick@php.net
Change the extention of the file 'include($rootHttp . "/test/test_abs_http.php");' to .txt, and you'll see it works fine.

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 23:01:31 2024 UTC