Re: [PHP4BETA] Newbie question about include and require...

From: Date: Thu, 02 Mar 2000 19:07:57 +0000
Subject: Re: [PHP4BETA] Newbie question about include and require...
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-11382@lists.php.net to get a copy of this message
Ryan Robertson wrote: > Hello again, > > I have an include file (application.php, pasted in below) that I'm adding to > each page on my site using the require function. This file also requires > other files in the same directory as itself. I'll call that directory A. > > Requiring application.php from any php files in directory A works just fine > as expected. If I have a subdirectory of directory A (directory B), I can't > find an elegant way to include application.php. When I try using > require("../application.php"), it correctly finds application.php from > directory A but execution fails when application.php tries to require > another file. PHP doesn't correctly resolve the path to the required files > since its executing from a subdirectory (which makes some sense). > > > I've tried hard-coding the path to the files that I require in > application.php, but that doesn't seem to work. Is there an easy way to > tell PHP to look in the same directory as the file that is requiring other > files (ie: directory A). > I don't think so, but it is suprising that abosolute paths don't work. Paths like include("/usr/www/htdocs/myFile.php") or include("C:/Apache/htdocs/myFile.php") should always work. > > Here is the code for application.php: > > <? > // Display the offline message if we are offline > $Offline = 0; > if ($Offline) > { > require("unavailable.php"); > exit(); > } > You should use include() in if statements. Require() will always include the file. Michael

« previous php.version4 (#11382) next »