Changeset 2071 for trunk/include


Ignore:
Timestamp:
Jul 24, 2007, 9:14:11 PM (17 years ago)
Author:
rub
Message:

Resolved 0000726: script_basename returns bad result

With specific server configuration, script_basename returns bad result.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions.inc.php

    r2029 r2071  
    12871287
    12881288/**
    1289  * Return is "file_name" argument is candidate to
    1290  * compute script_basename value
    1291  *
    1292  * @param string file_name
    1293  *
    1294  * @return boolean is candidate or not?
    1295  */
    1296 function is_script_basename($file_name)
    1297 {
    1298   $file_name = basename($file_name);
    1299   return !empty($file_name);
    1300 }
    1301 
    1302 /**
    13031289 * Return basename of the current script
    13041290 * Lower case convertion is applied on return value
     
    13111297function script_basename()
    13121298{
    1313   if (is_script_basename($_SERVER['SCRIPT_NAME']))
    1314   {
    1315     $file_name = $_SERVER['SCRIPT_NAME'];
    1316   }
    1317   else if (is_script_basename($_SERVER['SCRIPT_FILENAME']))
    1318   {
    1319     $file_name = $_SERVER['SCRIPT_FILENAME'];
    1320   }
    1321   else
    1322   {
    1323     $file_name = '';
    1324   }
    1325 
    1326   // $_SERVER return lower string following var and systems
    1327   return basename(strtolower($file_name), '.php');
     1299  global $conf;
     1300
     1301  foreach (array('SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF') as $value)
     1302  {
     1303    $continue = !empty($_SERVER[$value]);
     1304    if ($continue)
     1305    {
     1306      $filename = strtolower($_SERVER[$value]);
     1307
     1308      if ($conf['php_extension_in_urls'])
     1309      {
     1310        $continue = get_extension($filename) ===  'php';
     1311      }
     1312
     1313      if ($continue)
     1314      {
     1315        $basename = basename($filename, '.php');
     1316        $continue = !empty($basename);
     1317      }
     1318
     1319      if ($continue)
     1320      {
     1321        return $basename;
     1322      }
     1323    }
     1324  }
     1325
     1326  return '';
    13281327}
    13291328
Note: See TracChangeset for help on using the changeset viewer.