PDA

View Full Version : what is the best way to reference files in root directory


Bernard
05-04-2005, 23:38/11:38PM
I'd like to have some basic include files in the root directory that are included in every page - no matter what sub-directory the page is in.

What is the best way to reference the include files?<?php include("http://www.domain.com/includefile.inc"); ?>works, but I was wondering if there is a way to specify it without using the domain name. I tried: <?php include("/includefile.inc"); ?>but that did not work.

ArmenT
06-04-2005, 01:37/01:37AM
You should specify the whole path to the file, something like this:

<?
include ("/home/bernard/www/include.inc");
?>


I usually prefer something like this:

<?
$doc_root = $_SERVER["DOCUMENT_ROOT"];
include ("$doc_root/include.inc");
include ("$doc_root/include2.inc");
?>

This way, the variable $doc_root is set no matter where it is installed.

Bernard
06-04-2005, 02:17/02:17AM
Thanks! That works like a charm.

WebSavvy
06-04-2005, 02:54/02:54AM
I do mine the same way ArmenT suggested. The only thing I do differently is add the @ sign before the call.

<?php

@include("{$_SERVER['DOCUMENT_ROOT']}/include.inc");

?>

The reason for adding the @ sign is, if your scripts mess up when John Q. Public is at the site, it'll turn off the scripting error message - thus not allowing them to see your root path.

Too many hackers out there and it's never wise to show someone your path info!

Bernard
06-04-2005, 03:19/03:19AM
Thanks Deb! Will do...