-
Notifications
You must be signed in to change notification settings - Fork 69
/
index.php
285 lines (231 loc) · 10.3 KB
/
index.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php
include('./env.php');
require('./admin/dBconn/database.php');
$new_url = "";
if (isset($_GET)) {
// print_r( $_GET);
$database = new Database();
$db = $database->connect();
foreach ($_GET as $key => $val) {
$u = mysqli_real_escape_string($db, $key);
$new_url = str_replace('/', '', $u);
}
if (strlen($new_url) == "0") {
// Nothing
} else {
$sql = "SELECT * from links WHERE shortenLink='" . $new_url . "'";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
// Update clicks column
$updatedClicks = intval($row['clicks']) + 1;
mysqli_query($db, "UPDATE links SET clicks = '" . $updatedClicks . "' WHERE shortenLink='" . $new_url . "'");
// Update total_clicks table
mysqli_query($db, "UPDATE total_clicks SET total_clicks = total_clicks+1 WHERE id=1");
// Redirect to the original link
header("Location:" . $row['originalLink']);
} else {
if ($new_url != "i") {
header("Location:404");
} else {
header("Location:" . $env_domain);
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<!-- importing the SEO FROM SEO.PHP FILE -->
<?php include './includes/seo.php'; ?>
<!-- Favicons -->
<link href="./assets/img/logo.webp" rel="icon" />
<link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon" />
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,600;1,700&family=Poppins:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&family=Inter:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap"
rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet" />
<link href="assets/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" />
<link href="assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet" />
<link href="assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet" />
<link href="assets/vendor/aos/aos.css" rel="stylesheet" />
<!-- Template Main CSS File -->
<link href="./assets/css/shorty.css" rel="stylesheet" />
<link rel="stylesheet" href="./assets/css/homePage.css">
<link rel="stylesheet" href="./assets/css/sweetAlertButton.css">
<!-- =======================================================
* Template Name: Logis - v1.1.0
* Template URL: https://bootstrapmade.com/logis-bootstrap-logistics-website-template/
* Author: BootstrapMade.com
* License: https://bootstrapmade.com/license/
======================================================== -->
</head>
<?php
// require('./admin/dBconn/database.php');
$database = new Database();
$db = $database->connect();
// echo "aefgsrdhtfjgk,hfrtwerfhjkgfdf".$db;
$random = bin2hex(random_bytes(3));
// $random = '209b01';
$sql = "SELECT * from links WHERE shortenLink='" . $random . "'";
$result = mysqli_query($db, $sql);
$rows = mysqli_num_rows($result);
$avail;
if ($rows == 0) {
$avail = $random;
} else {
$avail = bin2hex(random_bytes(3));
;
}
// echo $avail;
?>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> -->
<body>
<!-- importing the HEADER FROM HEADER PHP FILE -->
<?php include './includes/header.php'; ?>
<!-- ======= Hero Section ======= -->
<section id="hero" class="hero d-flex align-items-center">
<div class="container">
<div class="row gy-4 d-flex justify-content-between">
<div class="col-lg-6 order-lg-1 d-flex flex-column justify-content-center">
<h2 data-aos="fade-up" class="mt-p4">Shorty</h2>
<p data-aos="fade-up" data-aos-delay="100">
To help you grow, scale, and dominate through the power of link management.Whether you’re sharing one link
or millions, Shorty lets you personalize, share, and track your content links, while capturing data with
every click.
</p>
<form class="form-search d-flex align-items-stretch mb-3" data-aos="fade-up" data-aos-delay="200"
method="POST">
<div class="inputIconContainer">
<i class="bi bi-link-45deg"></i>
<input type="text" class="form-control bg-black fontSize9rem pl-35" placeholder="Your Link"
id="originalLink" onkeydown="if(event.keyCode === 13) { event.preventDefault(); generateShorty(); }">
</div>
<button type="button" class="btn btn-primary" onclick="generateShorty()">Shorten</button>
</form>
<div id="generateShorty"></div>
<?php
$database = new Database();
$link = $database->connect();
$visitor_ip = $_SERVER['REMOTE_ADDR'];
// $visitor_ip = "54:54:24:54";
$query = "SELECT * FROM counter_table WHERE ip_address='$visitor_ip'";
$result = mysqli_query($link, $query);
if (!$result) {
die("Retriving Error");
}
$total_visitors = mysqli_num_rows($result);
if ($total_visitors < 1) {
$query = "INSERT INTO counter_table(ip_address) VALUES('$visitor_ip')";
$result = mysqli_query($link, $query);
}
$query = "SELECT * FROM counter_table ";
$result = mysqli_query($link, $query);
if (!$result) {
die("Retriving Error");
}
$total_visitors = mysqli_num_rows($result);
?>
<div class="row gy-4" data-aos="fade-up" data-aos-delay="400">
<div class="col-lg-3 col-6">
<div class="stats-item text-center w-100 h-100">
<span data-purecounter-start="0" data-purecounter-end="<?php echo $total_visitors ?>"
data-purecounter-duration="1" class="purecounter"></span>
<p>Total Visitors</p>
</div>
</div>
<!-- End Stats Item -->
<?php
// require('../admin/dBconn/database.php');
$database = new Database();
$link = $database->connect();
// count total links
$sql = "SELECT COUNT(*) as count_links FROM links";
$result = mysqli_query($link, $sql);
if ($result) {
$row = mysqli_fetch_assoc($result);
$count_links = $row['count_links'];
mysqli_free_result($result);
} else {
echo "Error executing the query: " . mysqli_error($link);
}
?>
<div class="col-lg-3 col-6">
<div class="stats-item text-center w-100 h-100">
<span data-purecounter-start="0" data-purecounter-end="<?php echo $count_links ?>"
data-purecounter-duration="1" class="purecounter"></span>
<p>Shorten Links</p>
</div>
</div>
<?php
// require('../admin/dBconn/database.php');
$database = new Database();
$link = $database->connect();
// count total clicks
$sql = "SELECT * FROM total_clicks where id=1";
$result = mysqli_query($link, $sql);
$row = mysqli_fetch_array($result);
$clicks = $row['total_clicks'];
//count total registered users
$registeredUsers = 0;
$sql = "SELECT COUNT(*) as registeredUsers FROM users";
if ($result = mysqli_query($link, $sql)) {
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$registeredUsers = $row['registeredUsers'];
mysqli_free_result($result);
} else {
echo "<p class='lead'><em>No registered users found.</em></p>";
}
}
?>
<div class="col-lg-3 col-6">
<div class="stats-item text-center w-100 h-100">
<span data-purecounter-start="0" data-purecounter-end="<?php echo $clicks ?>"
data-purecounter-duration="1" class="purecounter"></span>
<p>Total Clicks</p>
</div>
</div>
<div class="col-lg-3 col-6">
<div class="stats-item text-center w-100 h-100">
<span data-purecounter-start="0" data-purecounter-end="<?php echo $registeredUsers ?>"
data-purecounter-duration="1" class="purecounter"></span>
<p>Registered Users</p>
</div>
</div>
<!-- End Stats Item -->
</div>
</div>
<div class="col-lg-5 order-1 order-lg-2 hero-img" data-aos="zoom-out">
<img src="assets/img/hero-img.svg" class="img-fluid mb-3 mb-lg-0 vert-move mobile-size mt-p20" />
</div>
</div>
</div>
</section>
<!-- End Hero Section -->
<!-- importing the FOOTER CODE FROM FOOTER PHP FILE -->
<?php include './includes/footer.php'; ?>
<!-- importing the CHATBOX && SCROLL BUTTON FROM COMMON PHP FILE -->
<?php include './includes/chatbotsidebar.php'; ?>
<div id="preloader"></div>
<!-- Vendor JS Files -->
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/vendor/purecounter/purecounter_vanilla.js"></script>
<script src="assets/vendor/glightbox/js/glightbox.min.js"></script>
<script src="assets/vendor/swiper/swiper-bundle.min.js"></script>
<script src="assets/vendor/aos/aos.js"></script>
<script src="assets/vendor/php-email-form/validate.js"></script>
<!-- Template Main JS File -->
<script src="assets/js/shorty.js"></script>
<script src="js/jquery-3.3.1.min.js"></script>
</body>
</html>