[Phplogcon-dev] duplicated code

Michael Meckelein mmeckelein at hq.adiscon.com
Wed Dec 7 16:05:24 CET 2005


Hi Brian, 

I noticed that you use duplicated code in some files. The code snippet
below is in e.g.  auth.php, config.php, include.php, ...

Wouldn't it be better to put it into a function onto the top in
include.php? 

// BGS -- This will remove the trailin / in a uri like .../index.php/
// This causes the directories to get mucked up.
// Patch from http://www.php.net/manual/en/ref.apache.php by
henk_nicolai at REMOVE-THIS at hotmail dot com
	$req = $_SERVER['REQUEST_URI'];
	// Remove rubbish.
	$newReq = ereg_replace ( $_SERVER['SCRIPT_NAME'] . '[^?]*',
$_SERVER['SCRIPT_NAME'], $req);
	if (strlen($newReq) < strlen($req)) 
	{
		header ('Location: '.$newReq);
		header ('HTTP/1.0 301 Moved Permanently');
		die;  // Don't send any more output.
	}
	unset($req); 
	unset($newReq);
// BGS end	
// BGS -- do not all access from URI
$filename =  substr(__FILE__, strrpos( __FILE__, "/" ));
$requestname = substr($_SERVER['SCRIPT_NAME'], strrpos(
$_SERVER['SCRIPT_NAME'], "/" ));
if( $filename == $requestname )
{
	session_unset();
	header("Location: ../index.php");
	exit;
}
// BGS end

Michael



More information about the Phplogcon-dev mailing list