note 40752 deleted from function.dirname by nlopess

From: Date: Sat, 13 Mar 2004 21:31:42 +0000
Subject: note 40752 deleted from function.dirname by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-66781@lists.php.net to get a copy of this message
Note Submitter: Brian ---- Since dirname() does not return "" when you are in the / directory it is not appropriate for relative redirects as stated in the documentation for header(). I wrote a function below that should work. <?php function relative_redirect($uri) { $directoryname = dirname($_SERVER['PHP_SELF']); if($directoryname == "." || $directoryname == "\\" || $directoryname == "/") $directoryname = ""; header("Location: http://".$_SERVER['HTTP_HOST'].$directoryname."/".$uri); } ?>

« previous php.notes (#66781) next »