2008/7/1 久米
login.php
<?php
//error_reporting(0);
session_start();
if(isset($_SESSION['login'])){
if($_SESSION['login']=='OK'){
header("Location: submit.php");
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>login</title>
</head>
<body>
<h1>掲示板 投稿ログイン</h1>
<form method="post" name="f" action="login2.php">
パスワード:<input type="password" name="password">
<input type="submit" name="sub" value="ログイン">
</form>
</body>
</html>
|
login2.php
<?php
//error_reporting(0);
session_start();
if(!isset($_POST['password'])) exit("アクセスエラーです。");
if($_POST['password']=='777'){
$_SESSION['login']='OK';
header("Location: submit.php");
exit();
}else{
$_SESSION['login']='NG';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>login2</title>
</head>
<body>
<h1>掲示板 投稿ログイン</h1>
<p>パスワードが違います。</p>
<p><a href="login.php">戻る</a> </p>
</body>
</html>
|
submit.phpの先頭に次のスクリプトを追加
<?php
//error_reporting(0);
session_start();
if(!isset($_SESSION['login'])){
header("Location: login.php");
exit();
}
if($_SESSION['login']!='OK'){
header("Location: login.php");
exit();
}
?>
|
| 会員用 テーブル作成 |
CREATE TABLE users ( |
| パスワードを 暗号化して 挿入 |
INSERT INTO users (name, password) VALUES ('kume', ENCODE('777','seed')) |
| パスワードを 取得 |
SELECT name, DECODE(password, 'seed') pass FROM users |
| 名前とパスワードが 一致しているか |
SELECT count(*) cnt FROM users WHERE name='kume' AND password=ENCODE('777', 'seed') |