"title" => "guestbook",
"meta" => [
["name" => "description", "content" => "sign my guestbook"]
- ]
+ ],
+ "css" => ["/stylesheet/guestbook.css"]
]);
?>
<center><img src="/image/gif/guestbook.gif" width="200"></center>
<?php
- error_reporting(E_ALL);
- ini_set("display_errors", 1);
-
// load database config
$config = parse_ini_file(__DIR__ . '/../config/config.ini', true);
$conn->query("SET time_zone='+08:00';");
// check connection
- if($conn->connect_error){
+ if($conn->connect_error) {
die("Connection failed: {$conn->connect_error}");
}
// entry submission
- if ($_SERVER["REQUEST_METHOD"] == "POST"){
+ if ($_SERVER["REQUEST_METHOD"] == "POST") {
+
+ // honeypot check
+ if(!empty($_POST['honeypot'])) {
+ header("Location: " . $_SERVER["PHP_SELF"]);
+ die();
+ };
+
$name = htmlspecialchars($_POST['name'], ENT_QUOTES, "UTF-8");
$country = htmlspecialchars($_POST['country'], ENT_QUOTES, "UTF-8");
$website = htmlspecialchars($_POST['website'], ENT_QUOTES, "UTF-8");
VALUES (?, ?, ?, ?, ?, ?);";
$stmt = $conn->prepare($sql);
- if(!$stmt){
+ if(!$stmt) {
die("Prepare failed: {$conn->error}");
}
// s = string
$stmt->bind_param("ssssss", $name, $country, $website, $email, $comment, $ip_addr);
- if(!$stmt->execute()){
+ if(!$stmt->execute()) {
die("Execute failed: {$stmt->error}");
}
<br>
<label for="website">My website: </label><input type="text" name="website" placeholder="optional">
<br>
+ <input type="text" class="honeypot" name="honeypot">
<label for="email">My e-mail: </label><input type="email" name="email" placeholder="only me can see, optional">
<br>
<label for="comment">Comment: </label><br><textarea name="comment" rows="10" cols="35" placeholder="..." required></textarea>
?>
<!-- stylesheets -->
- <link rel="stylesheet" href="/part/stylesheet/root.css?v=<?= filemtime("{$_SERVER['DOCUMENT_ROOT']}/part/stylesheet/root.css");?>">
+ <link rel="stylesheet" href="/stylesheet/root.css?v=<?= filemtime("{$_SERVER['DOCUMENT_ROOT']}/stylesheet/root.css");?>">
<?php foreach($css as $file):?>
<?php
$filepath = $_SERVER['DOCUMENT_ROOT'] . $file;
<?php endforeach;?>
<!-- scripts -->
- <script src="/part/script/root.js?v=<?= filemtime("{$_SERVER['DOCUMENT_ROOT']}/part/script/root.js");?>"></script>
+ <script src="/script/root.js?v=<?= filemtime("{$_SERVER['DOCUMENT_ROOT']}/script/root.js");?>"></script>
<?php foreach($js as $file):?>
<?php
$filepath = $_SERVER['DOCUMENT_ROOT'] . $file;