-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_delete_handler.php
More file actions
34 lines (25 loc) · 930 Bytes
/
user_delete_handler.php
File metadata and controls
34 lines (25 loc) · 930 Bytes
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
<?php
require("php/util/user_reader.php");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST)) {
$email = $_POST['email'];
$users[] = null;
if (file_exists("database/users.json")) {
$input = file_get_contents("database/users.json", true);
$users = json_decode($input);
}
//find in which user the email is
$key = array_search($email, array_column($users, 'email'));
//delete user at key
unset($users[$key]);
//rebase array
$users = array_values($users);
$json = json_encode($users);
//write json to file
if (file_put_contents("database/users.json", $json)){
echo "<script type='text/javascript'> document.location = 'backstore/user_profiles.php'; </script>";
} else {
echo "Oops! Error creating json file when deleting user...";
}
}
}