-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.php
39 lines (32 loc) · 1.12 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
<?php
try {
$dbPath = __DIR__.'/data/database.sqlite';
$dbh = new PDO('sqlite:'.$dbPath);
} catch(PDOException $e) {
die('Panic! '.$e->getMessage());
}
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if ($uri == '/' || $uri == '') {
echo '<h1>PHP Camp!</h1>';
echo '<a href="/attendees">See the attendees</a>';
if (isset($_GET['name'])) {
echo sprintf('<p>Oh, and hello %s!</p>', $_GET['name']);
}
} elseif ($uri == '/attendees') {
$sql = 'SELECT * FROM php_camp';
echo '<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />';
echo '<h1>PHP Camp Attendees</h1>';
echo '<table class="table" style="width: 300px;">';
foreach ($dbh->query($sql) as $row) {
echo sprintf(
'<tr><td style="font-size: 24px;">%s</td><td><img src="%s" height="120" /></td></tr>',
$row['attendee'],
$row['avatar_url']
);
}
echo '</table>';
} else {
header("HTTP/1.1 404 Not Found");
echo '<h1>404 Page not Found</h1>';
echo '<p>Find a boy (or girl) scout - they can fix this!</p>';
}