note 35873 deleted from function.include by sniper
| From: | sniper@php.net | Date: | Tue, 04 Nov 2003 00:42:52 +0000 |
| Subject: | note 35873 deleted from function.include by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59796@lists.php.net to get a copy of this message | ||
Note Submitter: greg@doutromundo.com
----
If you've worked with wierd and crazy sites like I have, you've most probably come across
situations where you must use the same include in several pages.
On one particular site, I faced a situation in which I had to include the same file in all my pages
depending on the first directory.
i.e. :
http://mysite/dir1/
http://mysite/dir2/
In this case, using a root relative include will not work, so I "threw-up" this bit of
code.
I've fixed it up a bit, but probably there's lot's of room for improvment:
<?
$includeName="includeName.php";
#
# Here I get the script location
#
$script = $_SERVER["SCRIPT_NAME"];
#
# Define here the number of directories from the
# root the include is included.
# let's say you are here on dir4:
# http://domain/dir1/dir2/dir3/dir4
# and your include is in dir2, then you
# would set $numDir=2
$numDir = 0;
$bars = count(explode("/",$script))-($numDir+2);
$path="";
if ($bars>0){
for ($i=0;$i<$bars;$i++) $path.="../";
}
include ($path.$includeName);
?>