[thelist] PHP includes on Linux vs. Windows

Rich Gray rich at f1central.net
Sat Nov 30 12:53:01 CST 2002


David

The <a href="..." html stuff is going through the web server which will only
honour local links within the site's document root - i.e. it has it's own
artificial root directory. PHP's include/require functions are file system
based so they can access anything on the hard drive (security settings
dependent of course) that is why the root directory for include/require is
the real root directory. So the leading slash has two different meanings to
href vs include()...

So to include() relative to the document root is simple...

<?
include($_SERVER['DOCUMENT_ROOT'].'/includes/included_file.php')
?>

It looks clumsy but you can get round that by having a constant defined in a
common script ...
e.g.

<?
define('R',$_SERVER['DOCUMENT_ROOT']);

// Now you can substitute 'R' for the site root
include(R.'/includes/included_file.php');
?>

I hope I am making sense ...
Cheers
Rich
<<<<<<<<<<<<<<

A good example of this would be (thinking HTML here)...

<a href="/index.html">goes to index.html in the web root</a>

How would I include a page relative to website's root directory?


Thanks,
David Bindel




More information about the thelist mailing list