Home  >  Article  >  Backend Development  >  Uchome1.2 1.5 代码学习 common.php_PHP

Uchome1.2 1.5 代码学习 common.php_PHP

WBOY
WBOYOriginal
2016-06-01 12:23:54691browse

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
复制代码 代码如下:
/*
[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前缀的长度,$_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,用来跳转
//登录注册防灌水机
/*
在登录或者注册的时候看到形如:do.php?ac=750e45d29d276b2f86f1445627c08f99的链接
后面的750e45d29d276b2f86f1445627c08f99就是用下面的来获取的。
*/
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;
}
}
}
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn