ユーザー名とパスワードは必須です。
"; echo ""; exit; } // ユーザー名の重複チェック foreach ($users as $u) { if ($u['username'] === $username) { echo "そのユーザー名はすでに使われています。
"; echo ""; exit; } } // 新規ID作成 $newId = $users ? max(array_column($users, 'id')) + 1 : 1; // 新規ユーザー配列作成 $newUser = [ 'id' => $newId, 'username' => $username, 'password' => password_hash($password, PASSWORD_DEFAULT), 'email' => $email, // 空文字でもOK 'created_at' => date('Y-m-d H:i:s') ]; // 配列に追加 $users[] = $newUser; // JSON に書き込み write_json($usersPath, $users); // 自動ログインさせる場合 $_SESSION['user_id'] = $newUser['id']; $_SESSION['username'] = $newUser['username']; header("Location: ../mypage.php"); exit;