fix for MDL-6680 redirect function is broken when running php as CGI, me() now used instead of SCRIPT_NAME + minor coding style changes

This commit is contained in:
skodak 2006-09-24 19:10:13 +00:00
parent 1cc309df9d
commit aade3a4b6a

View file

@ -4673,21 +4673,19 @@ function redirect($url, $message='', $delay=-1) {
// the absolute path. (In practice browsers accept relative // the absolute path. (In practice browsers accept relative
// paths - but still, might as well do it properly.) // paths - but still, might as well do it properly.)
// This code turns relative into absolute. // This code turns relative into absolute.
if(!preg_match('/^[a-z]+:/',$url)) { if (!preg_match('|^[a-z]+:|', $url)) {
// Get host name http://www.wherever.com // Get host name http://www.wherever.com
$hostpart=preg_replace('/^(.*?[^:\/])\/.*$/','$1',$CFG->wwwroot); $hostpart = preg_replace('|^(.*?[^:/])/.*$|', '$1', $CFG->wwwroot);
if(preg_match('/^\//',$url)) { if (preg_match('|^/|', $url)) {
// URLs beginning with / are relative to web server root so // URLs beginning with / are relative to web server root so we just add them in
// we just add them in
$url = $hostpart.$url; $url = $hostpart.$url;
} else { } else {
// URLs not beginning with / are relative to path of current // URLs not beginning with / are relative to path of current script, so add that on.
// script, so add that on. $url = $hostpart.me().'/../'.$url;
$url=$hostpart.rtrim(dirname($_SERVER['SCRIPT_NAME']),'/\\').'/'.$url;
} }
// Replace all ..s // Replace all ..s
while (true) { while (true) {
$newurl=preg_replace('/\/[^\/]*\/\.\.\//','/',$url); $newurl = preg_replace('|/[^/]*/\.\./|', '/', $url);
if ($newurl == $url) { if ($newurl == $url) {
break; break;
} }