forked from 51isoft/bnucpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_conn.php
63 lines (61 loc) · 1.99 KB
/
db_conn.php
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
<?php
include("config.php");
include("cookie.php");
function db_connect() {
global $db_addr, $db_user, $db_pass, $db_table;
$con = mysql_connect($db_addr,$db_user,$db_pass);
mysql_query('SET NAMES "utf8"',$con);
if (!$con) {
return false;
}
$sql = mysql_select_db($db_table,$con);
if (!$sql) return false;
}
function convert_str ($str) {
if ($str===null) return "";
if (get_magic_quotes_gpc())
{
return $str;
}
return mysql_real_escape_string ($str);
}
function convert_all_str($arr) {
if ($arr==null) return null;
if (!is_array($arr)) {
return convert_str($arr);
}
foreach ($arr as $k=>$a) {
if (is_array($a)) $arr[$k]=convert_all_str($a);
else if ($k!="op_content") $arr[$k]=convert_str($a);
else $arr[$k]=$a;
}
return $arr;
}
function pwd($a) {
return sha1(md5($a."dfs;j90i")."1p304uijoek");
}
function db_user_match($user, $password) {
//if ($user==""||$password="") return false;
$result = mysql_query("select * from user where username = '$user' and password='$password'");
$row = @mysql_num_rows($result);
if ($row == 1) return true;
else return false;
}
function db_user_exist($username) {
$result = mysql_query("select username from user where username = '$username'");
$row = @mysql_num_rows($result);
if ($row==1) return true;
else return false;
}
function db_user_isroot($username) {
if (!db_user_exist($username)) return false;
$result = mysql_query("select isroot from user where username = '$username'");
$row = mysql_fetch_array($result);
if ($row[0]==1) return true;
else return false;
}
db_connect();
$_COOKIE=convert_all_str($_COOKIE);
$_GET=convert_all_str($_GET);
$_POST=convert_all_str($_POST);
?>