summaryrefslogtreecommitdiff
path: root/inc/init.php
diff options
context:
space:
mode:
authorChris Smith <chris.eureka@jalakai.co.uk>2008-04-18 12:19:46 +0200
committerChris Smith <chris.eureka@jalakai.co.uk>2008-04-18 12:19:46 +0200
commit46c73e019aa4552abbd431f3086e73cea74429ce (patch)
tree4ae7305da71d2234d422914253fa5ca976002db4 /inc/init.php
parentbde4e341723f1f504448e86150fb171d76aef615 (diff)
downloadrpg-46c73e019aa4552abbd431f3086e73cea74429ce.tar.gz
rpg-46c73e019aa4552abbd431f3086e73cea74429ce.tar.bz2
Update GetBaseURL() to avoid multiple consecutive slashes in absolute return values (incl. test cases)
darcs-hash:20080418101946-f07c6-615691fab5d4b5714134634b38567ca8422a0aa0.gz
Diffstat (limited to 'inc/init.php')
-rw-r--r--inc/init.php18
1 files changed, 9 insertions, 9 deletions
diff --git a/inc/init.php b/inc/init.php
index 9563af296..ee82bbe0e 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -298,21 +298,21 @@ function getBaseURL($abs=null){
if(is_null($abs)) $abs = $conf['canonical'];
if($conf['basedir']){
- $dir = $conf['basedir'].'/';
+ $dir = $conf['basedir'];
}elseif(substr($_SERVER['SCRIPT_NAME'],-4) == '.php'){
- $dir = dirname($_SERVER['SCRIPT_NAME']).'/';
+ $dir = dirname($_SERVER['SCRIPT_NAME']);
}elseif(substr($_SERVER['PHP_SELF'],-4) == '.php'){
- $dir = dirname($_SERVER['PHP_SELF']).'/';
+ $dir = dirname($_SERVER['PHP_SELF']);
}elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){
$dir = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
$_SERVER['SCRIPT_FILENAME']);
- $dir = dirname('/'.$dir).'/';
+ $dir = dirname('/'.$dir);
}else{
- $dir = './'; //probably wrong
+ $dir = '.'; //probably wrong
}
- $dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour
- $dir = preg_replace('#//+#','/',$dir);
+ $dir = str_replace('\\','/',$dir); // bugfix for weird WIN behaviour
+ $dir = preg_replace('#//+#','/',"/$dir/"); // ensure leading and trailing slashes
//handle script in lib/exe dir
$dir = preg_replace('!lib/exe/$!','',$dir);
@@ -323,8 +323,8 @@ function getBaseURL($abs=null){
//finish here for relative URLs
if(!$abs) return $dir;
- //use config option if available
- if($conf['baseurl']) return $conf['baseurl'].$dir;
+ //use config option if available, trim any slash from end of baseurl to avoid multiple consecutive slashes in the path
+ if($conf['baseurl']) return rtrim($conf['baseurl'],'/').$dir;
//split hostheader into host and port
list($host,$port) = explode(':',$_SERVER['HTTP_HOST']);