当前位置:编程学习 > php >>

Uchome1.2 1.5 代码学习 common.php

答案: UCHOME的代码还是很不错的,学习一下!
复制代码 代码如下:

<?php
/**
* 定义一些常量
*/
@define('IN_UCHOME', TRUE); //据说可以防止文件非法包含
define('X_VER', '1.2'); //Uchome版本
define('X_RELEASE', '20080612');//发布日期
define('D_BUG', '0'); //是否开启调试功能, 0:关闭, 1:开启
//根据是否开启调试功能设置错误报告级别
D_BUG?error_reporting(7):error_reporting(0);
//初始化一些全局变量
$_SGLOBAL = $_SCONFIG = $_SBLOCK = $_TPL = $_SCOOKIE = $space = array();
//定义程序目录常量
define('S_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
//获取时间,主要用于输出程序运行时间
$mtime = explode(' ', microtime());
$_SGLOBAL['timestamp'] = $mtime[1];
$_SGLOBAL['supe_starttime'] = $_SGLOBAL['timestamp'] + $mtime[0];
//基本文件,尝试包含基本配置文件,如果包含不成功,则安装程序
if(!@include_once(S_ROOT.'./config.php')) {
header("Location: install/index.php");
exit();
}
//包含公用函数库
include_once(S_ROOT.'./source/function_common.php');
//链接数据库
dbconnect();
//配置文件,尝试包含缓存目录中的网站配置信息,如果不成功,则包含进缓存处理函数库并生成配置缓存
if(!@include_once(S_ROOT.'./data/data_config.php')) {
include_once(S_ROOT.'./source/function_cache.php');
config_cache();
}
//强制使用字符集
if($_SCONFIG['headercharset']) {
@header('Content-Type: text/html; charset='.$_SC['charset']);
}
//GPC过滤,自动转义$_GET,$_POST,$_COOKIE中的特殊字符,防止SQL注入攻击
$magic_quote = get_magic_quotes_gpc();
if(emptyempty($magic_quote)) {
$_GET = saddslashes($_GET);
$_POST = saddslashes($_POST);
}
//COOKIE
$prelength = strlen($_SC['cookiepre']);
foreach($_COOKIE as $key => $val) {
if(substr($key, 0, $prelength) == $_SC['cookiepre']) {
$_SCOOKIE[(substr($key, $prelength))] = emptyempty($magic_quote) ? saddslashes($val) : $val;
}
}
//启用GIP
if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
//初始化
$_SGLOBAL['supe_uid'] = 0;
$_SGLOBAL['supe_username'] = '';
$_SGLOBAL['inajax'] = emptyempty($_GET['inajax'])?0:intval($_GET['inajax']);
$_SGLOBAL['ajaxmenuid'] = emptyempty($_GET['ajaxmenuid'])?'':$_GET['ajaxmenuid'];
$_SGLOBAL['refer'] = emptyempty($_SERVER['HTTP_REFERER'])?'':$_SERVER['HTTP_REFERER'];
//获取用户信息
getuser();
//应用列表
@include_once(S_ROOT.'./data/data_app.php');
if(emptyempty($_SGLOBAL['app'])) {
include_once(S_ROOT.'./source/function_cache.php');
app_cache();
}
?>
<?php
/**
* 定义一些常量
*/
@define('IN_UCHOME', TRUE); //据说可以防止文件非法包含
define('X_VER', '1.2'); //Uchome版本
define('X_RELEASE', '20080612');//发布日期
define('D_BUG', '0'); //是否开启调试功能, 0:关闭, 1:开启
//根据是否开启调试功能设置错误报告级别
D_BUG?error_reporting(7):error_reporting(0);
//初始化一些全局变量
$_SGLOBAL = $_SCONFIG = $_SBLOCK = $_TPL = $_SCOOKIE = $space = array();
//定义程序目录常量
define('S_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
//获取时间,主要用于输出程序运行时间
$mtime = explode(' ', microtime());
$_SGLOBAL['timestamp'] = $mtime[1];
$_SGLOBAL['supe_starttime'] = $_SGLOBAL['timestamp'] + $mtime[0];
//基本文件,尝试包含基本配置文件,如果包含不成功,则安装程序
if(!@include_once(S_ROOT.'./config.php')) {
header("Location: install/index.php");
exit();
}
//包含公用函数库
include_once(S_ROOT.'./source/function_common.php');
//链接数据库
dbconnect();
//配置文件,尝试包含缓存目录中的网站配置信息,如果不成功,则包含进缓存处理函数库并生成配置缓存
if(!@include_once(S_ROOT.'./data/data_config.php')) {
include_once(S_ROOT.'./source/function_cache.php');
config_cache();
}
//强制使用字符集
if($_SCONFIG['headercharset']) {
@header('Content-Type: text/html; charset='.$_SC['charset']);
}
//GPC过滤,自动转义$_GET,$_POST,$_COOKIE中的特殊字符,防止SQL注入攻击
$magic_quote = get_magic_quotes_gpc();
if(emptyempty($magic_quote)) {
$_GET = saddslashes($_GET);
$_POST = saddslashes($_POST);
}
//COOKIE
$prelength = strlen($_SC['cookiepre']);
foreach($_COOKIE as $key => $val) {
if(substr($key, 0, $prelength) == $_SC['cookiepre']) {
$_SCOOKIE[(substr($key, $prelength))] = emptyempty($magic_quote) ? saddslashes($val) : $val;
}
}
//启用GIP
if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
//初始化
$_SGLOBAL['supe_uid'] = 0;
$_SGLOBAL['supe_username'] = '';
$_SGLOBAL['inajax'] = emptyempty($_GET['inajax'])?0:intval($_GET['inajax']);
$_SGLOBAL['ajaxmenuid'] = emptyempty($_GET['ajaxmenuid'])?'':$_GET['ajaxmenuid'];
$_SGLOBAL['refer'] = emptyempty($_SERVER['HTTP_REFERER'])?'':$_SERVER['HTTP_REFERER'];
//获取用户信息
getuser();
//应用列表
@include_once(S_ROOT.'./data/data_app.php');
if(emptyempty($_SGLOBAL['app'])) {
include_once(S_ROOT.'./source/function_cache.php');
app_cache();
}
?>

下面是1.5版本的common.php
复制代码 代码如下:

<?php
/*
[UCenter Home] (C) 2007-2008 Comsenz Inc.
$Id: common.php 10981 2009-01-14 03:05:20Z liguode $
*/
//定义一个常量,用来在其他页面中,防止被恶意用户直接调用其他PHP文件。
@define('IN_UCHOME', TRUE);
//定义一个常量,这个常量表示版本号
define('X_VER', '1.5');
//这个也是一个常量,次版本号
define('X_RELEASE', '20090114');
/*定义程序的调试模式,在我们调试程序的时候将常量值设为1,这样程序出错的时候会在页面显示错误信息。
在调试完毕正常投入使用后设为0,这样程序出错不会显示给用户。
*/
define('D_BUG', '0');
//通过D_BUG常量值指定错误报告类型。其中error_reporting()的参数是错误报告类型,相关参数可查询PHP手册
D_BUG?error_reporting(7):error_reporting(0);
//这下面都是定义的全局变量。具体的会在后面使用的时候一一介绍
$_SGLOBAL = $_SCONFIG = $_SBLOCK = $_TPL = $_SCOOKIE = $_SN = $space = array();
//定义程序目录常量。其中DIRECTORY_SEPARATOR是路径分隔符,linux上就是'/' windows上是'\'
define('S_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
//加载基本的配置文件,用了@符号,达到找不到该文件时在页面不提示错误信息
if(!@include_once(S_ROOT.'./config.php')) {
//如果找不到的话则重定向到安装文件
header("Location: install/index.php");
exit();
}
//通用函数文件,具体函数在介绍时间会一一解释
include_once(S_ROOT.'./source/function_common.php');
//时间microtime()获取含毫秒的时间
$mtime = explode(' ', microtime());
$_SGLOBAL['timestamp'] = $mtime[1];
//$mtime[0]为UNIX时间戳(整形), $mtime[0]为毫秒
$_SGLOBAL['supe_starttime'] = $_SGLOBAL['timestamp'] + $mtime[0];
//get_magic_quotes_gpc检测PHP.INI配置中的魔术引号功能是否打开
$magic_quote = get_magic_quotes_gpc();
if(emptyempty($magic_quote)) {
//如果自动过滤每打开,则对传入的参数进行转义
$_GET = saddslashes($_GET);
$_POST = saddslashes($_POST);
}
//货主站点的URL,其中getsiteurl()是用来获取当前站点的域名
if(emptyempty($_SC['siteurl'])) $_SC['siteurl'] = getsiteurl();
//链接数据库
dbconnect();
//打开缓存文件
foreach (array('config', 'app', 'userapp', 'ad') as $value) {
if(!@include_once(S_ROOT.'./data/data_'.$value.'.php')) {
//如果缓存文件打开失败重建缓存,function_cache.php是包含建立缓存的函数文件
include_once(S_ROOT.'./source/function_cache.php');
$cache_func = $value.'_cache';
//调用相应的函数来生成缓存。
$cache_func();
}
}
//获取COOKIE前缀的

上一个:PHP 字符串编码截取函数(兼容utf-8和gb2312)
下一个:PHPMyAdmin 快速配置方法

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,