質問編集履歴
2
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -51,80 +51,114 @@
|
|
51
51
|
|
52
52
|
会員登録画面<index.php>
|
53
53
|
```php
|
54
|
+
<!DOCTYPE html>
|
55
|
+
<html lang="ja">
|
56
|
+
<head>
|
57
|
+
<meta charset="UTF-8">
|
58
|
+
<title>会員登録処理</title>
|
59
|
+
</head>
|
60
|
+
<body>
|
61
|
+
<h1>会員登録</h1>
|
54
|
-
<?php
|
62
|
+
<?php
|
55
|
-
require
|
63
|
+
require('../dbconnect.php');
|
56
64
|
|
57
|
-
session_start();
|
65
|
+
session_start();
|
58
66
|
|
59
|
-
if (isset($_COOKIE['email']) != '') {
|
60
|
-
$_POST['email'] = $_COOKIE['email'];
|
61
|
-
$_POST['password'] = $_COOKIE['password'];
|
62
|
-
|
67
|
+
//フォーム画面の処理 初期化
|
68
|
+
$_POST=array();
|
69
|
+
$_SESSION = array();
|
63
70
|
|
71
|
+
if(!empty($_POST)) {
|
72
|
+
//エラー項目の確認
|
73
|
+
if($_POST['name'] == '') {
|
74
|
+
$error['name'] = 'blank';
|
64
|
-
}
|
75
|
+
}
|
76
|
+
if($_POST['email'] == '') {
|
77
|
+
$error['email'] = 'blank';
|
78
|
+
}
|
79
|
+
if(strlen($_POST['password']) < 4) {
|
80
|
+
$error['password'] = 'length';
|
81
|
+
}
|
82
|
+
if($_POST['password'] == '') {
|
83
|
+
$error['password'] = 'blank';
|
84
|
+
}
|
85
|
+
$fileName = $_FILES['image'] ['name'];
|
86
|
+
if(!empty($fileName)) {
|
87
|
+
$ext = substr($fileName, -3);
|
88
|
+
if($ext != 'jpg' && $ext != 'gif') {
|
89
|
+
$error['image'] = 'type';
|
90
|
+
}
|
91
|
+
}
|
65
92
|
|
93
|
+
//重複アカウントのチェック
|
66
|
-
if
|
94
|
+
if(empty($error)) {
|
67
|
-
//ログイン処理
|
68
|
-
|
95
|
+
$member = $db->prepare('SELECT COUNT(*) AS cnt FROM members WHERE email=?');
|
69
|
-
$sql = sprintf('select * from members where email="%s" and password = "%s"',
|
70
|
-
|
96
|
+
$member->execute(array($_POST['email']));
|
71
|
-
mysqli_real_escape_string($db,shal($_POST['password']))
|
72
|
-
);
|
73
|
-
$record =
|
97
|
+
$record = $member->fetch();
|
74
|
-
if
|
98
|
+
if($record['cnt'] > 0) {
|
75
|
-
//ログイン成功
|
76
|
-
|
99
|
+
$error['email'] = 'duplicate';
|
77
|
-
|
100
|
+
}
|
101
|
+
}
|
78
102
|
|
103
|
+
if(empty($error)) {
|
79
|
-
|
104
|
+
//画像をアップロードする
|
80
|
-
if ($_POST['save'] =- 'on') {
|
81
|
-
|
105
|
+
$image = date('YmdHis') . $_FILES['image']['name'];
|
106
|
+
move_uploaded_file($_FILES['image']['tmp_name'], '../member_picture/' . $image);
|
107
|
+
|
108
|
+
$_SESSION['join'] = $_POST;
|
82
|
-
|
109
|
+
$_SESSION['join']['image'] = $image;
|
110
|
+
header('Location: check.php');
|
111
|
+
exit();
|
83
|
-
|
112
|
+
}
|
84
|
-
header('Location; index.php');exit();
|
85
|
-
} else {
|
86
|
-
$error['login'] = 'failed';
|
87
|
-
}
|
88
|
-
} else {
|
89
|
-
$error['login']='blank';
|
90
113
|
}
|
91
|
-
}
|
92
|
-
?>
|
114
|
+
?>
|
93
|
-
<!DOCTYPE html>
|
94
|
-
<html lang="ja">
|
95
|
-
<head>
|
96
|
-
<meta charset="utf-8" />
|
97
|
-
<script type="text/javascript" charset="UTF-8"></script>
|
98
|
-
</head>
|
99
|
-
<body>
|
100
|
-
<div id="lead">
|
101
|
-
<p>
|
115
|
+
<p>次のフォームに必要事項をご記入ください。</p>
|
102
|
-
<p>入会手続きがまだの方はこちらからどうぞ</p>
|
103
|
-
<p>»<a href="join/">入会手続きをする</a></p>
|
104
|
-
</div>
|
105
|
-
|
116
|
+
<form action="" method="post" enctype="multipart/form-data">
|
106
|
-
|
117
|
+
<dl>
|
118
|
+
<dt>ニックネーム<span class="required">必須</span></dt>
|
119
|
+
<dd><input type="text" name="name" size="35" maxlength="255" value="<?php echo htmlspecialchars($_POST['name'], ENT_QUOTES,'UTF-8'); ?>" />
|
107
|
-
<
|
120
|
+
<?php if(!empty($sen1)):?>
|
121
|
+
<?php if($error['name'] == 'blank'): ?>
|
122
|
+
<p class="error">* ニックネームを入力してください</p>
|
123
|
+
<?php endif; ?>
|
124
|
+
<?php endif; ?>
|
108
|
-
<dd>
|
125
|
+
</dd>
|
126
|
+
<dt>メールアドレス<span class="required">必須</span></dt>
|
109
|
-
|
127
|
+
<dd><input type="text" name="email" size="35" maxlength="255" value="<?php echo htmlspecialchars($_POST['email'], ENT_QUOTES,'UTF-8'); ?>" />
|
128
|
+
<?php if(!empty($sen1)):?>
|
110
|
-
|
129
|
+
<?php if($error['email'] == 'blank'): ?>
|
111
|
-
<p class="error">*
|
130
|
+
<p class="error">* メールアドレスを入力してください</p>
|
131
|
+
<?php endif; ?>
|
132
|
+
<?php if($error['email'] == 'duplicate'): ?>
|
133
|
+
<p class="error">* 指定されたメールアドレスはすでに登録されています</p>
|
134
|
+
<?php endif; ?>
|
135
|
+
<?php endif; ?>
|
136
|
+
</dd>
|
137
|
+
<dt>パスワード<span class="required">必須</span></dt>
|
138
|
+
<dd><input type="password" name="password" size="10" maxlength="20" value="<?php echo htmlspecialchars($_POST['password'], ENT_QUOTES,'UTF-8'); ?>" />
|
139
|
+
<?php if(!empty($sen1)):?>
|
140
|
+
<?php if($error['password'] == 'blank'): ?>
|
141
|
+
<p class="error">* パスワードを入力してください</p>
|
142
|
+
<?php endif; ?>
|
143
|
+
<?php if($error['password'] == 'length'): ?>
|
144
|
+
<p class="error">* パスワードは4文字以上で入力してください</p>
|
145
|
+
<?php endif; ?>
|
146
|
+
<?php endif; ?>
|
147
|
+
</dd>
|
148
|
+
<dt>写真など</dt>
|
149
|
+
<dd><input type="file" name="image" size="35" />
|
150
|
+
<?php if(!empty($image)):?>
|
151
|
+
<?php if($error['image'] == 'type'): ?>
|
152
|
+
<p class="error">* 写真などは「.gif」または「.jpg」の画像を指定してください</p>
|
112
153
|
<?php endif; ?>
|
113
|
-
<?php if
|
154
|
+
<?php if(!empty($error)): ?>
|
114
|
-
|
155
|
+
<p class="error">* 恐れ入りますが、画像を改めて指定してください</p>
|
115
156
|
<?php endif; ?>
|
157
|
+
<?php endif; ?>
|
116
158
|
</dd>
|
117
|
-
<dt>パスワード</dt>
|
118
|
-
<dd>
|
119
|
-
<input type="password" name="password" size="35" maxlength="255" value="<?php echo filter_input(INPUT_POST,"password"); ?>" />
|
120
|
-
</dd>
|
121
|
-
<dt>ログイン情報の記録</dt>
|
122
|
-
<dd>
|
123
|
-
<input id="save" type="checkbox" name="save" value="on"><label for="save">次回からは自動的にログインする</label>
|
124
|
-
</dd>
|
125
|
-
|
159
|
+
</dl>
|
126
|
-
|
160
|
+
<div><input name="sen1" type="submit" value="入力内容を確認する" /></div>
|
127
|
-
|
161
|
+
</form>
|
128
162
|
</body>
|
129
163
|
</html>
|
130
164
|
```
|
1
改造前のソースに戻します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -51,112 +51,80 @@
|
|
51
51
|
|
52
52
|
会員登録画面<index.php>
|
53
53
|
```php
|
54
|
-
<!DOCTYPE html>
|
55
|
-
<html lang="ja">
|
56
|
-
<head>
|
57
|
-
<meta charset="UTF-8">
|
58
|
-
<title>会員登録処理</title>
|
59
|
-
</head>
|
60
|
-
<body>
|
61
|
-
<h1>会員登録</h1>
|
62
|
-
|
54
|
+
<?php
|
63
|
-
|
55
|
+
require ('dbconnect.php');
|
64
56
|
|
65
|
-
|
57
|
+
session_start();
|
66
58
|
|
67
|
-
|
59
|
+
if (isset($_COOKIE['email']) != '') {
|
68
|
-
|
60
|
+
$_POST['email'] = $_COOKIE['email'];
|
61
|
+
$_POST['password'] = $_COOKIE['password'];
|
69
|
-
|
62
|
+
$_POST['save'] = 'on';
|
70
|
-
$error['name'] = 'blank';
|
71
|
-
}
|
72
|
-
if($_POST['email'] == '') {
|
73
|
-
$error['email'] = 'blank';
|
74
|
-
}
|
75
|
-
if(strlen($_POST['password']) < 4) {
|
76
|
-
$error['password'] = 'length';
|
77
|
-
}
|
78
|
-
if($_POST['password'] == '') {
|
79
|
-
$error['password'] = 'blank';
|
80
|
-
}
|
81
|
-
$fileName = $_FILES['image'] ['name'];
|
82
|
-
if(!empty($fileName)) {
|
83
|
-
$ext = substr($fileName, -3);
|
84
|
-
if($ext != 'jpg' && $ext != 'gif') {
|
85
|
-
$error['image'] = 'type';
|
86
|
-
}
|
87
|
-
}
|
88
63
|
|
89
|
-
//重複アカウントのチェック
|
90
|
-
if(empty($error)) {
|
91
|
-
$member = $db->prepare('SELECT COUNT(*) AS cnt FROM members WHERE email=?');
|
92
|
-
$member->execute(array($_POST['email']));
|
93
|
-
$record = $member->fetch();
|
94
|
-
if($record['cnt'] > 0) {
|
95
|
-
$error['email'] = 'duplicate';
|
96
|
-
|
64
|
+
}
|
97
|
-
}
|
98
65
|
|
99
|
-
|
66
|
+
if (!empty($_POST)) {
|
100
|
-
|
67
|
+
//ログイン処理
|
101
|
-
|
68
|
+
if ($_POST['email'] != '' && $_POST['password'] != '') {
|
102
|
-
|
69
|
+
$sql = sprintf('select * from members where email="%s" and password = "%s"',
|
70
|
+
mysqli_real_escape_string($db,$_POST['email']),
|
71
|
+
mysqli_real_escape_string($db,shal($_POST['password']))
|
72
|
+
);
|
73
|
+
$record = mysqli_query(isset($db), $sql) or die (mysqli_error(isset($db)));
|
74
|
+
if ($table = mysqli_fetch_assoc($record)) {
|
75
|
+
//ログイン成功
|
76
|
+
$_SESSION['id'] = $table['id'];
|
77
|
+
$_SESSION['time'] = time();
|
103
78
|
|
104
|
-
|
79
|
+
//ログイン情報を記録する
|
105
|
-
|
80
|
+
if ($_POST['save'] =- 'on') {
|
106
|
-
|
81
|
+
setcookie('email', $_POST['email'], time()+60*60*24*14);
|
107
|
-
|
82
|
+
setcookie('password', $_POST['password'], time()+60*60*24*14);
|
108
|
-
|
83
|
+
}
|
84
|
+
header('Location; index.php');exit();
|
85
|
+
} else {
|
86
|
+
$error['login'] = 'failed';
|
87
|
+
}
|
88
|
+
} else {
|
89
|
+
$error['login']='blank';
|
109
90
|
}
|
91
|
+
}
|
110
|
-
|
92
|
+
?>
|
93
|
+
<!DOCTYPE html>
|
94
|
+
<html lang="ja">
|
95
|
+
<head>
|
96
|
+
<meta charset="utf-8" />
|
97
|
+
<script type="text/javascript" charset="UTF-8"></script>
|
98
|
+
</head>
|
99
|
+
<body>
|
100
|
+
<div id="lead">
|
111
|
-
<p>
|
101
|
+
<p>メールアドレスとパスワードを記入してログインしてください。</p>
|
102
|
+
<p>入会手続きがまだの方はこちらからどうぞ</p>
|
103
|
+
<p>»<a href="join/">入会手続きをする</a></p>
|
104
|
+
</div>
|
112
|
-
|
105
|
+
<form action="" method="post">
|
113
|
-
|
106
|
+
<dl>
|
114
|
-
<dt>
|
107
|
+
<dt>メールアドレス</dt>
|
108
|
+
<dd>
|
115
|
-
|
109
|
+
<input type="text" name="email" size="35" maxlength="255" value="<?php echo filter_input(INPUT_POST,"email"); ?>" />
|
116
|
-
<?php if(!empty($sen1)):?>
|
117
|
-
|
110
|
+
<?php if (isset($error['login'])): ?>
|
118
|
-
<p class="error">*
|
111
|
+
<p class="error">* メールアドレスとパスワードをご記入ください</p>
|
119
|
-
|
112
|
+
<?php endif; ?>
|
113
|
+
<?php if ($error['login'] == 'failed'): ?>
|
114
|
+
<p class="error">* ログイン失敗したした。正しくご記入ください。</p>
|
120
|
-
|
115
|
+
<?php endif; ?>
|
121
116
|
</dd>
|
122
|
-
<dt>
|
117
|
+
<dt>パスワード</dt>
|
118
|
+
<dd>
|
123
|
-
<
|
119
|
+
<input type="password" name="password" size="35" maxlength="255" value="<?php echo filter_input(INPUT_POST,"password"); ?>" />
|
124
|
-
<dd><input type="text" name="email" size="35" maxlength="255" value="" />
|
125
|
-
<?php if(!empty($sen1)):?>
|
126
|
-
<?php if($error['email'] == 'blank'): ?>
|
127
|
-
<p class="error">* メールアドレスを入力してください</p>
|
128
|
-
<?php endif; ?>
|
129
|
-
<?php if($error['email'] == 'duplicate'): ?>
|
130
|
-
<p class="error">* 指定されたメールアドレスはすでに登録されています</p>
|
131
|
-
<?php endif; ?>
|
132
|
-
<?php endif; ?>
|
133
120
|
</dd>
|
134
|
-
<dt>
|
121
|
+
<dt>ログイン情報の記録</dt>
|
135
|
-
<
|
122
|
+
<dd>
|
136
|
-
|
123
|
+
<input id="save" type="checkbox" name="save" value="on"><label for="save">次回からは自動的にログインする</label>
|
137
|
-
<?php if(!empty($sen1)):?>
|
138
|
-
<?php if($error['password'] == 'blank'): ?>
|
139
|
-
<p class="error">* パスワードを入力してください</p>
|
140
|
-
<?php endif; ?>
|
141
|
-
<?php if($error['password'] == 'length'): ?>
|
142
|
-
<p class="error">* パスワードは4文字以上で入力してください</p>
|
143
|
-
<?php endif; ?>
|
144
|
-
<?php endif; ?>
|
145
124
|
</dd>
|
146
|
-
<dt>写真など</dt>
|
147
|
-
<dd><input type="file" name="image" size="35" />
|
148
|
-
<?php if(!empty($image)):?>
|
149
|
-
<?php if($error['image'] == 'type'): ?>
|
150
|
-
<p class="error">* 写真などは「.gif」または「.jpg」の画像を指定してください</p>
|
151
|
-
<?php endif; ?>
|
152
|
-
<?php if(!empty($error)): ?>
|
153
|
-
<p class="error">* 恐れ入りますが、画像を改めて指定してください</p>
|
154
|
-
<?php endif; ?>
|
155
|
-
<?php endif; ?>
|
156
|
-
</dd>
|
157
|
-
|
125
|
+
</dl>
|
158
|
-
|
126
|
+
<div><input type="submit" value="ログインする" /></div>
|
159
|
-
|
127
|
+
</form>
|
160
128
|
</body>
|
161
129
|
</html>
|
162
130
|
```
|