The following files exists in this folder. Click to view.
accountant.php33 lines ASCII Unix (LF)
<?php
$file_in = "users.json";
$json = json_decode(file_get_contents($file_in), true);
foreach ($json["users"] as $u){
$users[] = $u["usn"];
}
foreach($json["users"] as $u){
if($_POST["c_username"] != $u["usn"]){
$occupied="N";
}
else{
$occupied="Y";
break;
}
}
if($occupied=="Y"){
header("location: create_account.php?mess=EXISTS");
exit();
}
else{
$json["users"][] = ["usn" => $_POST["c_username"], "pwd" => $_POST["c_password"], "status" => "user"];
$file_out = "users.json";
$file = fopen($file_out, "w");
fwrite($file, json_encode($json, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
fclose($file);
header("location: index.php?mess=CREATED");
exit();
}
?>