Upload 3 files
Browse files
hi.html
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>User JSON Display</title>
|
5 |
+
<script>
|
6 |
+
// Fetch the user.json file
|
7 |
+
fetch('user.json')
|
8 |
+
.then(response => response.json())
|
9 |
+
.then(data => {
|
10 |
+
// Display the JSON data
|
11 |
+
document.getElementById('user-data').textContent = JSON.stringify(data, null, 2);
|
12 |
+
})
|
13 |
+
.catch(error => {
|
14 |
+
console.error('Error:', error);
|
15 |
+
});
|
16 |
+
</script>
|
17 |
+
</head>
|
18 |
+
<body>
|
19 |
+
<pre id="user-data"></pre>
|
20 |
+
</body>
|
21 |
+
</html>
|
index.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Define the file path
|
3 |
+
$file = 'user.json';
|
4 |
+
|
5 |
+
// Check if the form is submitted
|
6 |
+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
7 |
+
// Get the username and password from the form
|
8 |
+
$username = $_POST['username'];
|
9 |
+
$password = $_POST['password'];
|
10 |
+
|
11 |
+
// Create an array with the username and password
|
12 |
+
$data = array(
|
13 |
+
'username' => $username,
|
14 |
+
'password' => $password
|
15 |
+
);
|
16 |
+
|
17 |
+
// Read the existing JSON data from the file
|
18 |
+
$jsonData = file_get_contents($file);
|
19 |
+
|
20 |
+
// Convert the JSON data to an array
|
21 |
+
$existingData = json_decode($jsonData, true);
|
22 |
+
|
23 |
+
// Add the new data to the existing array
|
24 |
+
$existingData[] = $data;
|
25 |
+
|
26 |
+
// Convert the array to JSON format
|
27 |
+
$json = json_encode($existingData);
|
28 |
+
|
29 |
+
// Save the JSON data to the file
|
30 |
+
file_put_contents($file, $json);
|
31 |
+
|
32 |
+
// Display a success message
|
33 |
+
echo 'Username and password saved successfully!';
|
34 |
+
}
|
35 |
+
|
36 |
+
// Read the JSON data from the file
|
37 |
+
$jsonData = file_get_contents($file);
|
38 |
+
|
39 |
+
// Convert the JSON data to an array
|
40 |
+
$dataArray = json_decode($jsonData, true);
|
41 |
+
?>
|
42 |
+
|
43 |
+
<!DOCTYPE html>
|
44 |
+
<html>
|
45 |
+
<head>
|
46 |
+
<title>Save User</title>
|
47 |
+
</head>
|
48 |
+
<button onclick="window.location.href='hi.html'">Go to User Page</button>
|
49 |
+
|
50 |
+
|
51 |
+
<body>
|
52 |
+
<h2>Save User</h2>
|
53 |
+
<form method="POST" action="">
|
54 |
+
<label for="username">Username:</label>
|
55 |
+
<input type="text" name="username" id="username" required><br><br>
|
56 |
+
<label for="password">Password:</label>
|
57 |
+
<input type="password" name="password" id="password" required><br><br>
|
58 |
+
<input type="submit" value="Save">
|
59 |
+
</form>
|
60 |
+
</body>
|
61 |
+
</html>
|
user.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"username":"[email protected]","password":"rthh","0":{"username":"oamr nuwara","password":"ergerger"},"1":{"username":"oamr nuwara","password":"thjtjy"},"2":{"username":"[email protected]","password":"erggere"},"3":{"username":"rthrt","password":"rthrth"},"4":{"username":"admin","password":"rhrhtrh"},"5":{"username":"yuhedfa","password":"ergergrge"}}
|