回答編集履歴
4
新規登録コードを追加しました。
test
CHANGED
@@ -195,3 +195,161 @@
|
|
195
195
|
</html>
|
196
196
|
|
197
197
|
```
|
198
|
+
|
199
|
+
```sinki.php
|
200
|
+
|
201
|
+
<?php
|
202
|
+
|
203
|
+
// セッション開始
|
204
|
+
|
205
|
+
session_start();
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
$db['host'] = "localhost"; // DBサーバのURL
|
210
|
+
|
211
|
+
$db['user'] = "hogeUser"; // ユーザー名
|
212
|
+
|
213
|
+
$db['pass'] = "hogehoge"; // ユーザー名のパスワード
|
214
|
+
|
215
|
+
$db['dbname'] = "loginManagement"; // データベース名
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
// エラーメッセージ、登録完了メッセージの初期化
|
220
|
+
|
221
|
+
$errorMessage = "";
|
222
|
+
|
223
|
+
$signUpMessage = "";
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
// ログインボタンが押された場合
|
228
|
+
|
229
|
+
if (isset($_POST["signUp"])) {
|
230
|
+
|
231
|
+
// 1. ユーザIDの入力チェック
|
232
|
+
|
233
|
+
if (empty($_POST["username"])) { // 値が空のとき
|
234
|
+
|
235
|
+
$errorMessage = 'ユーザーIDが未入力です。';
|
236
|
+
|
237
|
+
} else if (empty($_POST["password"])) {
|
238
|
+
|
239
|
+
$errorMessage = 'パスワードが未入力です。';
|
240
|
+
|
241
|
+
} else if (empty($_POST["URL"])) {
|
242
|
+
|
243
|
+
$errorMessage = 'URLが未入力です。';
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
if (!empty($_POST["username"]) && !empty($_POST["password"]) && !empty($_POST["URL"])) {
|
250
|
+
|
251
|
+
// 入力したユーザIDとパスワードを格納
|
252
|
+
|
253
|
+
$username = $_POST["username"];
|
254
|
+
|
255
|
+
$password = $_POST["password"];
|
256
|
+
|
257
|
+
$URL = $_POST["URL"];
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
// 2. ユーザIDとパスワードが入力されていたら認証する
|
262
|
+
|
263
|
+
$dsn = sprintf('mysql: host=%s; dbname=%s; charset=utf8', $db['host'], $db['dbname']);
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
// 3. エラー処理
|
268
|
+
|
269
|
+
try {
|
270
|
+
|
271
|
+
$pdo = new PDO($dsn, $db['user'], $db['pass'], array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
$stmt = $pdo->prepare("INSERT INTO userData(name, password, link) VALUES (?, ?, ?)");
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
$stmt->execute(array($username, $password, $URL));
|
280
|
+
|
281
|
+
$userid = $pdo->lastinsertid(); // 登録した(DB側でauto_incrementした)IDを$useridに入れる
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
$signUpMessage = '登録が完了しました。あなたの登録IDは '. $userid. ' です。パスワードは '. $password. ' です。'; // ログイン時に使用するIDとパスワード
|
286
|
+
|
287
|
+
} catch (PDOException $e) {
|
288
|
+
|
289
|
+
$errorMessage = 'データベースエラー';
|
290
|
+
|
291
|
+
// $e->getMessage() でエラー内容を参照可能(デバッグ時のみ表示)
|
292
|
+
|
293
|
+
// echo $e->getMessage();
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
?>
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
<!doctype html>
|
306
|
+
|
307
|
+
<html>
|
308
|
+
|
309
|
+
<head>
|
310
|
+
|
311
|
+
<meta charset="UTF-8">
|
312
|
+
|
313
|
+
<title>新規登録</title>
|
314
|
+
|
315
|
+
</head>
|
316
|
+
|
317
|
+
<body>
|
318
|
+
|
319
|
+
<h1>新規登録画面</h1>
|
320
|
+
|
321
|
+
<form id="loginForm" name="loginForm" action="" method="POST">
|
322
|
+
|
323
|
+
<fieldset>
|
324
|
+
|
325
|
+
<legend>新規登録フォーム</legend>
|
326
|
+
|
327
|
+
<div><font color="#ff0000"><?php echo htmlspecialchars($errorMessage, ENT_QUOTES); ?></font></div>
|
328
|
+
|
329
|
+
<div><font color="#0000ff"><?php echo htmlspecialchars($signUpMessage, ENT_QUOTES); ?></font></div>
|
330
|
+
|
331
|
+
<label for="username">ユーザー名</label><input type="text" id="username" name="username" placeholder="ユーザー名を入力" value="<?php if (!empty($_POST["username"])) {echo htmlspecialchars($_POST["username"], ENT_QUOTES);} ?>">
|
332
|
+
|
333
|
+
<br>
|
334
|
+
|
335
|
+
<label for="password">パスワード</label><input type="password" id="password" name="password" value="" placeholder="パスワードを入力">
|
336
|
+
|
337
|
+
<br>
|
338
|
+
|
339
|
+
<label for="URL">URL</label><input type="text" id="URL" name="URL" value="" placeholder="URLを入力">
|
340
|
+
|
341
|
+
<br>
|
342
|
+
|
343
|
+
<input type="submit" id="signUp" name="signUp" value="新規登録">
|
344
|
+
|
345
|
+
</fieldset>
|
346
|
+
|
347
|
+
</form>
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
</body>
|
352
|
+
|
353
|
+
</html>
|
354
|
+
|
355
|
+
```
|
3
誤字の修正
test
CHANGED
@@ -104,7 +104,9 @@
|
|
104
104
|
|
105
105
|
$_SESSION["NAME"] = $row['name'];
|
106
106
|
|
107
|
+
//スペルミスをしていました。'rink'ではなく、'link'です。
|
108
|
+
|
107
|
-
header("Location:".$row['
|
109
|
+
header("Location:".$row['link']);
|
108
110
|
|
109
111
|
exit(); // 処理終了
|
110
112
|
|
2
コードの間違いを修正しました
test
CHANGED
@@ -78,7 +78,9 @@
|
|
78
78
|
|
79
79
|
if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
80
80
|
|
81
|
+
//ここ間違ってました。すみません。
|
82
|
+
|
81
|
-
if (
|
83
|
+
if ($password == $row['password']) {
|
82
84
|
|
83
85
|
session_regenerate_id(true);
|
84
86
|
|
1
codeの間違いを訂正しました
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
MySQLとphpを使って以下のコードで出来ます。
|
2
2
|
|
3
|
-
```index
|
3
|
+
```indexphp
|
4
4
|
|
5
5
|
<?php
|
6
6
|
|
@@ -158,20 +158,6 @@
|
|
158
158
|
|
159
159
|
<body>
|
160
160
|
|
161
|
-
<!--shinobibarrier1-->
|
162
|
-
|
163
|
-
<script type="text/javascript" src="./bk.js"></script>
|
164
|
-
|
165
|
-
<script type="text/javascript" src="http://bar1.shinobi.jp/s/89/00708.js"></script>
|
166
|
-
|
167
|
-
<noscript><meta http-equiv="refresh" content="0;URL=http://bar1.shinobi.jp/hoge/NoScript?0070889" />
|
168
|
-
|
169
|
-
<div style="background-color: #000000;text-align: center;vertical-align: middle;width:100%;height: 100%;margin: -10px;padding: 0px;z-index: 10;position: absolute;">
|
170
|
-
|
171
|
-
<div style="color: #ffffff;margin: 0px;padding: 0px;position: absolute;top:50%;left:47%;">NINJA TOOLS</div></div></noscript>
|
172
|
-
|
173
|
-
<!--shinobibarrier2-->
|
174
|
-
|
175
161
|
|
176
162
|
|
177
163
|
<h1>ログイン画面</h1>
|
@@ -198,19 +184,7 @@
|
|
198
184
|
|
199
185
|
</form>
|
200
186
|
|
201
|
-
|
187
|
+
|
202
|
-
|
203
|
-
<form action="SignUp.php">
|
204
|
-
|
205
|
-
<fieldset>
|
206
|
-
|
207
|
-
<legend>新規登録フォーム</legend>
|
208
|
-
|
209
|
-
<input type="submit" value="新規登録">
|
210
|
-
|
211
|
-
</fieldset>
|
212
|
-
|
213
|
-
</form>
|
214
188
|
|
215
189
|
</body>
|
216
190
|
|