Add guestbook
This commit is contained in:
parent
f71c6421f3
commit
d32f9aeafd
3 changed files with 137 additions and 2 deletions
74
guestbook/index.php
Executable file
74
guestbook/index.php
Executable file
|
@ -0,0 +1,74 @@
|
|||
<?php $db = new PDO("sqlite:/mnt/data1/webdata/floppydisk/guestbook.db"); ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Global -->
|
||||
<?php require('../inc/head.html'); ?>
|
||||
|
||||
<!-- Page-specific -->
|
||||
<title>Bookmarks</title>
|
||||
<!--<link rel="shortcut icon" href="../res/img/icons/ico/calc.ico" type="image/x-icon">-->
|
||||
<meta property="og:title" content="Guestbook">
|
||||
<meta property="og:description" content="h">
|
||||
<!--<meta property="og:image" content="/res/img/icons/png/computer.png">-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<?php require('../inc/nav.php') ?>
|
||||
|
||||
<div id="pagebody">
|
||||
<div id="content">
|
||||
<br>
|
||||
<form action="submit.php" method="post">
|
||||
<b>Nickname:</b> <input type="text" name="name"><br>
|
||||
<b>Message:</b> <textarea name="message"></textarea><br>
|
||||
<b>Show IP:</b><input type="checkbox" name="showip" value="yes"><br>
|
||||
<b>Show info:</b><input type="checkbox" name="showinfo" value="yes"><br>
|
||||
<br><input type="submit">
|
||||
</form>
|
||||
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
// Pain
|
||||
$count_query = $db->prepare('SELECT COUNT(*) FROM Entries');
|
||||
$count_query->execute();
|
||||
$count = $count_query->fetch()[0];
|
||||
echo '<h1>Entries <small>(' . $count . ' total)</small></h1>';
|
||||
// Prepare SELECT statement.
|
||||
$select = "SELECT name, message, show_info, show_ip, ip, submitted, browser_info FROM Entries ORDER BY id DESC";
|
||||
$stmt = $db->prepare($select);
|
||||
|
||||
// Execute statement.
|
||||
$stmt->execute(); // ID between 1 and 3.
|
||||
|
||||
// Get the results.
|
||||
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach($results as $row) {
|
||||
echo '<table border="1" width="500"><tr><td><pre>';
|
||||
$submittedRaw = $row['submitted'];
|
||||
$submittedDT = new DateTime("@$submittedRaw");
|
||||
$submitted = $submittedDT->format('H:i:s - Y-m-d');
|
||||
|
||||
$browser = get_browser(null, true);
|
||||
$sys = $browser['parent'] . ' (' . $browser['platform_description'] . ' ' . $browser['platform_version'] . ')';
|
||||
|
||||
echo 'Name: ' . $row['name'] . PHP_EOL;
|
||||
if ($row['show_ip']) echo 'IP: ' . $row['ip'] . PHP_EOL;
|
||||
if ($row['show_info']) echo 'Sys: ' . $row['browser_info'] . PHP_EOL;
|
||||
echo 'Date: ' . $submitted . PHP_EOL . PHP_EOL;
|
||||
echo $row['message'];
|
||||
echo '</pre></td></tr></table><br>';
|
||||
}
|
||||
?>
|
||||
</>
|
||||
</div> <!-- content -->
|
||||
|
||||
<div id="footer" class="pagefooter">
|
||||
<!-- Created <span class="date">Sat 26 Mar 2011 03:11:41 PM CET</span> -->
|
||||
</div> <!-- footer -->
|
||||
</div> <!-- pagebody -->
|
||||
</div> <!-- page -->
|
||||
</body>
|
||||
</html>
|
60
guestbook/submit.php
Executable file
60
guestbook/submit.php
Executable file
|
@ -0,0 +1,60 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Global -->
|
||||
<?php require('../inc/head.html'); ?>
|
||||
|
||||
<!-- Page-specific -->
|
||||
<title>Bookmarks</title>
|
||||
<!--<link rel="shortcut icon" href="../res/img/icons/ico/calc.ico" type="image/x-icon">-->
|
||||
<!--<meta property="og:image" content="/res/img/icons/png/computer.png">-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<?php require('../inc/nav.php') ?>
|
||||
|
||||
<div id="pagebody">
|
||||
<div id="content">
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
// Open the DB
|
||||
if ($_POST['name'] === "" || $_POST['message'] === "") {
|
||||
echo '<b>You must provide both a name and message!</b>';
|
||||
} else {
|
||||
$db = new PDO("sqlite:/mnt/data1/webdata/floppydisk/guestbook.db");
|
||||
$name = $_POST["name"];
|
||||
$msg = strip_tags($_POST["message"]);
|
||||
$showinfo = isset($_POST["showinfo"]) ? true : false;
|
||||
$showip = isset($_POST["showip"]) ? true : false;
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
$browser = get_browser(null, true);
|
||||
$sys = $browser['parent'] . ' (' . $browser['platform_description'] . ' ' . $browser['platform_version'] . ')';
|
||||
|
||||
$data = array('name' => $name, 'message' => $msg, 'show_info' => $showinfo, 'show_ip' => $showip, 'ip' => $ip, 'submitted' => time(), 'sys' => $sys);
|
||||
|
||||
$insert = "INSERT INTO Entries (name, message, show_info, show_ip, ip, submitted, browser_info) VALUES (:name, :message, :show_info, :show_ip, :ip, :submitted, :browser)";
|
||||
$stmt = $db->prepare($insert);
|
||||
$stmt->bindParam(':name', $data['name'], PDO::PARAM_STR);
|
||||
$stmt->bindParam(':message', $data['message'], PDO::PARAM_STR);
|
||||
$stmt->bindParam(':show_info', $data['show_info'], PDO::PARAM_STR);
|
||||
$stmt->bindParam(':show_ip', $data['show_ip'], PDO::PARAM_STR);
|
||||
$stmt->bindParam(':ip', $data['ip'], PDO::PARAM_STR);
|
||||
$stmt->bindParam(':submitted', $data['submitted'], PDO::PARAM_STR);
|
||||
$stmt->bindParam(':browser', $data['sys'], PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
echo '<b>Success!</b>';
|
||||
}
|
||||
?><br><br>
|
||||
<a href="./">Back</a>
|
||||
</div> <!-- content -->
|
||||
|
||||
<div id="footer" class="pagefooter">
|
||||
<!-- Created <span class="date">Sat 26 Mar 2011 03:11:41 PM CET</span> -->
|
||||
</div> <!-- footer -->
|
||||
</div> <!-- pagebody -->
|
||||
</div> <!-- page -->
|
||||
</body>
|
||||
</html>
|
|
@ -6,13 +6,14 @@
|
|||
<a href="/projects/">projects</a> |
|
||||
<a href="/pics/">pics</a> |-->
|
||||
<!--<a href="/dog/">dog</a> |-->
|
||||
<a href="/pics/">pictures</a> |
|
||||
<!--<a href="/pics/">pictures</a> |-->
|
||||
<a href="/projects/">projects</a> |
|
||||
<a href="https://github.com/floppydisk05?tab=repositories">repos</a> |
|
||||
<a href="/calculators/">calculators</a> |
|
||||
<a href="/computers/">computers</a> |
|
||||
<a href="/bookmarks/">bookmarks</a> |
|
||||
<a href="https://blog.diskfloppy.me/">blog</a>
|
||||
<a href="https://blog.diskfloppy.me/">blog</a> |
|
||||
<a href="/guestbook/">guestbook</a>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="pagetree">
|
||||
|
|
Loading…
Reference in a new issue