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

register.php

35 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
30
31
32
33
34
35
<?php

$filename 
"users.json";
$users = [];
if (
file_exists($filename)) {
    
$users json_decode(file_get_contents($filename), true) ?? [];
}

$username trim($_POST['new_username'] ?? '');
$password $_POST['new_password'] ?? '';

if (
$username === '' || $password === '') {
    
header('Location: index.php?regerror=tomt');
    exit;
}

// Kontrollera om användarnamnet redan finns
foreach ($users as $user) {
    if (
$user['username'] === $username) {
        
header('Location: index.php?regerror=upptaget');
        exit;
    }
}

// Spara ny användare med hashat lösenord
$users[] = [
    
"username" => $username,
    
"password" => password_hash($passwordPASSWORD_DEFAULT),
    
"role" => ($username === "Admin" "admin" "user")
];

file_put_contents($filenamejson_encode($usersJSON_PRETTY_PRINT));
header('Location: index.php?regsuccess=1');
exit;
?>