質問編集履歴
2
整形
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
ログイン日時をセッションに格納したい
|
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
```php
|
28
28
|
|
29
|
-
|
29
|
+
<?php
|
30
30
|
|
31
31
|
session_start();
|
32
32
|
|
@@ -34,9 +34,9 @@
|
|
34
34
|
|
35
35
|
if (isset($_SESSION["NAME"])) {
|
36
36
|
|
37
|
-
|
37
|
+
header("Location: my.php");
|
38
38
|
|
39
|
-
|
39
|
+
exit;
|
40
40
|
|
41
41
|
}
|
42
42
|
|
@@ -64,131 +64,131 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
|
67
|
-
|
67
|
+
if (isset($_POST["login"])) {
|
68
68
|
|
69
|
-
|
69
|
+
if (empty($_POST["mail"])) {
|
70
70
|
|
71
|
-
|
71
|
+
$errorMessage = '※空やでやで';
|
72
72
|
|
73
|
-
|
73
|
+
} else if (empty($_POST["password"])) {
|
74
74
|
|
75
|
-
|
75
|
+
$errorMessage_2 = '※空やで。';
|
76
76
|
|
77
|
-
|
77
|
+
} else if (!preg_match('/^[!-~]+@[!-~]+$/', $_POST["mail"])){
|
78
78
|
|
79
|
-
|
79
|
+
$errorMessage = '※正規表現外mail';
|
80
80
|
|
81
|
-
|
81
|
+
} else if (!preg_match("/\A(?=.*?[a-z])(?=.*?\d)[a-z\d]{8,100}+\z/i", $_POST["password"])){
|
82
82
|
|
83
|
-
|
83
|
+
$errorMessage_2 = '※正規表現外pass';
|
84
84
|
|
85
|
-
|
85
|
+
} else if (!preg_match("/^.{4,32}$/",$_POST["mail"])){
|
86
86
|
|
87
|
-
|
87
|
+
$errorMessage = '※桁数上mail';
|
88
88
|
|
89
|
-
|
89
|
+
} else if (!preg_match("/^.{4,32}$/",$_POST["password"])){
|
90
90
|
|
91
|
-
|
91
|
+
$errorMessage_2 = '※桁数上pass';
|
92
92
|
|
93
93
|
|
94
94
|
|
95
|
-
|
95
|
+
}else{
|
96
96
|
|
97
97
|
|
98
98
|
|
99
|
-
|
99
|
+
if (!empty($_POST["mail"]) && !empty($_POST["password"])) {
|
100
100
|
|
101
|
-
|
101
|
+
$mail = $_POST["mail"];
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
$dsn = sprintf('mysql:host=%s; dbname=%s; charset=utf8;unix_socket=/tmp/mysql.sock', $db['host'], $db['dbname']);
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
try {
|
110
|
-
|
111
|
-
$pdo = new PDO($dsn, $db['user'], $db['pass'], array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
|
112
|
-
|
113
|
-
$stmt = $pdo->prepare('SELECT * FROM member WHERE mail = ?');
|
114
|
-
|
115
|
-
$stmt->execute(array($mail));
|
116
|
-
|
117
|
-
$password = $_POST["password"];
|
118
102
|
|
119
103
|
|
120
104
|
|
121
|
-
|
105
|
+
$dsn = sprintf('mysql:host=%s; dbname=%s; charset=utf8;unix_socket=/tmp/mysql.sock', $db['host'], $db['dbname']);
|
122
106
|
|
123
|
-
if (password_verify($password, $row['password'])) {
|
124
107
|
|
125
|
-
session_regenerate_id(true);
|
126
108
|
|
127
|
-
|
109
|
+
try {
|
128
110
|
|
129
|
-
|
111
|
+
$pdo = new PDO($dsn, $db['user'], $db['pass'], array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
|
130
112
|
|
131
|
-
|
113
|
+
$stmt = $pdo->prepare('SELECT * FROM member WHERE mail = ?');
|
132
114
|
|
133
|
-
|
115
|
+
$stmt->execute(array($mail));
|
134
116
|
|
135
|
-
|
117
|
+
$password = $_POST["password"];
|
136
118
|
|
137
|
-
$row['mail'];
|
138
119
|
|
139
|
-
}
|
140
120
|
|
141
|
-
|
121
|
+
if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
142
122
|
|
143
|
-
|
123
|
+
if (password_verify($password, $row['password'])) {
|
144
124
|
|
145
|
-
|
125
|
+
session_regenerate_id(true);
|
146
126
|
|
147
|
-
$sql = "UPDATE member SET sdate='$date' WHERE id='$id'";
|
148
127
|
|
149
|
-
$result = $pdo->query($sql);
|
150
128
|
|
151
|
-
|
129
|
+
$id = $row['id'];
|
152
130
|
|
153
|
-
|
131
|
+
$sql = "SELECT * FROM member WHERE id = $id"; //入力したIDからユーザー名を取得
|
154
132
|
|
155
|
-
|
133
|
+
$stmt = $pdo->query($sql);
|
156
134
|
|
157
|
-
|
135
|
+
foreach ($stmt as $row) {
|
158
136
|
|
159
|
-
|
137
|
+
$row['mail'];
|
160
138
|
|
161
|
-
|
139
|
+
}
|
162
140
|
|
163
|
-
exit();
|
164
141
|
|
165
|
-
|
166
142
|
|
167
|
-
|
143
|
+
$stmt = $pdo->prepare('SELECT * FROM member WHERE sdate = ?');
|
168
144
|
|
169
|
-
|
145
|
+
$stmt->execute(array($date));
|
170
146
|
|
171
|
-
|
147
|
+
$sql = "UPDATE member SET sdate='$date' WHERE id='$id'";
|
172
148
|
|
173
|
-
|
149
|
+
$result = $pdo->query($sql);
|
174
150
|
|
175
|
-
} else {
|
176
151
|
|
177
|
-
$errorMessage = '※該当データなしmailまたはPasswordが間違っています。';
|
178
152
|
|
179
|
-
}
|
180
153
|
|
181
|
-
} catch (PDOException $e) {
|
182
154
|
|
183
|
-
$errorMessage = header("Location: 500.php");
|
184
155
|
|
185
|
-
}
|
186
156
|
|
187
|
-
|
157
|
+
$_SESSION["sdate"] = $row['sdate'];
|
188
158
|
|
189
|
-
|
159
|
+
$_SESSION["mail"] = $row['mail'];
|
190
160
|
|
161
|
+
header("location: my.php");
|
162
|
+
|
163
|
+
exit();
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
} else {
|
170
|
+
|
171
|
+
$errorMessage = '※mailまたはPasswordが間違っています。';
|
172
|
+
|
191
|
-
|
173
|
+
}
|
174
|
+
|
175
|
+
} else {
|
176
|
+
|
177
|
+
$errorMessage = '※該当データなしmailまたはPasswordが間違っています。';
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
} catch (PDOException $e) {
|
182
|
+
|
183
|
+
$errorMessage = header("Location: 500.php");
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
192
|
|
193
193
|
|
194
194
|
|
1
コード修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ログイン日時をセッションに格納したい
|
1
|
+
こログイン日時をセッションに格納したい
|
test
CHANGED
@@ -26,7 +26,83 @@
|
|
26
26
|
|
27
27
|
```php
|
28
28
|
|
29
|
+
<?php
|
30
|
+
|
31
|
+
session_start();
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
if (isset($_SESSION["NAME"])) {
|
36
|
+
|
37
|
+
header("Location: my.php");
|
38
|
+
|
39
|
+
exit;
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
$db['host'] = "hoge";
|
46
|
+
|
47
|
+
$db['user'] = "hoge";
|
48
|
+
|
49
|
+
$db['pass'] = "hoge";
|
50
|
+
|
51
|
+
$db['dbname'] = "hoge";
|
52
|
+
|
53
|
+
$date = date('Y-m-d H:i:s');
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
$errorMessage = "";
|
58
|
+
|
59
|
+
$errorMessage_2 = "";
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
require_once 'hasu_test.php';
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
if (isset($_POST["login"])) {
|
68
|
+
|
69
|
+
if (empty($_POST["mail"])) {
|
70
|
+
|
71
|
+
$errorMessage = '※空やでやで';
|
72
|
+
|
73
|
+
} else if (empty($_POST["password"])) {
|
74
|
+
|
75
|
+
$errorMessage_2 = '※空やで。';
|
76
|
+
|
77
|
+
} else if (!preg_match('/^[!-~]+@[!-~]+$/', $_POST["mail"])){
|
78
|
+
|
79
|
+
$errorMessage = '※正規表現外mail';
|
80
|
+
|
81
|
+
} else if (!preg_match("/\A(?=.*?[a-z])(?=.*?\d)[a-z\d]{8,100}+\z/i", $_POST["password"])){
|
82
|
+
|
83
|
+
$errorMessage_2 = '※正規表現外pass';
|
84
|
+
|
85
|
+
} else if (!preg_match("/^.{4,32}$/",$_POST["mail"])){
|
86
|
+
|
87
|
+
$errorMessage = '※桁数上mail';
|
88
|
+
|
89
|
+
} else if (!preg_match("/^.{4,32}$/",$_POST["password"])){
|
90
|
+
|
91
|
+
$errorMessage_2 = '※桁数上pass';
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
}else{
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
if (!empty($_POST["mail"]) && !empty($_POST["password"])) {
|
100
|
+
|
101
|
+
$mail = $_POST["mail"];
|
102
|
+
|
103
|
+
|
104
|
+
|
29
|
-
$dsn = sprintf('mysql:host=%s; dbname=%s; charset=utf8;unix_socket=/tmp/mysql.sock', $db['host'], $db['dbname']);
|
105
|
+
$dsn = sprintf('mysql:host=%s; dbname=%s; charset=utf8;unix_socket=/tmp/mysql.sock', $db['host'], $db['dbname']);
|
30
106
|
|
31
107
|
|
32
108
|
|
@@ -34,68 +110,88 @@
|
|
34
110
|
|
35
111
|
$pdo = new PDO($dsn, $db['user'], $db['pass'], array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
|
36
112
|
|
37
|
-
|
38
|
-
|
39
113
|
$stmt = $pdo->prepare('SELECT * FROM member WHERE mail = ?');
|
40
114
|
|
41
115
|
$stmt->execute(array($mail));
|
42
116
|
|
117
|
+
$password = $_POST["password"];
|
43
118
|
|
44
119
|
|
45
|
-
$password = $_POST["password"];
|
46
|
-
|
47
|
-
|
48
120
|
|
49
121
|
if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
50
122
|
|
51
123
|
if (password_verify($password, $row['password'])) {
|
52
124
|
|
53
|
-
|
125
|
+
session_regenerate_id(true);
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
$id = $row['id'];
|
130
|
+
|
131
|
+
$sql = "SELECT * FROM member WHERE id = $id"; //入力したIDからユーザー名を取得
|
132
|
+
|
133
|
+
$stmt = $pdo->query($sql);
|
134
|
+
|
135
|
+
foreach ($stmt as $row) {
|
136
|
+
|
137
|
+
$row['mail'];
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
$stmt = $pdo->prepare('SELECT * FROM member WHERE sdate = ?');
|
144
|
+
|
145
|
+
$stmt->execute(array($date));
|
146
|
+
|
147
|
+
$sql = "UPDATE member SET sdate='$date' WHERE id='$id'";
|
148
|
+
|
149
|
+
$result = $pdo->query($sql);
|
150
|
+
|
151
|
+
|
54
152
|
|
55
153
|
|
56
154
|
|
155
|
+
|
57
156
|
|
157
|
+
$_SESSION["sdate"] = $row['sdate'];
|
58
158
|
|
59
|
-
|
159
|
+
$_SESSION["mail"] = $row['mail'];
|
60
160
|
|
161
|
+
header("location: my.php");
|
61
162
|
|
62
|
-
|
63
|
-
// 入力したIDのmialを取得
|
64
|
-
|
65
|
-
$id = $row['id'];
|
66
|
-
|
67
|
-
$sql = "SELECT * FROM member WHERE id = $id"; //入力したIDからユーザー名取得
|
68
|
-
|
69
|
-
$stmt = $pdo->query($sql);
|
70
|
-
|
71
|
-
foreach ($stmt as $row) {
|
72
|
-
|
73
|
-
$row['mail']; // メール
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
//アップデートを実行完了した後に、セッションにログイン日時を格納したい
|
78
|
-
|
79
|
-
$stmt = $pdo->prepare('SELECT * FROM member WHERE sdate = ?');
|
80
|
-
|
81
|
-
|
163
|
+
exit();
|
82
|
-
|
83
|
-
$sql = "UPDATE member SET sdate='$date' WHERE id='$id'";
|
84
|
-
|
85
|
-
$result = $pdo->query($sql);
|
86
|
-
|
87
|
-
|
88
164
|
|
89
165
|
|
90
166
|
|
91
167
|
|
92
168
|
|
93
|
-
|
169
|
+
} else {
|
94
170
|
|
95
|
-
|
171
|
+
$errorMessage = '※mailまたはPasswordが間違っています。';
|
96
172
|
|
97
|
-
|
173
|
+
}
|
98
174
|
|
175
|
+
} else {
|
176
|
+
|
177
|
+
$errorMessage = '※該当データなしmailまたはPasswordが間違っています。';
|
178
|
+
|
179
|
+
}
|
180
|
+
|
99
|
-
|
181
|
+
} catch (PDOException $e) {
|
182
|
+
|
183
|
+
$errorMessage = header("Location: 500.php");
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
?>
|
100
196
|
|
101
197
|
```
|