Visa Källkod

The following files exist in this folder. Click to view.

NamnTypStorlek
admin.phpPHP Fil7.4 KB
change_password.phpPHP Fil1.6 KB
check_login.phpPHP Fil183 B
delete_user.phpPHP Fil641 B
guestbook.jsonJSON Fil623 B
guestbook.phpPHP Fil5.5 KB
index.phpPHP Fil1.9 KB
login.phpPHP Fil1.6 KB
logout.phpPHP Fil341 B
register.phpPHP Fil872 B
users.jsonJSON Fil1.9 KB

delete_user.php

29 lines UTF-8 Unix (LF) - Type: PHP Fil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?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($filenamejson_encode($newUsersJSON_PRETTY_PRINT));

// Rensa session och skicka tillbaka till startsidan
session_unset();
session_destroy();
header('Location: index.php?deleted=1');
exit;
?>