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 |
register.php35 lines UTF-8 Unix (LF) - Type: PHP Fil
<?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($password, PASSWORD_DEFAULT),
"role" => ($username === "Admin" ? "admin" : "user")
];
file_put_contents($filename, json_encode($users, JSON_PRETTY_PRINT));
header('Location: index.php?regsuccess=1');
exit;
?>