Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
}

// Connect to session
session_start();
session_start();
session_regenerate_id(true);

// Check Login
function logged_in() {
Expand Down
6 changes: 4 additions & 2 deletions guestbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@

if(isset($_POST['entry']) && $_POST['entry'] != "") {
$id = $_SESSION['userid'];
$entry = $_POST['entry'];
$entry = filter_input(INPUT_POST, 'entry', FILTER_SANITIZE_SPECIAL_CHARS); //$_POST['entry'];
$query = "select * from `users` where `id` = '$id' LIMIT 1";
$result = $db->query($query);
if ($row = $result->fetch_assoc()) {
$username = $row['username'];
}
$query = "INSERT INTO `guestbook` (`username`, `entry`) VALUES ('$username', '$entry');";


$query = "INSERT INTO `guestbook` (`username`, `entry`) VALUES ('" . $db->real_escape_string($username) . "', '" . $db->real_escape_string($entry) . "');";
$result = $db->query($query);
$db->commit();
print('<div class="row">
Expand Down
18 changes: 13 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

echo("<html><head>");

include "connect.php";


echo("<html><head>");
include "head.php";

echo("</head><body>");
Expand All @@ -25,10 +27,10 @@
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a href="?site=guestbook.php">Guestbook</a>
<a href="?site=guestbook">Guestbook</a>
</li>
<li>
<a href="?site=login.php">Private</a>
<a href="?site=login">Private</a>
</li>
</ul>
</div>
Expand All @@ -37,8 +39,14 @@
<!-- /.container -->
</nav>');

if (isset($_GET['site']) && $_GET['site'] != "") {
include $_GET['site'];
$allowed_pages = [
'guestbook',
'login',
'logout'
];

if (isset($_GET['site']) && $_GET['site'] != "" && in_array( $_GET['site'], $allowed_pages) ) {
require $_GET['site'] . '.php';
} else {
$description = nl2br(file_get_contents("README.md"));
echo(' <!-- Page Content -->
Expand Down
5 changes: 3 additions & 2 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

function login($username, $password) {
global $db;
$query = "select `id` from `users` where `username` = '$username' AND `password` = '$password'";
$query = "select `id` from `users` where `username` = '" . $db->real_escape_string($username) . "' AND `password` = '" . $db->real_escape_string($password) . "';";

$result = $db->query($query);
if ($result->num_rows > 0 && $row = $result->fetch_assoc()) {
$_SESSION['logged_in'] = true;
Expand Down Expand Up @@ -32,7 +33,7 @@ function login($username, $password) {
<h1>Private Area</h1>
Hey ' . $username . '. Nice to have you here!
<p>
<a class="btn btn-danger" href="?site=logout.php">Logout</a>
<a class="btn btn-danger" href="?site=logout">Logout</a>
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

echo "Setting up database"
mysql --user=che --password=che < create_db.sql

rm create_db.sql
echo "Finished..."