/*
想法:现在网上一般都用Discuz!2.0版的,所以现在开始写 它的文件的解释。
作者:流水
网站:www.uplinux.com
文件:common.php--它是非常重要的文件,主要的前期工作 都在这个文件执行。
*/
/*系统关于文件错的处理设置*/
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//error_reporting(E_ALL); //debug
//require './include/debugger.php'; //debug
/*可能用于时间变量的赋值*/
$mtime = explode(' ', microtime());
$starttime = $mtime[1] + $mtime[0];
define('IN_DISCUZ', TRUE);
set_magic_quotes_runtime(0);
/*得到当前访问的页面--虚拟路径+当前的页面,或者直接是当前页面*/
$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'] ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
/*得到当前的绝对路径,有一个不清楚的地方,在WIN下c:\\就换成了c:/而正确的是c:\*/
$SCRIPT_FILENAME = str_replace('\\\\', '/', ($HTTP_SERVER_VARS['PATH_TRANSLATED'] ? $HTTP_SERVER_VARS['PATH_TRANSLATED'] : $HTTP_SERVER_VARS['SCRIPT_FILENAME']));
/*得到当前的URL,没有页面值*/
$boardurl = 'http://'.$HTTP_SERVER_VARS['HTTP_HOST'].substr($PHP_SELF, 0, strrpos($PHP_SELF, '/') + 1);
/*得到当前的虚拟目录*/
$discuz_root = substr($SCRIPT_FILENAME, 0, strrpos($SCRIPT_FILENAME, '/') + 1);
/*1.基本配置文件 2、常用的函数文件,以后会单独给大家说明书 3、数据库处理文件,是一个类*/
require $discuz_root.'./config.php';
require $discuz_root.'./include/global.php';
require $discuz_root.'./include/db_'.$database.'.php';
/*1.time()取得是距离1979年1月1日的秒数和microtime()不同,具体内容可看手册
2.
3.*/
$timestamp = time();
$magic_quotes_gpc = get_magic_quotes_gpc();
$register_globals = @ini_get('register_globals');
/*1、 2、作为中转数组变量*/
$url_redirect = '';
$_DSESSION = $_DCACHE = array();
/*得到访问者的IP*/
if(getenv('HTTP_CLIENT_IP')) {
$onlineip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR')) {
$onlineip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR')) {
$onlineip = getenv('REMOTE_ADDR');
} else {
$onlineip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
}
/*1、 2、用table_把在安装时设置的表前缀代替 3、把$tablename变量空间释放*/
$tables = array('attachments', 'announcements', 'banned', 'favorites', 'forumlinks', 'forums', 'karmalog',
'members', 'memo', 'posts', 'searchindex', 'sessions', 'settings', 'smilies', 'stats', 'styles',
'stylevars', 'subscriptions', 'templates', 'threads', 'pm', 'usergroups', 'words', 'buddys');
foreach($tables as $tablename) {
${'table_'.$tablename} = $tablepre.$tablename;
}
unset($tablename);
/*数据库的连接*/
$db = new dbstuff;
$db->connect($dbhost, $dbuser, $dbpw, $pconnect);
$db->select_db($dbname);
unset($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
/*1、得到当前的页面值 2、得到没有.php当前页面的值*/
$currscript = basename($PHP_SELF);
$currscript = substr($currscript, 0, strpos($currscript, '.php'));
/*说明一下/forumdata/cache是作为数据库内容的缓存,它们都是数组形式,/forumdata/template是作为模板页面的缓存
*1、加载cache_settings.php文件,它是论坛页面的基本设置,2、加载你访问页面的内容 */
$cacheexists = (@include $discuz_root.'./forumdata/cache/cache_settings.php') ? 1 : 0;
if(in_array($currscript, array('index', 'forumdisplay', 'viewthread', 'post', 'search', 'pm'))) {
$cacheexists = ($cacheexists && @include $discuz_root.'./forumdata/cache/cache_'.$currscript.'.php') ? 1 : 0;
}
/*1、把数组变量导入成单个变量的形式 2、得到sid值*/
@extract($_DCACHE['settings']);
$sid = isset($HTTP_GET_VARS['sid']) ? $HTTP_GET_VARS['sid'] :
(isset($HTTP_POST_VARS['sid']) ? $HTTP_POST_VARS['sid'] :
$HTTP_COOKIE_VARS['sid']);
/*对变理进行反斜线处理*/
$discuz_user = daddslashes($HTTP_COOKIE_VARS['_discuz_user']);
$discuz_pw = daddslashes($HTTP_COOKIE_VARS['_discuz_pw']);
$newpm = $ipbanned = $sessionexists = 0;
/*-处理当你不是第一次登陆的情况-
--1当你是会员时就进行if语句中的处理,查询会员的基本信息,当是游客时进行else语句处理--1
--2对上面的查询进行进一步的处理,并且把$sessionexists赋值为1,如果是会员的话执行if,再进行一次查询,并用array_merge把前面相同的值覆盖,是游客的话,执行else,也是进行一次查询,执行clearcookies()函数它是在global.php文件中,设置cookie文件中的值--2*/
if($sid) {-
if($discuz_user) {--1
$query = $db->query("SELECT s.sid, s.groupid, s.styleid, s.groupid, m.username AS discuz_user, m.password AS discuz_pw, m.status, m.email, m.timeoffset, m.tpp, m.ppp, m.credit, m.timeformat, m.dateformat, m.signature, m.lastvisit, m.newpm
FROM $table_sessions s, $table_members m WHERE m.username=s.username AND s.sid='$sid' AND s.ip='$onlineip' AND ('$discuz_user'='' OR ('$discuz_user'<>'' AND m.username='$discuz_user' AND m.password='$discuz_pw'))");
}else {
$query = $db->query("SELECT sid, status, username AS sessionuser, groupid, styleid FROM $table_sessions WHERE sid='$sid' AND ip='$onlineip'");
}--1
if($_DSESSION = $db->fetch_array($query)) {--2
$sessionexists = 1;
if(!empty($_DSESSION['sessionuser'])) {
$query = $db->query("SELECT m.username AS discuz_user, m.password AS discuz_pw, m.status, m.email, m.timeoffset, m.tpp, m.ppp, m.credit, m.timeformat, m.dateformat, m.signature, m.avatar, m.lastvisit, m.newpm FROM $table_members m WHERE username='$_DSESSION[sessionuser]'");
$_DSESSION = array_merge($_DSESSION, $db->fetch_array($query));
}
} else {
$query = $db->query("SELECT sid, status, groupid, styleid FROM $table_sessions WHERE sid='$sid' AND ip='$onlineip'");
if($_DSESSION = $db->fetch_array($query)) {
clearcookies();
$sessionexists = 1;
}
}--2
}-
/*当你是第一次访问论坛时,开执行下面的语句
--1判断你的IP地址是否被禁止--1
--2判断你是否是会员,如果不是重新设置cookie文件中的值--2
函数random生成一个sid值
*/
if(empty($sessionexists)) {-
$ips = explode('.', $onlineip);
$query = $db->query("SELECT COUNT(*) FROM $table_banned WHERE (ip1='$ips[0]' OR ip1='-1') AND (ip2='$ips[1]' OR ip2='-1') AND (ip3='$ips[2]' OR ip3='-1') AND (ip4='$ips[3]' OR ip4='-1')");
if($db->result($query, 0)) {--1
$statusverify = 'u.status=\'IPBanned\'';
$ipbanned = 1;
} else {
$statusverify = 'u.status=m.status';
}--1
if($discuz_user) {--2
$query = $db->query("SELECT m.username as discuz_user, m.password as discuz_pw, m.status, m.email, m.timeoffset, m.styleid, m.tpp, m.ppp, m.credit, m.timeformat, m.dateformat, m.signature, m.avatar, m.lastvisit, m.newpm, u.groupid, u.specifiedusers LIKE '%\t$discuz_user\t%' AS specifieduser
FROM $table_members m LEFT JOIN $table_usergroups u ON u.specifiedusers LIKE '%\t$discuz_user\t%' OR ($statusverify AND ((u.creditshigher='0' AND u.creditslower='0' AND u.specifiedusers='') OR (m.credit>=u.creditshigher AND m.credit<u.creditslower)))
WHERE username='$discuz_user' AND password='$discuz_pw' ORDER BY specifieduser DESC");
if(!($_DSESSION = $db->fetch_array($query))) {
clearcookies();
}
}--2
$_DSESSION['sid'] = random(8);
}-
/*设置你访问论坛的形式,在usergroups表中可以查找到*/
if(!isset($discuz_user) && empty($_DSESSION['groupid'])) {
$_DSESSION['groupid'] = empty($ipbanned) ? 1 : 2;
}
/*设置你最后登陆的时间值,如果超过在线时间就再进行一次赋值*/
if(!isset($_DSESSION['lastvisit'])) {
$_DSESSION['lastvisit'] = $HTTP_COOKIE_VARS['lastvisit'] ? $HTTP_COOKIE_VARS['lastvisit'] : $timestamp - 86400;
} else {
if($timestamp - $_DSESSION['lastvisit'] - $onlinehold < 0) {
$_DSESSION['lastvisit'] = $HTTP_COOKIE_VARS['lastvisit'];
} else {
$_DSESSION['lastvisit'] -= $onlinehold;
setcookie('lastvisit', $_DSESSION['lastvisit'], $timestamp + 3600, $cookiepath, $cookiedomain);
}
}
/**/
@extract($_DSESSION);
/*当你第一次访问时,用updatesession()处理你的信息*/
if(empty($sessionexists)) {
$discuz_action = 0;
updatesession();
}
setcookie('sid', $sid, 0, $cookiepath, $cookiedomain);
$discuz_userss = stripslashes($discuz_user);
$credit = intval($credit);
/*关于上传文件的处理*/
if(!$register_globals || !$magic_quotes_gpc) {
@extract(daddslashes($HTTP_POST_VARS));
@extract(daddslashes($HTTP_GET_VARS));
if(!$register_globals) {
foreach($HTTP_POST_FILES as $key => $val) {
$$key = $val['tmp_name'];
${$key.'_name'} = $val['name'];
${$key.'_size'} = $val['size'];
${$key.'_type'} = $val['type'];
}
}
}
/**/
if($statstatus) {
require $discuz_root.'./include/counter.php';
}
/*设置论坛每页显示的主题数$tpp和每页显示贴数$ppp*/
$tpp = $tpp ? $tpp : $topicperpage;
$ppp = $ppp ? $ppp : $postperpage;
/*得到当访问的页面值,把sid去掉*/
if(empty($referer) && isset($HTTP_SERVER_VARS['HTTP_REFERER'])) {
$referer = preg_replace("/(?:([\?&]sid\=[a-z0-9]{8}&?))/i", '', $HTTP_SERVER_VARS['HTTP_REFERER']);
$referer = substr($referer, -1) == '?' ? substr($referer, 0, -1) : $referer;
}
/*显示论坛和帖子*/
if(isset($tid)){
$query = $db->query("SELECT f.* FROM $table_forums f, $table_threads t WHERE t.tid='$tid' AND f.fid=t.fid LIMIT 0, 1");
$forum = $db->fetch_array($query);
$fid = $forum['fid'];
} elseif(isset($fid)) {
$query = $db->query("SELECT * FROM $table_forums WHERE fid='$fid'");
$forum = $db->fetch_array($query);
}
/*显示论坛的类型*/
$styleid = !empty($HTTP_GET_VARS['styleid']) ? $HTTP_GET_VARS['styleid'] :
(!empty($HTTP_POST_VARS['styleid']) ? $HTTP_POST_VARS['styleid'] :
(!empty($_DSESSION['styleid']) ? $_DSESSION['styleid'] :
$_DCACHE['settings']['styleid']));
/*加载基本页面常量*/
if(@!include $discuz_root.'./forumdata/cache/style_'.(!empty($forum['styleid']) ? $forum['styleid'] : $styleid).'.php') {
$styleid = $_DCACHE['settings']['styleid'];
$cacheexists = ($cacheexists && @include $discuz_root.'./forumdata/cache/style_'.$styleid.'.php') ? 1 : 0;
}
/*加载各种用户状态的值*/
$cacheexists = ($cacheexists && @include $discuz_root.'./forumdata/cache/usergroup_'.$groupid.'.php') ? 1 : 0;
/*生成缓存文件,以后详细讲解cahce.php*/
if(!$cacheexists) {
require $discuz_root.'./include/cache.php';
updatecache();
discuz_exit('Caches successfully created, please refresh.');
}
/**/
if($headercharset) {
header('Content-Type: text/html; charset='.CHARSET);
}
/*将输出缓存打开*/
$gzipcompress ? ob_start('ob_gzhandler') : ob_start();
/*关于插件*/
$pluglink = '';
if(!empty($plugins) && is_array($plugins)) {
foreach($plugins as $plugarray) {
if($plugarray['name'] && $plugarray['url']) {
$pluglink .= '| <a href="'.$plugarray['url'].'"><font class="navtd">'.$plugarray['name'].'</font></a> ';
}
}
}
/*查看一下论坛是否允许访问,并且看一下论坛是关闭*/
if(isset($allowvisit) && $allowvisit == 0) {
setcookie('_discuz_user', $discuz_user, 86400 * 365, $cookiepath, $cookiedomain);
setcookie('_discuz_pw', $discuz_pw, 86400 * 365, $cookiepath, $cookiedomain);
showmessage('user_banned');
} elseif(isset($action) && $action != 'login' && $bbclosed && !$isadmin) {
clearcookies();
showmessage($closedreason ? $closedreason : 'Sorry, this forum is temporarily closed.');
}
本文地址:http://com.8s8s.com/it/it26582.htm