-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.php
86 lines (84 loc) · 2.49 KB
/
db.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
session_start();
$connection = NULL;
if ($_SESSION['connection'] && $_SESSION['connection'] != "") {
$connection = $_SESSION['connection'];
}
function DBLogin($db_name) {
$host = "mysql13.000webhost.com";
$user = "a8823305_cjr125";
$password = "________";
$connection = mysql_connect($host, $user, $password);
if (!$connection) {
die('Not connected: '.mysql_error());
}
$db = mysql_select_db($db_name);
$_SESSION['connection'] = $connection;
$_COOKIE['user'] = $user;
$_COOKIE['passwd'] = $password;
}
function DBQuery($qry) {
if ($_SESSION['connection'] && $_SESSION['connection'] != "") {
$connection = $_SESSION['connection'];
}
if (!$connection) {
die('Error - Unable to connect to database');
}
$result = mysql_query($qry, $connection);
if (!$result) {
die('Error: '.mysql_error());
}
return $result;
}
function DBC() {
if ($_SESSION['connection'] && $_SESSION['connection'] != "") {
$connection = $_SESSION['connection'];
}
mysql_close($connection);
}
function mysql_evaluate($query, $default_value="undefined") {
$result = mysql_query($query);
if (mysql_num_rows($result)==0)
return $default_value;
else
return mysql_result($result,0);
}
function mysql_evaluate_array($query) {
$result = mysql_query($query);
$values = array();
for ($i=0; $i<mysql_num_rows($result); ++$i)
array_push($values, mysql_result($result,$i));
return $values;
}
function logged_in() {
if ($_SESSION['connection'] && $_SESSION['connection'] != "") {
$connection = $_SESSION['connection'];
}
$passwd = $_COOKIE["passwd"];
if ($_COOKIE["user"] == null || $_COOKIE["user"] == "") {
return false;
}
else {
DBLogin("a8823305_audio");
$qry = "SELECT username,password FROM users WHERE username = '".$_COOKIE["user"]."'";
$result = DBQuery($qry) or die("Invalid query: ".mysql_error());
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_row($result);
$db_password = $result["password"];
if ($passwd == $db_password) {
DBC();
DBQuery("UPDATE users SET lastLogin = NOW() WHERE username = '".$_COOKIE["user"]."'");
return true;
}
else {
echo "Invalid Username/Password";
DBC();
return false;
}
}
echo "Invalid Username/Password";
DBC();
return false;
}
}
?>