-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·64 lines (58 loc) · 2.2 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
<?php
require "autoload.php";
require "src/html/header.php";
require "src/html/footer.php";
$argument = preg_split('/[\/].*[?]/', $_SERVER["REQUEST_URI"]);
if (sizeof($argument) === 2) {
$argument = $argument[1];
$dsn = "mysql:host=" . env("mysql_address") . ";dbname=" . env("mysql_database") . ";port=".env("mysql_port").";charset=utf8mb4";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, env("mysql_username"), env("mysql_password"), $options);
$pdo->exec("use ". env("mysql_database"));
} catch (\PDOException $e) {
die($e->getMessage()." ".(int)$e->getCode());
}
$req = $pdo->prepare("select * from LONGR where id = ?");
$req->execute([$argument]);
$row = $req->fetch();
if (isset($row['text'])) {
add_header();
?>
<center>
<div class="message">
<?= $row['text'] ?>
</div>
</center>
<?php
add_footer("<small class=\"grey from\">Message uploaded from " . $row['country'] . "</small><br>");
die();
} else {
add_header();
?>
<center>
<h1>This message doesn't exist.</h1>
<a href="<?= env("ext_url") ?>" class="btn goback">Go back</a>
</center>
<?php
}
} else {
add_header();
?>
<div class="center"><h1>Turn your giant messages into small links.</h1></div>
<form method="post" action="<?= env('ext_url') ?>/message.php">
<center>
<div id="epiceditor">
<textarea placeholder="Put your message here" id="message" name="message" maxlength="<?= env("char_per_msg") ?>"required></textarea>
</div>
<small class="grey">You can't put messages longer than <?= env("char_per_msg") ?> characters</small>
<input type="submit" value="Transformation" class="btn">
</center>
</form>
<?php
}
add_footer();