-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
102 lines (94 loc) · 3.3 KB
/
Copy pathsearch.php
File metadata and controls
102 lines (94 loc) · 3.3 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
<!-- start header -->
<?php
$pageTitle = "Search";
include "./components/header.php";
?>
<!-- end header -->
<!-- main-section start -->
<div class="container">
<div class="heading_container mb-3 mt-3">
<h2>
<?php
if (isset($_GET['search'])) {
$search = $_GET['search'];
echo "SEARCH FOR '" . htmlspecialchars($search) . "' IS";
}
?>
</h2>
</div>
<?php
if (isset($_GET['search'])) {
$search = $_GET['search'];
require "./database/database.php";
$cleanSearch = strtolower(trim($search));
$cacheKey = "search_results_" . md5($cleanSearch);
$searchItems = [];
$fromCache = false;
if ($redis) {
$cachedData = $redis->get($cacheKey);
if ($cachedData) {
$searchItems = json_decode($cachedData, true);
$fromCache = true;
}
}
if (!$fromCache) {
$safeSearch = $conn->real_escape_string($search);
$searchList = "SELECT * FROM `thread` JOIN registration ON thread.register_id = registration.id where thread.thread_name LIKE '%$safeSearch%';";
$result = $conn->query($searchList);
if ($result && $result->num_rows > 0) {
$searchItems = $result->fetch_all(MYSQLI_ASSOC);
if ($redis) {
$redis->setex($cacheKey, 300, json_encode($searchItems));
}
}
}
if (count($searchItems) > 0) {
foreach ($searchItems as $item) {
echo '<div class="container mb-3 pt-2 pb-2" style="background-color: #1cbbb4;border-radius:5px;">
<div class="row no-gutters align-items-center">
<div class="col-auto">
<img src="./static/images/user.png" alt="" height="50" width="50">
</div>
<div class="col ml-2">
<div>
' . htmlspecialchars($item['username']) . '
</div>
<div class="d-flex justify-content-between align-items-center">
<div>
' . htmlspecialchars($item['email']) . '
</div>
<div>
' . substr($item['created_at'], 0, 10) . '
</div>
</div>
</div>
</div>
<div class="container mt-2">
<a style="color:black;font-size:1.5rem;" href="comments.php?id=' . $item['thread_id'] . '" >
' . htmlspecialchars($item['thread_name']) . '
</a>
<div>';
if (strlen($item['thread_description']) <= 20) {
echo htmlspecialchars($item['thread_description']);
} else {
echo htmlspecialchars(substr($item['thread_description'], 0, 20)) . '...';
}
echo '</div></div>
</div>';
}
} else {
echo '
<div class="alert alert-dark" role="alert">
There is No Items similar to ' . htmlspecialchars($_GET['search']) . ' !!!
</div>
';
}
}
?>
</div>
<!-- end main-session -->
<!-- start Footer -->
<?php
include "./components/footer.php";
?>
<!-- end footer -->