|
<?php
|
|
|
|
$file = 'user.json';
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
$username = $_POST['username'];
|
|
$password = $_POST['password'];
|
|
|
|
|
|
$data = array(
|
|
'username' => $username,
|
|
'password' => $password
|
|
);
|
|
|
|
|
|
$jsonData = file_get_contents($file);
|
|
|
|
|
|
$existingData = json_decode($jsonData, true);
|
|
|
|
|
|
$existingData[] = $data;
|
|
|
|
|
|
$json = json_encode($existingData);
|
|
|
|
|
|
file_put_contents($file, $json);
|
|
|
|
|
|
echo 'Username and password saved successfully!';
|
|
}
|
|
|
|
|
|
$jsonData = file_get_contents($file);
|
|
|
|
|
|
$dataArray = json_decode($jsonData, true);
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Save User</title>
|
|
</head>
|
|
<button onclick="window.location.href='hi.html'">Go to User Page</button>
|
|
|
|
|
|
<body>
|
|
<h2>Save User</h2>
|
|
<form method="POST" action="">
|
|
<label for="username">Username:</label>
|
|
<input type="text" name="username" id="username" required><br><br>
|
|
<label for="password">Password:</label>
|
|
<input type="password" name="password" id="password" required><br><br>
|
|
<input type="submit" value="Save">
|
|
</form>
|
|
</body>
|
|
</html> |