
PHP код:
<? $success = @include_once(dirname(__FILE__)."/elem/config.inc.php");
if (!$success) { echo "Include failed"; } ?>
Или

PHP код:
<?php
function getPath() {
// get position of current file
$path = $GLOBALS["PATH_INFO"];
// save a few nanaseconds, has this been done before,
// has the global variable been set ?
if (!isset($definedPath)) {
// is file in root already ?
if (strrpos($path,"/")!=0) {
// there is probably a quicker way to count
// the "/"s in the path
$path=explode("/",$path);
$s="";
for ($i=0;$i<count($path)-1;$i++) {
if ($path[$i]!="") {
// add the number of "../"s required
$s.="../";
}
}
// declare a global variable so you dont have to
// do this again, and return the variable
global $definedPath;
$definedPath=$s;
return $definedPath;
}
} else {
// just return what it worked out before, function
// only really runs once
return $definedPath;
}
}
include getPath() . "my_include_path/header.inc";
include getPath() . "includes/somethingelse.inc";
//above file is at mydomain.com/includes/somethingelse.inc
include getPath() . "includes/footer.inc";
?>