-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.php
139 lines (110 loc) · 4.37 KB
/
config.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
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
<?php
// ==============================
// 📊 DATABASE CONFIGURATION
// ==============================
define("DB_SERVER", "YOUR_DB_SERVER"); // 🌐 Database host (e.g., 'localhost' or '127.0.0.1')
define("DB_USERNAME", "YOUR_DB_USERNAME"); // 👤 Database username (e.g., 'root')
define("DB_PASSWORD", "YOUR_DB_PASSWORD"); // 🔒 Database password (use a strong password)
define("DB_NAME", "click_payment"); // 💾 Database name for storing payment data
// ==============================
// 💸 CLICK PAYMENT INTEGRATION
// ==============================
define("MERCHANT_ID", "YOUR_MERCHANT_ID"); // 🏷️ Unique Merchant ID provided by Click
define("SERVICE_ID", "YOUR_SERVICE_ID"); // 💡 Service ID for your specific /service
define("MERCHANT_USER_ID", "YOUR_MERCHANT_USER_ID"); // 👥 Merchant User ID assigned by Click
define("SECRET_KEY", "YOUR_SECRET_KEY"); // 🛡️ Secret key for API authentication (KEEP IT SAFE!)
define("SITE_PATH", $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST']);
date_default_timezone_set('Etc/GMT-5');
class Database
{
private $conn;
public function __construct()
{
$this->conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
if ($this->conn->connect_error) {
die("Database connection error: " . $this->conn->connect_error);
}
}
public function __destruct()
{
if ($this->conn) {
$this->conn->close();
}
}
public function executeQuery($sql, $params = [], $types = "")
{
$result = $this->conn->prepare($sql);
if (!$result) {
return "SQL error: " . $this->conn->error;
}
if ($params) {
$result->bind_param($types, ...$params);
}
if (!$result->execute()) {
return "Execution error: " . $result->error;
}
return $result;
}
function validate($value)
{
return htmlspecialchars(trim(stripslashes($value)), ENT_QUOTES, 'UTF-8');
}
public function select($table, $columns = "*", $condition = "", $params = [], $types = "")
{
$sql = "SELECT $columns FROM $table" . ($condition ? " WHERE $condition" : "");
$result = $this->executeQuery($sql, $params, $types);
if (is_string($result)) {
return $result;
}
return $result->get_result()->fetch_all(MYSQLI_ASSOC);
}
public function insert($table, $data)
{
$keys = implode(', ', array_keys($data));
$placeholders = implode(', ', array_fill(0, count($data), '?'));
$sql = "INSERT INTO $table ($keys) VALUES ($placeholders)";
$types = str_repeat('s', count($data));
$result = $this->executeQuery($sql, array_values($data), $types);
if (is_string($result)) {
return $result;
}
return $this->conn->insert_id;
}
public function update($table, $data, $condition = "", $params = [], $types = "")
{
$set = implode(", ", array_map(function ($k) {
return "$k = ?";
}, array_keys($data)));
$sql = "UPDATE $table SET $set" . ($condition ? " WHERE $condition" : "");
$types = str_repeat('s', count($data)) . $types;
$result = $this->executeQuery($sql, array_merge(array_values($data), $params), $types);
if (is_string($result)) {
return $result;
}
return $this->conn->affected_rows;
}
public function delete($table, $condition = "", $params = [], $types = "")
{
$sql = "DELETE FROM $table" . ($condition ? " WHERE $condition" : "");
$result = $this->executeQuery($sql, $params, $types);
if (is_string($result)) {
return $result;
}
return $this->conn->affected_rows;
}
public function hashPassword($password)
{
return hash_hmac('sha256', $password, 'iqbolshoh');
}
public function checkUserSession($role)
{
if (($_SESSION['loggedin'] ?? false) !== true || ($_SESSION['role'] ?? '') !== $role) {
header("Location: " . SITE_PATH . "/login/");
exit;
}
if (!$this->select('active_sessions', '*', 'session_token = ?', [session_id()], 's')) {
header("Location: " . SITE_PATH . "/logout/");
exit;
}
}
}