Skip to content

Commit 4e19bf6

Browse files
committed
commit
1 parent c810d0e commit 4e19bf6

File tree

7 files changed

+322
-54
lines changed

7 files changed

+322
-54
lines changed

.gitignore

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# 🛠 Composer `vendor/` papkasi yuklanmaydi
1+
# 🛠 Composer `vendor/` directory should not be included
22
/vendor/
33

4-
# 🛠 `.env` fayli maxfiy ma'lumotlarni saqlaydi
4+
# 🛠 `.env` file contains sensitive information
55
.env
66
.env.local
77
.env.*.local
88

9-
# 🛠 Kesh, loglar va vaqtinchalik fayllar
9+
# 🛠 Cache, logs, and temporary files
1010
/storage/logs/
1111
storage/cache/
1212
storage/framework/sessions/
1313
storage/framework/views/
1414
storage/framework/cache/
1515

16-
# 🛠 `node_modules/` agar frontend ham ishlatilsa
16+
# 🛠 `node_modules/` if frontend is used
1717
/node_modules/
1818

19-
# 🛠 IDE va OS fayllari
19+
# 🛠 IDE and OS files
2020
.idea/
2121
.vscode/
2222
*.swp
@@ -26,6 +26,6 @@ storage/framework/cache/
2626
*.DS_Store
2727
Thumbs.db
2828

29-
# 🛠 Debug va error loglar
29+
# 🛠 Debug and error logs
3030
*.log
31-
php_errorlog
31+
php_errorlog

.htaccess

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
# .htaccess fayli
1+
<IfModule mod_rewrite.c>
22

3-
# ModRewrite ni yoqish
4-
RewriteEngine On
3+
RewriteEngine On
54

6-
# Barcha so'rovlarni public/index.php ga yo'naltirish
7-
RewriteCond %{REQUEST_URI} !^/public/
8-
RewriteRule ^(.*)$ public/$1 [L]
5+
# Redirect requests not pointing to /public, /assets (for specific file types), to /public
6+
RewriteCond %{REQUEST_URI} !^/public
7+
RewriteCond %{REQUEST_URI} !^/assets/.*\.(css|js|png|jpg|jpeg|svg|json)$ [NC]
8+
RewriteRule ^(.*)$ /public/$1 [L]
99

10-
# Agar fayl yoki papka mavjud bo'lmasa, index.php ga yo'naltirish
11-
RewriteCond %{REQUEST_FILENAME} !-f
12-
RewriteCond %{REQUEST_FILENAME} !-d
13-
RewriteRule ^(.*)$ public/index.php [QSA,L]
10+
# Allow access to specific file types in /assets for all IPs
11+
RewriteCond %{REQUEST_URI} ^/assets/.*\.(css|js|png|jpg|jpeg|svg|json)$ [NC]
12+
RewriteRule ^(.*)$ - [L]
1413

15-
# Favicon uchun so'rovlarni boshqarish
16-
RewriteCond %{REQUEST_FILENAME} !-f
17-
RewriteRule ^favicon\.ico$ public/assets/images/favicon.ico [L]
14+
# Deny access to /assets for all other files except for IP 127.0.0.1
15+
RewriteCond %{REQUEST_URI} ^/assets
16+
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
17+
RewriteRule ^(.*)$ - [R=404,L]
1818

19-
# CSS, JS va boshqa statik fayllarga kirishni ruxsat berish
20-
RewriteCond %{REQUEST_URI} \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ [NC]
21-
RewriteRule ^(.*)$ public/assets/$1 [L]
19+
# Custom error documents
20+
ErrorDocument 400 /public/errors.php?error=400
21+
ErrorDocument 401 /public/errors.php?error=401
22+
ErrorDocument 403 /public/errors.php?error=403
23+
ErrorDocument 404 /public/errors.php?error=404
24+
ErrorDocument 500 /public/errors.php?error=500
2225

23-
# Index faylini ko'rsatish
24-
DirectoryIndex public/index.php
25-
26-
# Xatolik sahifalarini sozlash
27-
ErrorDocument 404 /public/index.php
28-
ErrorDocument 403 /public/index.php
29-
ErrorDocument 500 /public/index.php
26+
</IfModule>

app/core/Database.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,32 +125,31 @@ public function count($table, $condition = "", $params = [])
125125
)->fetch()['total'];
126126
}
127127

