note 78344 added to function.include
| From: | sbwoodside at yahoo dot com | Date: | Sun, 07 Oct 2007 21:19:46 +0000 |
| Subject: | note 78344 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131212@lists.php.net to get a copy of this message | ||
Here's a really simple solution to a common problem. Let's say you want to include files
the way that apache does, relative to the document root (the root dir of your app). Independent of
what server you are on, so that you don't have to specify an absolute path on your filesystem.
At the top of your page put:
<?php set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT']
); ?>
Now anywhere you do an include you can do something like:
<?php include ( "Templates/header.inc") ?>
So, if your server files are in /var/www/mysite, this will include
/var/www/mysite/Templates/header.inc when it's on your server. And if on your dev machine
it's in /user/myname/mysite, it will include /user/myname/mysite/Templates/header.inc when
it's on your dev machine.
----
Server IP: 64.71.164.2
Probable Submitter: 74.12.187.202
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- https://master.php.net/note/edit/78344
Del: integrated -- https://master.php.net/note/delete/78344/integrated
Del: useless -- https://master.php.net/note/delete/78344/useless
Del: bad code -- https://master.php.net/note/delete/78344/bad+code
Del: spam -- https://master.php.net/note/delete/78344/spam
Del: non-english -- https://master.php.net/note/delete/78344/non-english
Del: in docs -- https://master.php.net/note/delete/78344/in+docs
Del: other reasons-- https://master.php.net/note/delete/78344
Reject -- https://master.php.net/note/reject/78344
Search -- https://master.php.net/manage/user-notes.php