The following files exist in this folder. Click to view.
| Namn | Typ | Storlek |
|---|---|---|
| admin.php | PHP Fil | 7.4 KB |
| change_password.php | PHP Fil | 1.6 KB |
| check_login.php | PHP Fil | 183 B |
| delete_user.php | PHP Fil | 641 B |
| guestbook.json | JSON Fil | 623 B |
| guestbook.php | PHP Fil | 5.5 KB |
| index.php | PHP Fil | 1.9 KB |
| login.php | PHP Fil | 1.6 KB |
| logout.php | PHP Fil | 341 B |
| register.php | PHP Fil | 872 B |
| users.json | JSON Fil | 1.9 KB |
delete_user.php29 lines UTF-8 Unix (LF) - Type: PHP Fil
<?php
require 'check_login.php';
$filename = "users.json";
$users = [];
if (file_exists($filename)) {
$users = json_decode(file_get_contents($filename), true) ?? [];
}
$username = $_POST['username'] ?? '';
// Filtrera bort den användare som ska raderas
$newUsers = [];
foreach ($users as $user) {
if ($user['username'] !== $username) {
$newUsers[] = $user;
}
}
// Skriv tillbaka listan utan användaren
file_put_contents($filename, json_encode($newUsers, JSON_PRETTY_PRINT));
// Rensa session och skicka tillbaka till startsidan
session_unset();
session_destroy();
header('Location: index.php?deleted=1');
exit;
?>