128+
/**
129+
* Generate CSRF token and store it in session.
130+
*
131+
* @return string The generated CSRF token.
132+
*/
133+
134+
public function generate_csrf_token()
135+
{
136+
return $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
137+
}
138+
128139
// ============================== //
129140
// TRANSACTION METHODS //
130141
// ============================== //
131142

132-
/**
133-
* Starts a new database transaction.
134-
* Transactions allow multiple queries to be executed safely.
135-
*/
136143
public function beginTransaction()
137144
{
138145
$this->conn->beginTransaction();
139146
}
140147

141-
/**
142-
* Commits the current transaction.
143-
* This ensures that all queries within the transaction are saved to the database.
144-
*/
145148
public function commit()
146149
{
147150
$this->conn->commit();
148151
}
149152

150-
/**
151-
* Rolls back the current transaction.
152-
* This cancels all queries within the transaction if an error occurs.
153-
*/
154153
public function rollback()
155154
{
156155
$this->conn->rollBack();

assets/css/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h1 {
2+
color: red;
3+
}

public/errors.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
$errors = [
3+
400 => [
4+
'title' => 'Bad Request',
5+
'icon' => 'fas fa-exclamation-triangle',
6+
'description' => 'Oops! Your request is invalid or malformed.'
7+
],
8+
401 => [
9+
'title' => 'Unauthorized',
10+
'icon' => 'fas fa-lock',
11+
'description' => 'Oops! You are not authorized to access this page.'
12+
],
13+
403 => [
14+
'title' => 'Forbidden',
15+
'icon' => 'fas fa-ban',
16+
'description' => 'Oops! You don\'t have permission to access this page.'
17+
],
18+
404 => [
19+
'title' => 'Page Not Found',
20+
'icon' => 'fas fa-exclamation-circle',
21+
'description' => 'Oops! The page you\'re looking for doesn\'t exist.'
22+
],
23+
500 => [
24+
'title' => 'Internal Server Error',
25+
'icon' => 'fas fa-server',
26+
'description' => 'Oops! Something went wrong on our server. Please try again later.'
27+
],
28+
];
29+
30+
$error_code = $_GET['error'] ?? 404;
31+
$error = $errors[$error_code] ?? $errors[404];
32+
?>
33+
34+
<!DOCTYPE html>
35+
<html lang="en">
36+
37+
<head>
38+
<meta charset="UTF-8">
39+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
40+
<title><?= $error['title'] ?></title>
41+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
42+
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
43+
<style>
44+
body {
45+
background-color: #f8d7da;
46+
}
47+
48+
.error-container {
49+
max-width: 600px;
50+
margin: 0 auto;
51+
padding: 20px;
52+
text-align: center;
53+
}
54+
55+
.error-icon {
56+
font-size: 100px;
57+
color: #dc3545;
58+
margin-bottom: 20px;
59+
}
60+
61+
.error-title {
62+
font-size: 72px;
63+
color: #dc3545;
64+
margin-bottom: 10px;
65+
}
66+
67+
.error-message {
68+
font-size: 24px;
69+
color: #721c24;
70+
margin-bottom: 20px;
71+
}
72+
73+
.btn-home {
74+
margin-top: 20px;
75+
padding: 10px 20px;
76+
font-size: 18px;
77+
color: #ffffff;
78+
background-color: #dc3545;
79+
border-color: #dc3545;
80+
transition: background-color 0.3s, border-color 0.3s;
81+
}
82+
83+
.btn-home:hover {
84+
background-color: #c82333;
85+
border-color: #bd2130;
86+
}
87+
</style>
88+
</head>
89+
90+
<body>
91+
<div class="container mt-5">
92+
<div class="error-container">
93+
<div class="error-icon">
94+
<i class="<?= $error['icon'] ?>"></i>
95+
</div>
96+
<h1 class="error-title"><?= $error_code ?></h1>
97+
<h2 class="display-4"><?= $error['title'] ?></h2>
98+
<p class="error-message"><?= $error['description'] ?></p>
99+
<a href="/" class="btn btn-lg btn-home">Go to Homepage</a>
100+
</div>
101+
</div>
102+
</body>
103+
104+
</html>

public/favicon.ico

4.52 KB
Binary file not shown.

0 commit comments

Comments
 (0)