-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.php
More file actions
142 lines (138 loc) · 4.67 KB
/
Copy pathconfig.php
File metadata and controls
142 lines (138 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
header("Content-type: text/html; charset=utf-8");
define("PANEL_MD5_KEY", "tvkey_"); //面板密码MD5加密秘钥
class Config {
// 私有属性,防止在类外引入存放对象
private static $conn = false;
private $host;
private $port;
private $user;
private $pass;
private $database;
private $charset;
private $link;
// 私有属性,防止在类外使用new关键字实例化对象
private function __construct() {
$this->host = 'localhost'; //数据库服务器
$this->port = '3306'; //数据库端口
$this->user = 'estv'; //数据库帐号
$this->pass = 't4mrFRdkHnX8kC2r'; //数据库密码
$this->database = 'estv'; //数据库名称
$this->charset = 'utf8'; //数据库字符集
$this->db_connect(); //连接数据库
$this->db_charset(); //设置字符集
}
// 防止在类外通过克隆成另一个对象
private function __clone() {
die('此类不允许克隆');
}
// 连接数据库
private function db_connect() {
$this->link = mysqli_connect($this->host . ':' . $this->port, $this->user, $this->pass, $this->database);
if (!$this->link) {
exit("数据库连接失败,请检查错误!");
}
}
// 设置字符集
private function db_charset() {
mysqli_query($this->link, "set names {$this->charset}");
}
// 实例化对象
public static function GetIntance() {
if (self::$conn == false) {
self::$conn = new self;
}
return self::$conn;
}
// 执行SQL语句
public function mQuery($func) {
if ($result = mysqli_query($this->link, $func)) {
return $result;
} else {
return false;
}
}
// 过滤字符串
public function mEscape_string($value) {
if ($result = mysqli_real_escape_string($this->link, $value)) {
return $result;
} else {
return false;
}
}
// 获取全部数组
public function mGetRow($table, $value, $func = "where 1") {
if ($result = $this->mQuery("SELECT $value FROM $table $func")) {
$row = mysqli_fetch_array($result);
return $row;
} else {
return false;
exit("<script>$.alert('mGetRow数据库有错误!$value,$table,$func');</script>");
}
}
// 获取单条数据
public function mGet($table, $value, $func = "where 1") {
if ($result = $this->mQuery("SELECT $value FROM $table $func")) {
$row = mysqli_fetch_array($result);
return $row[0];
} else {
return false;
exit("<script>$.alert('mGet数据库有错误!$value,$table,$func');</script>");
}
}
// 检查全部数组
public function mCheckRow($table, $value, $func = "where 1") {
if ($result = $this->mQuery("SELECT $value FROM $table $func")) {
$row = mysqli_fetch_array($result);
return $row;
} else {
return false;
}
}
// 检查单条数据
public function mCheckOne($table, $value, $func = "where 1") {
if ($result = $this->mQuery("SELECT $value FROM $table $func")) {
$row = mysqli_fetch_array($result);
return $row[0];
} else {
return false;
}
}
// 更新数据
public function mSet($table, $value, $func = "where 1") {
$this->mQuery("UPDATE $table SET $value $func");
}
// 删除数据
public function mDel($table, $func = "where 1") {
$this->mQuery("DELETE FROM $table $func");
}
// 插入数据
public function mInt($table, $name, $value) {
$this->mQuery("INSERT INTO $table ($name) VALUES($value)");
}
// 关闭数据库连接
public function mClose() {
mysqli_close($this->link);
}
// 销毁对象并断开数据库连接
public function __destruct() {
$this->mClose();
}
}
class GetIP {
function getuserip() {
$real_ip = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
$real_ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
foreach ($matches[0] AS $xip) {
if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
$real_ip = $xip;
break;
}
}
}
return $real_ip;
}
}
?>