RE: [PHP] Includes

From: Date: Sun, 20 Apr 2003 20:45:31 +0000
Subject: RE: [PHP] Includes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144573@lists.php.net to get a copy of this message
> Is there any way to "dynamically" alter the include path during a page > load? Something like Perl's use lib idea. I'm in a shared hosting > environment where I don't have access to the php.ini file. The web root > on the chroot host is /var/www/html and is where all of my include files > are at. If I: > > require_once("header.php"); > > >From a page within /var/www/html it works fine. If I (per my ISP's > instructions): > > require_once("/header.php"); > > It fails (can't find include). If I: > > require_once("header.php"); > require_once("/header.php"); > > >From any page in any directory below /var/www/html it fails (the usual > error). $path = '/var/www/html/'; include($path.'header.php'); will work from any page... or you can modify the include_path with ini_set(). ini_set('include_path','/var/www/html/'); include('header.php'); will now work from any page (I think, check the syntax). > Question with the / in the require. Is that going to the server root (/) > directory to look for the page or the root of the site the calling page > is loading from? It's going to the server root... > Can I somehow "push" /var/www/html onto the include stack during the > initial page load somehow (perl's push(@INC) kind of thing? > > Should I / could I somehow grab the server name from the QUERY_STRING > and prepend that to the require then fetch the page over HTTP? You can get the server name with $_SERVER['SERVER_NAME'], but if you use it that way, you're not going to get any PHP code, just the resulting HTML. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#144573) next »