Having problems with relativity? Prefer to use root-relative over document-relative includes? This script should help.
This function will treat all paths beginning with "/" as root-relative, and allow "../" to be used for parent pathing.

<?
// filename: util.php
function path_calc($dest,$ssl=false){
$toUrl = ($ssl ? 'https://' : 'http://').$_SERVER['HTTP_HOST'];
if (strpos($dest,0) == "/"){
// root-relative
$toUrl .= $dest;
} else if (strpos('http',0) == 0){
// absolute
$toUrl = $dest;
} else {
// document-relative
// traverse up the directory tree as needed
$parent = dirname($dest);
while(strpos($dest,"../") == 0){
$parent = dirname($parent);
$dest = substr($dest,3);
}
$toUrl .= $dest;
}

return($toUrl);
}

function redirect($dest,$ssl=false){
header("Location: ".path_calc($dest, $ssl));
exit();
}
?>

No more messing with _SERVER variables! just do something like

<?
require_once('util.php')
if (!isset($_SESSION['authorized'])){
redirect('/login.php'); //note this will work from anywhere in your site
}
?>

Granted, the root-relativity does not work for the inclusion of the util.php file, but for all others (including .gif, .jpeg, .css, .js, etc) you can use root-relativity. Example:</p>

<?
require_once('../../includes/util.php');
?>
<html>
<body>
<img src="<?=path_calc('/images/logo.gif')?>">
</body>
</html>

Hope that helps!
----
Manual Page -- [url]http://www.php.net/manual/en/function.require-once.php[/url]
Edit Note -- [url]http://master.php.net/manage/user-notes.php?action=edit+33914[/url]
Delete Note -- [url]http://master.php.net/manage/user-notes.php?action=delete+33914&report=yes[/url]
Reject Note -- [url]http://master.php.net/manage/user-notes.php?action=reject+33914&report=yes[/url]