common.lib.php

来自「php绿色服务器,让大家试用greenamp」· PHP 代码 · 共 1,687 行 · 第 1/5 页

PHP
1,687
字号
<?php/* $Id: common.lib.php,v 2.87.2.2 2004/11/10 00:40:48 lem9 Exp $ */// vim: expandtab sw=4 ts=4 sts=4:/** * Misc stuff and functions used by almost all the scripts. * Among other things, it contains the advanced authentification work. *//** * Order of sections for common.lib.php: * * some functions need the constants of libraries/defines.lib.php * and defines_mysql.lib.php * * the PMA_setFontSizes() function must be before the call to the * libraries/auth/cookie.auth.lib.php library * * the include of libraries/defines_mysql.lib.php must be after the connection * to db to get the MySql version * * the PMA_sqlAddslashes() function must be before the connection to db * * the authentication libraries must be before the connection to db but * after the PMA_isInto() function * * the PMA_mysqlDie() function must be before the connection to db but * after mysql extension has been loaded * * the PMA_mysqlDie() function needs the PMA_format_sql() Function * * ... so the required order is: * * - parsing of the configuration file * - load of the libraries/defines.lib.php library * - load of mysql extension (if necessary) * - definition of PMA_sqlAddslashes() * - definition of PMA_format_sql() * - definition of PMA_mysqlDie() * - definition of PMA_isInto() * - definition of PMA_setFontSizes() * - loading of an authentication library * - db connection * - authentication work * - load of the libraries/defines_mysql.lib.php library to get the MySQL *   release number * - other functions, respecting dependencies *//** * Minimum inclusion? (i.e. for the stylesheet builder) */if (!isset($is_minimum_common)) {    $is_minimum_common = FALSE;}/** * Avoids undefined variables */if (!isset($use_backquotes)) {    $use_backquotes   = 0;}if (!isset($pos)) {    $pos              = 0;}/** * 2004-06-30 rabus: Ensure, that $cfg variables are not set somwhere else * before including the config file. */unset($cfg);/** * Detects the config file we want to load */if (file_exists('./config.inc.developer.php')) {    $cfgfile_to_load = './config.inc.developer.php';} else {    $cfgfile_to_load = './config.inc.php';}/** * Parses the configuration file and gets some constants used to define * versions of phpMyAdmin/php/mysql... */$old_error_reporting = error_reporting(0);include_once($cfgfile_to_load);// Include failedif (!isset($cfgServers) && !isset($cfg['Servers'])) {    // Creates fake settings    $cfg = array('DefaultLang'           => 'en-iso-8859-1',                    'AllowAnywhereRecoding' => FALSE);    // Loads the language file    require_once('./libraries/select_lang.lib.php');    // Sends the Content-Type header    header('Content-Type: text/html; charset=' . $charset);    // Displays the error message    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $available_languages[$lang][2]; ?>" lang="<?php echo $available_languages[$lang][2]; ?>" dir="<?php echo $text_dir; ?>"><head><title>phpMyAdmin</title><meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" /><style type="text/css"><!--body  {font-family: sans-serif; font-size: small; color: #000000; background-color: #F5F5F5}h1    {font-family: sans-serif; font-size: large; font-weight: bold}//--></style></head><body bgcolor="#ffffff"><h1>phpMyAdmin - <?php echo $strError; ?></h1><p><?php echo $strConfigFileError; ?><br /><br /><a href="config.inc.php" target="_blank">config.inc.php</a></p></body></html>    <?php    exit();}error_reporting($old_error_reporting);unset($old_error_reporting, $cfgfile_to_load);/** * Includes compatibility code for older config.inc.php revisions * if necessary */if (isset($cfg['FileRevision'])) {    // converting revision string into an array    //     e.g. "Revision: 2.0" becomes array(2, 0).    $cfg['FileRevision'] = str_replace('$' . 'Revision: ', '', $cfg['FileRevision']);    $cfg['FileRevision'] = str_replace(' $', '', $cfg['FileRevision']);    $cfg['FileRevision'] = explode('.', $cfg['FileRevision']);} else {    $cfg['FileRevision'] = array(1, 1);}if ($cfg['FileRevision'][0] < 2 || ($cfg['FileRevision'][0] == 2 && $cfg['FileRevision'][1] < 38)) {    require_once('./libraries/config_import.lib.php');}/** * Includes the language file if it hasn't been included yet */require_once('./libraries/select_lang.lib.php');/** * Gets constants that defines the PHP version number. * This include must be located physically before any code that needs to * reference the constants, else PHP 3.0.16 won't be happy. */require_once('./libraries/defines.lib.php');if ($is_minimum_common == FALSE) {    /**     * Define $is_upload     */      $is_upload = TRUE;      if (strtolower(@ini_get('file_uploads')) == 'off'             || @ini_get('file_uploads') == 0) {          $is_upload = FALSE;      }    /**     * Maximum upload size as limited by PHP     * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas     *     * this section generates $max_upload_size in bytes     */    function get_real_size($size=0) {    /// Converts numbers like 10M into bytes        if (!$size) {            return 0;        }        $scan['MB'] = 1048576;        $scan['Mb'] = 1048576;        $scan['M'] = 1048576;        $scan['m'] = 1048576;        $scan['KB'] = 1024;        $scan['Kb'] = 1024;        $scan['K'] = 1024;        $scan['k'] = 1024;        while (list($key) = each($scan)) {            if ((strlen($size)>strlen($key))&&(substr($size, strlen($size) - strlen($key))==$key)) {                $size = substr($size, 0, strlen($size) - strlen($key)) * $scan[$key];                break;            }        }        return $size;    } // end function    if (!$filesize = ini_get('upload_max_filesize')) {        $filesize = "5M";    }    $max_upload_size = get_real_size($filesize);    if ($postsize = ini_get('post_max_size')) {        $postsize = get_real_size($postsize);        if ($postsize < $max_upload_size) {            $max_upload_size = $postsize;        }    }    unset($filesize);    unset($postsize);    /**     * other functions for maximum upload work     */    /**     * Displays the maximum size for an upload     *     * @param   integer  the size     *     * @return  string   the message     *     * @access  public     */     function PMA_displayMaximumUploadSize($max_upload_size) {         list($max_size, $max_unit) = PMA_formatByteDown($max_upload_size);         return '(' . sprintf($GLOBALS['strMaximumSize'], $max_size, $max_unit) . ')';     }    /**     * Generates a hidden field which should indicate to the browser     * the maximum size for upload     *     * @param   integer  the size     *     * @return  string   the INPUT field     *     * @access  public     */     function PMA_generateHiddenMaxFileSize($max_size){         return '<input type="hidden" name="MAX_FILE_SIZE" value="' .$max_size . '" />';     }    /**     * Charset conversion.     */    require_once('./libraries/charset_conversion.lib.php');    /**     * String handling     */    require_once('./libraries/string.lib.php');}/** * Removes insecure parts in a path; used before include() or * require() when a part of the path comes from an insecure source * like a cookie or form. * * @param    string  The path to check * * @return   string  The secured path * * @access  public * @author  Marc Delisle (lem9@users.sourceforge.net) */function PMA_securePath($path) {    // change .. to .    $path = preg_replace('@\.\.*@','.',$path);    return $path;} // end function// If zlib output compression is set in the php configuration file, no// output buffering should be runif (@ini_get('zlib.output_compression')) {    $cfg['OBGzip'] = FALSE;}// disable output-buffering (if set to 'auto') for IE6, else enable it.if (strtolower($cfg['OBGzip']) == 'auto') {    if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 6 && PMA_USR_BROWSER_VER < 7) {        $cfg['OBGzip'] = FALSE;    } else {        $cfg['OBGzip'] = TRUE;    }}/* Theme Manager * 2004-05-20 Michael Keck (mail_at_michaelkeck_dot_de) *            This little script checks if there're themes available *            and if the directory $ThemePath/$theme/img/ exists *            If not, it will use default images*/// Theme Managerif (!isset($_COOKIE['pma_theme']) || empty($_COOKIE['pma_theme'])){    $GLOBALS['theme'] = $cfg['ThemeDefault'];    $ThemeDefaultOk = FALSE;    if ($cfg['ThemePath']!='' && $cfg['ThemePath'] != FALSE) {        $tmp_theme_mainpath = $cfg['ThemePath'];        $tmp_theme_fullpath = $cfg['ThemePath'] . '/' .$cfg['ThemeDefault'];        if (@is_dir($tmp_theme_mainpath)) {            if (isset($cfg['ThemeDefault']) && @is_dir($tmp_theme_fullpath)) {                $ThemeDefaultOk = TRUE;            }        }    }    if ($ThemeDefaultOk == TRUE){        $GLOBALS['theme'] = $cfg['ThemeDefault'];    } else {        $GLOBALS['theme'] = 'original';    }} else {    // if we just changed theme, we must take the new one so that    // index.php takes the correct one for height computing    if (isset($_POST['set_theme'])) {        $GLOBALS['theme'] = PMA_securePath($_POST['set_theme']);    } else {        $GLOBALS['theme'] = PMA_securePath($_COOKIE['pma_theme']);    }}// check for theme requires/nameunset($theme_name, $theme_generation, $theme_version);@include($cfg['ThemePath'] . '/' . $GLOBALS['theme'] . '/info.inc.php');// did it set correctly?if (!isset($theme_name, $theme_generation, $theme_version))    $GLOBALS['theme'] = 'original'; // invalid themeif ($theme_generation != PMA_THEME_GENERATION)    $GLOBALS['theme'] = 'original'; // different generation

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?