-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
146 lines (125 loc) · 4.09 KB
/
index.php
File metadata and controls
146 lines (125 loc) · 4.09 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
143
144
145
146
<!DOCTYPE html>
<html>
<head>
<title>Ana Sayfa</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 50px auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}
h1 {
text-align: center;
margin-bottom: 20px;
}
.message {
text-align: center;
margin-bottom: 20px;
}
.links {
text-align: center;
}
.links a {
display: inline-block;
margin: 5px;
padding: 10px 20px;
background-color: #ccc;
color: #fff;
text-decoration: none;
border-radius: 3px;
}
.links a:hover {
background-color: #999;
}
.blog-list {
margin-top: 20px;
}
.blog-item {
margin-bottom: 20px;
border: 1px solid #ccc;
padding: 10px;
border-radius: 3px;
}
.blog-item h2 {
margin-top: 0;
}
.blog-item p {
margin-bottom: 10px;
}
.blog-item a {
display: inline-block;
background-color: #ccc;
color: #fff;
text-decoration: none;
padding: 5px 10px;
border-radius: 3px;
}
.blog-item a:hover {
background-color: #999;
}
</style>
</head>
<body>
<div class="container">
<h1>Ana Sayfa</h1>
<?php
session_start();
if (isset($_SESSION['username'])) {
$username = $_SESSION['username'];
echo "<div class='message'>Hoş geldiniz, $username! Giriş yaptınız.</div>";
echo "<div class='links'>";
echo "<a href='blog/profile.php'>Profil</a>";
echo "<a href='blog/add.php'>Blog Ekle</a>";
// Check if the user is an admin to display the Admin Panel link
if (isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] == 1) {
echo "<a href='/admin'>Admin Paneli</a>";
}
echo "<a href='logout.php'>Çıkış yap</a>";
echo "</div>";
} else {
echo "<div class='message'>Henüz giriş yapmadınız.</div>";
echo "<div class='links'>";
echo "<a href='login.php'>Giriş yap</a>";
echo "<a href='register.php'>Kayıt ol</a>";
echo "</div>";
}
// Blog yazılarını sorgula
require_once "config.php";
$conn = new mysqli($servername, $usernameDB, $passwordDB, $dbname);
if ($conn->connect_error) {
die("Veritabanı bağlantısı başarısız: " . $conn->connect_error);
}
$sql = "SELECT posts.*, categories.name AS category_name
FROM posts
INNER JOIN categories ON posts.category_id = categories.id
ORDER BY created_at DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<div class='blog-list'>";
while ($row = $result->fetch_assoc()) {
echo "<div class='blog-item'>";
echo "<h2>" . $row['title'] . "</h2>";
echo "<p>" . $row['content'] . "</p>";
echo "<p>Kategori: " . $row['category_name'] . "</p>";
echo "<p>Tarih: " . $row['created_at'] . "</p>";
echo "<p><a href='blog/details.php?id=" . $row['id'] . "'>Devamını Oku</a></p>";
echo "</div>";
}
echo "</div>";
} else {
echo "<p>Henüz blog yazısı bulunmamaktadır.</p>";
}
$conn->close();
?>
</div>
</body>
</html>