← 完成版とシステムの改良へ戻る / ソース一覧へ
index.php
このページはソースコードを表示するためのHTMLです。source_common/index.php への直接リンクではないため,PHPスクリプトは実行されません。
<?php
// index.php: ログイン画面
session_start();
require_once __DIR__ . '/common/common.php';
$error = '';
if (!empty($_POST)) {
if ($_POST['mail'] !== '' && $_POST['pass_word'] !== '') {
$sql = 'SELECT * FROM member WHERE mail = :mail';
$stmt = $dbh->prepare($sql);
$stmt->bindValue(':mail', $_POST['mail'], PDO::PARAM_STR);
$stmt->execute();
$record = $stmt->fetch();
if ($record && password_verify($_POST['pass_word'], $record['pass_word'])) {
$_SESSION['id'] = $record['id'];
$_SESSION['time'] = time();
header('Location: top_page.php');
exit();
}
$error = 'メールアドレスまたはパスワードが間違っています。';
} else {
$error = 'メールアドレスとパスワードを入力してください。';
}
}
?>
<!DOCTYPE html>
<html lang="ja">
<head><meta charset="UTF-8"><title>ログイン</title></head>
<body>
<h1>ログイン</h1>
<?php if ($error !== ''): ?><p style="color:red"><?php echo h($error); ?></p><?php endif; ?>
<form action="" method="post">
<p>メールアドレス:<input type="email" name="mail" required></p>
<p>パスワード:<input type="password" name="pass_word" required></p>
<p><input type="submit" value="ログイン"></p>
</form>
<p><a href="entry.php">ユーザー登録</a></p>
</body>
</html>