PHPを使って(偽)会社の社内システムを作成.2

requiredの追加

index.html

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>ログインフォーム</title>
<style></style>
</head>
<body>
<h1>ログインフォーム</h1>
<div id="container">
  <form action="login_check.php" method="post">
    <table>
      <tr>
        <th> <label for="user">ユーザーアカウント:</label></th>
        <td><input type="text" size="32" maxlength="32" name="user" id="user" required></td>
      </tr>
      <tr>
        <th> <label for="password">パスワード:</label></th>
        <td><input type="password" size="32" maxlength="32" name="password" id="password" required></td><tr>
        <th colspan="2"> <input type="submit" value="送信" class="btn"></th>
      </tr>
    </table>
  </form>
</div>
</body>
</html>

loginformフォルダの中にini.phpファイルを追加

ini.php

<?php
function h($str){
	return htmlspecialchars($str,ENT_QUOTES,'utf-8');
}
session_start();
ob_start();

login_check.phpの変更

    • 初期設定ファイルを読み込む
<?php
session_start();

を以下に書き換える

<?php
require_once dirname(__FILE__) . '/ini.php';

ユーザーIDとパスワードを照合する

  • true item_list.htmlへ
  • false index.htmlへ


セッションハイジャック