<?php
/********************************************************************
 *                              DirCMS公用文件
 *                            -------------------
 *   begin                : 2009/11/24
 *   copyright            : (C) 2009 DirCMS
 *   email                : uuturn@126.com
 *
 *   $Id: common.inc.php,2009/11/24 15:17 M Exp $
 ********************************************************************/
@error_reporting (E_ALL & ~E_NOTICE & ~E_WARNING);
define('DIRCMS_ROOT', str_replace("\\", '/', substr(dirname(__FILE__), 0, -7)));
define('TIME', time());
define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
define('HTTP_REFERER',isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'');
if(PHP_VERSION < '5.3')
{
	set_magic_quotes_runtime(0);
}
else
{
	ini_set('magic_quotes_runtime',0);
}
ini_set("memory_limit","-1"); // 去除内存限制
ini_set('date.timezone','Asia/Shanghai'); // 时区
header("Content-type:text/html;charset=gbk");
unset($LANG, $HTTP_ENV_VARS, $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_POST_FILES, $HTTP_COOKIE_VARS);

include(DIRCMS_ROOT.'config.inc.php');
if(!DEBUG)
{
	ini_set('display_errors','0');
}

include('global.func.php');
define('IP',getIp());
$black_iplist=explode('|',BLACK_IP);
$guestip=explode('.',IP);
unset($guestip[3]);
$guestip=implode('.',$guestip).'.*';
if(in_array($guestip,$black_iplist) || in_array(IP,$black_iplist)) //2010/10/17
{
	showmsg_nourl('您的IP或IP段已被禁止访问!');
}

define('CURURL',getcururl());
include('template.func.php');
include('mysql.class.php');
$db=new mysql(DB_HOST,DB_USER,DB_PSW,DB_NAME,DB_PCONNECT,DB_CHARSET);
include('cache.class.php');
if(GZIP && extension_loaded('zlib') && function_exists('ob_gzhandler'))
{
	ob_start('ob_gzhandler');
}
else
{
	ob_start();
}

if(function_exists(session_cache_limiter))
{
	session_cache_limiter("private, must-revalidate");
}

include('session.class.php');
$session=new session();
session_set_cookie_params(0,COOKIE_PATH,COOKIE_DOMAIN); 
include(DIRCMS_ROOT.'data/cache/common.cache.php');
if($_REQUEST)
{
	if(MAGIC_QUOTES_GPC)
	{
		$_REQUEST = dircms_stripslashes($_REQUEST);
		if($_COOKIE) $_COOKIE = dircms_stripslashes($_COOKIE);
	}
	else
	{
		$_POST = dircms_addslashes($_POST);
		$_GET = dircms_addslashes($_GET);
		$_COOKIE = dircms_addslashes($_COOKIE);
		@extract($_POST);
		@extract($_GET);
		@extract($_COOKIE);
	}
	extract($db->escape($_REQUEST));
	if($_COOKIE) $db->escape($_COOKIE);
}
$_userid=0;
$_d=hh(POW);
$_username='';
$_isvip=0;
$_groupid=2; //默认为游客
$_gradeid=0;
$dircms_auth=get_cookie('auth');
if($dircms_auth)
{
	$auth_key=md5(AUTH_KEY.$_SERVER['HTTP_USER_AGENT']);
	list($_userid,$_password)=explode("\t", dircms_auth($dircms_auth, 'DECODE', $auth_key));
	$_userid=intval($_userid);
	$sql_member="SELECT * FROM `".DB_PRE."member_cache` WHERE `id`=$_userid";
	$r = $db->fetch_one($sql_member);
	if(!$r)
	{
		$r=$db->fetch_one($sql_member);
	}
	if($r&&$r['password']===$_password)
	{
		if($r['groupid']==3)
		{
			set_cookie('auth', '');
			showmsg('该账号尚未通过审核，暂时不能登录!');
		}
		if($r['islocked']==1)
		{
			set_cookie('auth', '');
			showmsg('该账号已被管理员禁用，暂时不能登录!');
		}
		@extract($r,EXTR_PREFIX_ALL,'');
		$_message=max(0,$_message);
	}
	else
	{
		$_userid=0;
		$_username='';
		$_groupid=2;
		set_cookie('auth','');
	}
	unset($r,$dircms_auth,$dircms_auth_key,$_password,$sql_member);
}
$T=array();
?>