-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
81 lines (78 loc) · 3.37 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
<?php
include "php/config.php";
if (isset($_GET)) {
$new_url = '';
foreach ($_GET as $key=>$val) {
$u = mysqli_real_escape_string($con, $key);
$new_url = str_replace('/', '', $u);
}
$sql = mysqli_query($con, "SELECT full_url FROM url WHERE short_url = '$new_url'");
if (mysqli_num_rows($sql) > 0) {
$clicks_query = mysqli_query($con, "UPDATE url SET clicks = clicks + 1 WHERE short_url = '$new_url'");
if ($clicks_query) {
$full_url = mysqli_fetch_assoc($sql);
header("Location:" . $full_url['full_url']);
}
}
}
$display_count = mysqli_query($con, "SELECT clicks FROM url");
$total = 0;
while ($count = mysqli_fetch_assoc($display_count)) {
$total += $count['clicks'];
}
$display_sql = mysqli_query($con, "SELECT * FROM url ORDER BY id DESC");
$rows = mysqli_fetch_all($display_sql, MYSQLI_ASSOC);
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>URL Shortener</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://unicons.iconscout.com/release/v3.0.6/css/line.css">
</head>
<body>
<div class="wrapper">
<form action="#">
<i class="url-icon uil uil-link"></i>
<input type="text" name="full_url" placeholder="Вставьте длинный URL адрес" required>
<button>Сократить</button>
</form>
<?php if (mysqli_num_rows($display_sql) > 0): ?>
<div class="count">
<span>Всего ссылок: <span><?= mysqli_num_rows($display_sql)?></span> и всего кликов: <span><?= $total?></span></span>
<a href="php/delete.php?delete=all">Очистить все</a>
</div>
<div class="url-zone">
<ul class="title">
<li>Короткий</li>
<li>Оригинальный</li>
<li>Клики</li>
<li>Действие</li>
</ul>
<?php foreach ($rows as $row):?>
<ul class="links">
<li><a href="http://urls/'<?= $row['short_url'] ?>"><?= 'http://urls/'.$row['short_url']?></a></li>
<li><?php if ('http://urls/'.strlen($row['full_url']) > 65) {echo substr($row['full_url'], 0, 65).'...';} else {echo $row['full_url'];}?> </li>
<li><?= $row['clicks']?></li>
<li><a href="php/delete.php?id=<?= $row['id'] ?>">Удалить</a></li>
</ul>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="blur-effect"></div>
<div class="popup-box">
<div class="info">
Ваша короткая ссылка готова! Вы можете отредактировать её сейчас, после сохранения отредактировать не получится!
</div>
<form>
<label>Отредактировать ссылку:</label>
<input type="text" spellcheck="false" value="example.com/xyz123">
<i class="copy-icon uil uil-copy-alt"></i>
<button>Сохранить</button>
</form>
</div>
<script src="script.js"></script>
</body>
</html>