-
Notifications
You must be signed in to change notification settings - Fork 0
/
toreadsnapshot.php
34 lines (30 loc) · 924 Bytes
/
toreadsnapshot.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
<?php
$config = parse_ini_file('toread.ini');
if (!isset($_GET['id'])) {
header("HTTP/1.0 400 Bad Request");
echo "Please specify a link ID.";
exit;
}
try {
$dbh = new PDO(
"mysql:dbname=" . $config['db_name'] . ";host=" . $config['db_host'],
$config['db_user'], $config['db_pass']);
} catch (Exception $e) {
header("HTTP/1.0 500 Internal Server Error");
echo "Could not connect to database: " . $e->getMessage();
exit;
}
$sql = "SELECT snapshot"
. " FROM links"
. " WHERE id=" . $dbh->quote($_GET['id'])
. " LIMIT 1";
$result = $dbh->query($sql);
$snapshots = $result->fetchAll();
if (empty($snapshots)) {
header("HTTP/1.0 404 Not Found");
echo "Could not find link with ID of " . $_GET['id'];
exit;
}
header('Content-Type: text/html');
echo $snapshots[0]['snapshot'] ? $snapshots[0]['snapshot'] : '<p>No snapshot found.</p>';
?>