You are here: Re: use of $_SERVER['DOCUMENT_ROOT']. « PHP Programming Language « IT news, forums, messages
Re: use of $_SERVER['DOCUMENT_ROOT'].

Posted by Andy Jeffries on 05/09/06 22:50

On Tue, 09 May 2006 12:06:06 -0700, Chris wrote:
> I'm working on a large intranet group site with a lot of pages, file
> types, folders, subfolders, etc. I am using the include
> ('../includes/file.php') , but I would like to have a single snippet that
> will work for all .php/.html pages in all subfolders. I have seen the
> $_SERVER['DOCUMENT_ROOT'] indicated as a way to access the root of the
> website without using ../ for each folder you have to pass up through.

How about I give you a different way... In your Apache VirtualHost use:

php_value include_path .:/path/to/webroot/parent/includes/

Then you can just use:

include("file.php");

From anywhere and it will include it from the current folder (if found),
if not look in your /includes folder for it.

Anyway, you can do it by parsing $_SERVER["DOCUMENT_ROOT"] to get to the
parent, but it's much easier (and cleaner to read) by re-setting
include_path.

If you want to keep the current path you could do it using a single global
file which ini_set's the include_path to include the current include_path
and the new /includes folder. You could include that in your Apache
virtualhost using:

php_value auto_prepend_file /path/to/webroot/parent/includes/global.php

Hope this helps.

Cheers,


Andy


--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация