From d32f9aeafd556085c2e47a4b626091fa5be0b96c Mon Sep 17 00:00:00 2001 From: Frankie B Date: Sun, 2 Oct 2022 17:10:23 +0000 Subject: Add guestbook --- guestbook/index.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ guestbook/submit.php | 60 ++++++++++++++++++++++++++++++++++++++++++ inc/nav.php | 5 ++-- 3 files changed, 137 insertions(+), 2 deletions(-) create mode 100755 guestbook/index.php create mode 100755 guestbook/submit.php diff --git a/guestbook/index.php b/guestbook/index.php new file mode 100755 index 0000000..8ca20d5 --- /dev/null +++ b/guestbook/index.php @@ -0,0 +1,74 @@ + + + + + + + + + Bookmarks + + + + + + +
+ + +
+
+
+
+ Nickname:
+ Message:
+ Show IP:
+ Show info:
+
+
+ + prepare('SELECT COUNT(*) FROM Entries'); + $count_query->execute(); + $count = $count_query->fetch()[0]; + echo '

Entries (' . $count . ' total)

'; + // 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 '
';
+		    $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 '

'; + } + ?> + +
+ + +
+
+ + diff --git a/guestbook/submit.php b/guestbook/submit.php new file mode 100755 index 0000000..9187223 --- /dev/null +++ b/guestbook/submit.php @@ -0,0 +1,60 @@ + + + + + + + + + Bookmarks + + + + +
+ + +
+
+ You must provide both a name and message!'; + } 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 'Success!'; + } + ?>

+ Back +
+ + +
+
+ + diff --git a/inc/nav.php b/inc/nav.php index 364b3da..293549b 100644 --- a/inc/nav.php +++ b/inc/nav.php @@ -6,13 +6,14 @@ projects | pics |--> - pictures | + projects | repos | calculators | computers | bookmarks | - blog + blog | + guestbook
-- cgit v1.2.3-54-g00ecf