Created
March 15, 2020 13:19
-
-
Save PJZ9n/e116bb05d1b6c39dc4aed3c93140cda8 to your computer and use it in GitHub Desktop.
Webサーバー側
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //とても単純な例で、そのまま使うことを前提としていません | |
| //同一ディレクトリに所持金記録用のmoney.jsonがあるとする | |
| function response(int $code, array $data = []): void{ | |
| http_response_code($code); | |
| echo json_encode($data); | |
| exit(); | |
| } | |
| function setMoney(string $name, int $money): void{ | |
| $moneys = json_decode(file_get_contents("money.json"), true); | |
| $moneys[$name] = $money; | |
| file_put_contents("money.json", json_encode($moneys)); | |
| } | |
| //アクセス元IPアドレスをチェック | |
| if ($_SERVER["REMOTE_ADDR"] !== "123.456.789.012") { | |
| //アクセス元がサーバーではなかったら401を返して終了 | |
| response(401); | |
| } | |
| setMoney($_POST["name"], $_POST["money"]); | |
| response(200); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment