|
Posted by Jerry Stuckle on 01/20/07 02:26
Toby Inkster wrote:
> Paul wrote:
>
>> require_once($_SERVER['DOCUMENT_ROOT']."/utility/top.php");
>
> That's not a great way of referencing included files. It makes it
> difficult to move your site around.
>
> Try instead creating a directory called "includes", and putting all your
> included files into there, like:
>
> includes/search_functions.php
> includes/database_functions.php
> includes/utility/top.php
> includes/utility/bottom.php
> includes/utility/left.php
> includes/utility/right.php
>
> Now, when you need to refer to them, use:
>
> require_once 'utility/top.php';
>
> Note here that we've not specified the full path for the file, not even a
> normal relative path -- we've specified where it is RELATIVE TO THE
> "includes" DIRECTORY, not relative to where we are now.
>
> Now in your .htaccess file, you can set:
>
> php_value includes_path /full/path/to/includes/
>
> So when PHP sees a 'include' or 'require' statement, it will search
> through the path(s) in the includes_path setting and look for
> /full/path/to/includes/utility/top.php.
>
> Yay
>
Actually, that's the BEST WAY to reference your files.
$_SERVER['DOCUMENT_ROOT'] will ALWAYS contain the absolute path to the
root directory of your site, no matter where it is. You need to make no
changes to any files when referencing this way.
Then you don't need any entry in your .htaccess file (which even Apache
recommends against using), you don't have to worry about setting it up
or anything else. Everything works automatically.
I use this all the time in my sites. I can move them between different
test machines (both local and on the internet), the final site - whatever.
I've even moved complete sites from one provider to another. All that
was necessary was to upload and go.
And BTW - it works in IIS also, which doesn't have a .htaccess file.
Works great, in fact.
Use the server-provided values where you can. That's what they're there
for.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|