UCHOME的代码还是很不错的,学习一下!
复制代码 代码如下:
@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();
}
?>
@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文件。
@define('IN_UCHOME', TRUE);
//定义一个常量,这个常量表示版本号
define('X_VER', '1.5');
//这个也是一个常量,次版本号
define('X_RELEASE', '20090114');
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前缀的长度,$_SC['cookiepre']是在config.php中定义的cookie函数的前缀名称,$_cookie是存放cookie的数据全局变量数组
$prelength = strlen($_SC['cookiepre']);
foreach($_cookie as $key => $val) {
//判断当前域名下的cookie中属于UCHome的cookie
if(substr($key, 0, $prelength) == $_SC['cookiepre']) {
//对cookie值进行转义
$_Scookie[(substr($key, $prelength))] = emptyempty($magic_quote) ? saddslashes($val) : $val;
}
}
//是否启用GIP压缩传输,这个是用来提高PHP传输速度的。
if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
//初始化
$_SGLOBAL['supe_uid'] = 0; //初始化当前用户的UID
$_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']; //获得上一页的URL,用来跳转
//登录注册防灌水机
if(emptyempty($_SCONFIG['login_action'])) $_SCONFIG['login_action'] = md5('login'.md5($_SCONFIG['sitekey']));
if(emptyempty($_SCONFIG['register_action'])) $_SCONFIG['register_action'] = md5('register'.md5($_SCONFIG['sitekey']));
//整站风格,检查站点模板的路径。此处是default目录,就是我们常用黄色风格的模板路径
if(emptyempty($_SCONFIG['template'])) {
$_SCONFIG['template'] = 'default';
}
//在首页由下角可以自行选择风格的实现就是通过这段。
if($_Scookie['mytemplate']) {
$_Scookie['mytemplate'] = str_replace('.','',trim($_Scookie['mytemplate']));
if(file_exists(S_ROOT.'./template/'.$_Scookie['mytemplate'].'/style.css')) {
$_SCONFIG['template'] = $_Scookie['mytemplate'];
} else {
ssetcookie('mytemplate', '');
}
}
//处理REQUEST_URI,查询(query)的字符串(URL 中第一个问号 ? 之后的内容)。 如为空则为当前页面。
if(!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
if(isset($_SERVER['QUERY_STRING'])) $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
}
//判断用户登录状态
checkauth();
//用户菜单
getuserapp();
//处理UC应用,这个是漫游相关菜单,在此不用解释
$_SGLOBAL['appmenus'] = $_SGLOBAL['appmenu'] = array();
if($_SGLOBAL['app']) {
foreach ($_SGLOBAL['app'] as $value) {
if($value['open']) {
if(emptyempty($_SGLOBAL['appmenu'])) {
$_SGLOBAL['appmenu'] = $value;
} else {
$_SGLOBAL['appmenus'][] = $value;
}
}
}
}
?>



