<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_magic_quotes_runtime(0);
session_start();
header("Content-Type: text/html; charset=gb2312");
//set current time
$timeStamp = time();
//count running time
$mtime = explode(' ', microtime());
$starttime = $mtime[1] + $mtime[0];
define(HGP_ROOT, substr(dirname(__FILE__), 0, -7));
require_once HGP_ROOT.'include/config.inc.php';
require_once HGP_ROOT.'include/mysql.php';
//实例化数据库类
$mydb = Mysql::getMysqlClass($host,$user, $pass, $dbname);
unset($_ENV,$HTTP_ENV_VARS,$_REQUEST,$HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_POST_FILES,$HTTP_COOKIE_VARS,$host,$user, $pass, $dbname);
require_once HGP_ROOT.'smarty/Smarty.class.php';
//创建Smarty模板对象
$smarty = new Smarty;
$smarty->template_dir = "./templates";
$smarty->compile_dir = "./templates_c";
$smarty->compile_check = true;//为了最大性能,将$compile_check设为"false".
$smarty->debugging = true;
$smarty->left_delimiter = "{?";//默认为{}
$smarty->right_delimiter = "?}";
if(PHP_VERSION < '5.0.0') {
echo "对不起,需要PHP5的环境才能使用本程序!";
}
$PHP_SELF = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];//当前正在执行脚本的文件名
define('IN_BLUE', TRUE);//设置IN_BLUE常量
if (isset($_SESSION) && !is_array($_SESSION))
{
die("Hacking attempt");
}
if(!get_magic_quotes_gpc()) {
add_s($_COOKIE);
add_s($_POST);
add_s($_GET);
}
$_FILES = add_s($_FILES);
$id = (int)$id;
$classid = (int)$classid;
function getip() {
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$realip = $_SERVER['HTTP_CLIENT_IP'];
} else {
$realip = $_SERVER['REMOTE_ADDR'];
}
} else {
if (getenv("HTTP_X_FORWARDED_FOR")) {
$realip = getenv( "HTTP_X_FORWARDED_FOR");
} elseif (getenv("HTTP_CLIENT_IP")) {
$realip = getenv("HTTP_CLIENT_IP");
} else {
$realip = getenv("REMOTE_ADDR");
}
}
return $realip;
}
// 检查邮件
function checkmail($address) {
if(ereg("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$",$address)){
$result=true;
} else {
$result=false;
}
return $result;
}
if($debug){
//定义显示所有错误除了运行NOTICE错误
error_reporting(E_ALL | E_SCRIPT ^ E_NOTICE);
}
$version = "1.0.0";
//分页
function showlist ($count,$page,$url){
if($page > 1)
$re = "\n<a href=\"$url=1\">首页</a> <a href=\"$url=".($page-1)."\">上一页</a>";
else
$re = "\n首页 上一页";
for($i = $page-5; $i < $page + 5 && $i <= $count; $i ++){
if($i > 1){
if($i == $page)
$re .= "\n[$i]";
else
$re .= "\n<a href=\"$url=$i\">$i</a>";
}
}
if($page < $count)
$re .= "\n<a href=\"$url=".($page+1)."\">下一页</a> <a href=\"$url=$count\">尾页</a> ";
else
$re .= "\n下一页 尾页";
return $re;
}
function add_s(&$array){
foreach($array as $key=>$value){
if(!is_array($value)){
$array[$key]=addslashes($value);
}else{
add_s($array[$key]);
}
}
}
?>
<?php
//配制数据库链接
$host = 'localhost';//服务器
$user = 'root';//数据库用户名
$pass = '';//链接密码
$dbname = "web";//数据库名
//table prefix
$db_prefix='hgp_';
//配制站点信息
$websitename = "云南消费网";//站点名称
$websitelogo = "$image_url".'/logo.gif';//站点LOGO
$webmasteremail = "[[email protected]][email protected][/email]";
$is_reg = true;//是否可以注册
$list_num = 15;//分页数
$title_length= 60;//显示标题时的长度
$image_url = "/images";//网站引用图片的位置
$uploadfile_dir = "/uploadfile"; //图片存放目录
$imagewidth = 80; //缩图的宽
$imageheight = 68; //缩图的高
//$debug = true;
?>
<?php
//MySQL数据库操作类,仅能实例化一个对象。
class Mysql{
public $host;
public $user;
public $pass;
public $dbname;
public $link;//链接MySQL后返回的资源
public $query;
public $fetch_array;
public $num_rows;
public $insert_id;
public $version;
private static $a = null;
private function __construct($host, $user, $pass, $dbname){
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->dbname = $dbname;
$this->link = mysql_connect($host, $user, $pass) or die('Could not connect: ' . mysql_error());
mysql_select_db($dbname, $this->link) or die('Could not select database,' . mysql_error());
if($this->version() >'4.1'){
mysql_query("SET NAMES 'utf8'");
}
}
static function getMysqlClass($host, $user, $pass, $dbname){//初始化对象,仅能实例化一个对象。
if ( null == self::$a){
self::$a = new Mysql($host, $user, $pass, $dbname);
}
return self::$a;
}
function query($sql) {//指定的连接标识符关联的服务器中的当前活动数据库发送一条查询。
$this->$query = mysql_query($sql,$this->link);
return $this->$query;
}
function fetch_array($query){//返回根据从结果集取得的行生成的数组,如果没有更多行则返回 FALSE。
$this->fetch_array = mysql_fetch_array($query);
return $this->fetch_array;
}
function num_rows($query) {//返回结果集中行的数目。仅对 SELECT 语句有效。
$this->num_rows = mysql_num_rows($query);
return $this->num_rows;
}
function insert_id() {//返回给定的 link_identifier 中上一步 INSERT 查询中产生的 AUTO_INCREMENT 的 ID 号。
$this->insert_id = mysql_insert_id();
return $this->insert_id;
}
function query_and_fetch($sql){
$query = $this->query($sql);
$this->fetch_array = $this->fetch_array($query);
return $this->fetch_array;
}
function version() {
$this->version = mysql_get_server_info();
return $this->version;
}
private function error_info($info){
echo "$info<br /><b>MySQL error:</b>.mysql_error().<br />.<b>MySQL error number:</b>.intval(mysql_errno())";
exit;
}
}
?>
|