Update index.php

This commit is contained in:
2024-09-22 12:21:10 +02:00
committed by GitHub
parent eba0f59d9a
commit 5f346d99bf
+69 -1
View File
@@ -1,5 +1,69 @@
<?php
session_start();
// Password protection
$password = 'geheim'; // Replace with your desired password
$is_authenticated = isset($_SESSION['authenticated']) && $_SESSION['authenticated'] === true;
// Logout mechanism
if (isset($_GET['logout'])) {
unset($_SESSION['authenticated']);
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
if (!$is_authenticated) {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password'])) {
if ($_POST['password'] === $password) {
$_SESSION['authenticated'] = true;
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
} else {
$error = 'Incorrect password';
}
}
// Display password prompt
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Protected</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
</head>
<body class="d-flex align-items-center justify-content-center" style="min-height: 100vh;">
<div class="modal d-block" tabindex="-1" style="background-color: rgba(0,0,0,0.5);">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Password Required</h5>
</div>
<div class="modal-body">
<form method="post">
<div class="mb-3">
<label for="password" class="form-label">Enter Password:</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
<?php
exit;
} else {
// Rest of the original code
$directory = __DIR__ . '/files';
if (!file_exists($directory)) {
mkdir($directory, 0755, true);
@@ -121,10 +185,11 @@ function renderFileListItem($file) {
</head>
<body class="d-flex flex-column min-vh-100">
<header class="py-2 sticky-header">
<div class="container">
<div class="container d-flex justify-content-between align-items-center">
<a href="./" class="nav-brand">
<strong>VINCENT</strong><span>MARKDOWN</span>
</a>
<a href="?logout" class="btn btn-outline-dark btn-sm">Logout</a>
</div>
</header>
@@ -273,3 +338,6 @@ function renderFileListItem($file) {
<script src="scripts.js"></script>
</body>
</html>
<?php
}
?>