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
6 changes: 6 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Files ~ "^(\.|composer\.json)">
order allow,deny
deny from all
</Files>

RedirectMatch 404 /\.git
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: 3 additions & 3 deletions guestbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
if(isset($_POST['entry']) && $_POST['entry'] != "") {
$id = $_SESSION['userid'];
$entry = $_POST['entry'];
$query = "select * from `users` where `id` = '$id' LIMIT 1";
$query = "select * from `users` where `id` = '{$db->real_escape_string($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 All @@ -37,7 +37,7 @@
while ($row = $result->fetch_assoc()) {
$username = $row['username'];
$entry = $row['entry'];
print('<tr><td>' . $username . '</td><td>' . $entry . '</td></tr>');
print('<tr><td>' . htmlspecialchars($username) . '</td><td>' . htmlspecialchars($entry) . '</td></tr>');
}
print('</tbody></table>');
} else {
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<!-- /.container -->
</nav>');

if (isset($_GET['site']) && $_GET['site'] != "") {
if (isset($_GET['site']) && $_GET['site'] != "" && preg_match('/^[a-z]+\.php$/', $_GET['site']) && file_exists(__DIR__.'/'.$_GET['site'])) {
include $_GET['site'];
} else {
$description = nl2br(file_get_contents("README.md"));
Expand Down
11 changes: 7 additions & 4 deletions login.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php

function login($username, $password) {
/** @var mysqli $db */
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;
$_SESSION['userid'] = $row['id'];
return(true);
}
print('<div class="row"><div class="col-lg-12 text-center" style="color:red;">Login unsuccessful!</div></div>');
print('<div class="row"><div class="col-lg-12 text-center" style="color:#ff0000;">Login unsuccessful!</div></div>');
return(false);
}

Expand All @@ -21,16 +22,18 @@ function login($username, $password) {
if (logged_in() || (isset($_POST['username']) && isset($_POST['password']) && login($_POST['username'], $_POST['password']))) {
$id = $_SESSION['userid'];
global $db;
$query = "select * from `users` where `id` = '$id' LIMIT 1";
$query = "select * from `users` where `id` = '{$db->real_escape_string($id)}' LIMIT 1";
$result = $db->query($query);
if ($row = $result->fetch_assoc()) {
$username = $row['username'];
} else {
print('<div class="row"><div class="col-lg-12 text-center" style="color:#ff0000;">Login unsuccessful!</div></div>');
}

print('<div class="row">
<div class="col-lg-12 text-center">
<h1>Private Area</h1>
Hey ' . $username . '. Nice to have you here!
Hey ' . htmlspecialchars($username) . '. Nice to have you here!
<p>
<a class="btn btn-danger" href="?site=logout.php">Logout</a>
</p>
Expand Down