View sourcecode

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

accountant.php

33 lines ASCII Unix (LF)
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
<?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($filejson_encode($jsonJSON_UNESCAPED_UNICODE JSON_PRETTY_PRINT));
    
fclose($file);
    
header("location: index.php?mess=CREATED");
    exit();
}

?>