質問編集履歴
2
send.phpの全コード記載、HTMLとjavascriptのコード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,6 +10,18 @@
|
|
10
10
|
|
11
11
|
session_start();
|
12
12
|
|
13
|
+
ini_set('display_errors', 1);
|
14
|
+
|
15
|
+
ini_set('error_reporting', E_ALL);
|
16
|
+
|
17
|
+
ini_set('log_errors', 'On');
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
// ログの保存先
|
22
|
+
|
23
|
+
ini_set('error_log', __DIR__ . '/error.log');
|
24
|
+
|
13
25
|
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')) {
|
14
26
|
|
15
27
|
if($_SERVER["REQUEST_METHOD"] == "POST"){
|
@@ -42,7 +54,7 @@
|
|
42
54
|
|
43
55
|
if(isset($_SESSION['user_trip'])){
|
44
56
|
|
45
|
-
$Trip = $_SESSION['user_trip'];
|
57
|
+
$Trip = htmlspecialchars($_SESSION['user_trip']);
|
46
58
|
|
47
59
|
}
|
48
60
|
|
@@ -52,9 +64,9 @@
|
|
52
64
|
|
53
65
|
$Textcolor = htmlspecialchars($_SESSION['text_color']);
|
54
66
|
|
55
|
-
$Unixtime = $_SERVER['REQUEST_TIME'];
|
67
|
+
$Unixtime = htmlspecialchars($_SERVER['REQUEST_TIME']);
|
56
|
-
|
68
|
+
|
57
|
-
$IPaddress = $_SERVER["REMOTE_ADDR"];
|
69
|
+
$IPaddress = htmlspecialchars($_SERVER["REMOTE_ADDR"]);
|
58
70
|
|
59
71
|
$Hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
|
60
72
|
|
@@ -128,6 +140,16 @@
|
|
128
140
|
|
129
141
|
$result2 = file_put_contents($url2, $out_json2, LOCK_EX);
|
130
142
|
|
143
|
+
session_write_close();
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
header("Content-Type: application/json; charset=UTF-8");
|
148
|
+
|
149
|
+
echo json_encode($_SESSION);
|
150
|
+
|
151
|
+
exit;
|
152
|
+
|
131
153
|
}
|
132
154
|
|
133
155
|
}
|
@@ -151,3 +173,307 @@
|
|
151
173
|
array(11) { ["room_id"]=> string(8) "◆◆◆" ["user_name"]=> string(9) "◆◆◆" ["user_trip"]=> string(0) "" ["user_state"]=> string(0) "" ["last_log"]=> array(5) { ["num"]=> int(12) ["type"]=> string(4) "info" ["unixtime"]=> int(1567731477) ["name"]=> string(12) "◆◆◆" ["message"]=> string(43) "◆◆◆" } ["last_log_num"]=> int(12) ["name_color"]=> string(5) "black" ["text_color"]=> string(5) "black" ["csrf_token"]=> string(32) "0e82781dc1bc513c6118aa753eb94d14" ["username"]=> string(5) "◆◆◆" ["user_log"]=> string(0) "" }
|
152
174
|
|
153
175
|
```
|
176
|
+
|
177
|
+
【追記】
|
178
|
+
|
179
|
+
HTML(PHP)、javascriptも記載します。
|
180
|
+
|
181
|
+
//「room.php」HTML(PHP)
|
182
|
+
|
183
|
+
※文字数制限のため一部省略しています
|
184
|
+
|
185
|
+
```PHP
|
186
|
+
|
187
|
+
<?php
|
188
|
+
|
189
|
+
session_start();
|
190
|
+
|
191
|
+
session_id(sha1(uniqid(microtime())));
|
192
|
+
|
193
|
+
if( !isset( $_SESSION['room_id'] ) ) {
|
194
|
+
|
195
|
+
$_SESSION['room_id'] = $_GET['id'];
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
$_SESSION['user_name'] = "";
|
200
|
+
|
201
|
+
$_SESSION['user_trip'] = "";
|
202
|
+
|
203
|
+
$_SESSION['user_state'] = "";
|
204
|
+
|
205
|
+
$_SESSION['last_log'] = "";
|
206
|
+
|
207
|
+
$_SESSION['last_log_num'] = "";
|
208
|
+
|
209
|
+
$_SESSION['name_color'] = "";
|
210
|
+
|
211
|
+
$_SESSION['text_color'] = "";
|
212
|
+
|
213
|
+
$_SESSION['csrf_token'] = "";
|
214
|
+
|
215
|
+
$toke_byte = openssl_random_pseudo_bytes(16);
|
216
|
+
|
217
|
+
$csrf_token = bin2hex($toke_byte);
|
218
|
+
|
219
|
+
$_SESSION['csrf_token'] = $csrf_token;
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
$json = file_get_contents('data/roomlist.json');
|
224
|
+
|
225
|
+
$array = json_decode($json, true);
|
226
|
+
|
227
|
+
$result = array_keys(array_column($array, 'id'), $_GET["id"]);
|
228
|
+
|
229
|
+
if(!isset($_GET["id"]) || empty($result)){
|
230
|
+
|
231
|
+
header("HTTP/1.1 404 Not Found");
|
232
|
+
|
233
|
+
header('Location: ./');
|
234
|
+
|
235
|
+
exit;
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
foreach ($result as $index) {
|
240
|
+
|
241
|
+
$room_name = $array[$index]['name'];
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
?>
|
246
|
+
|
247
|
+
<!DOCTYPE html>
|
248
|
+
|
249
|
+
<html lang="ja">
|
250
|
+
|
251
|
+
<head>
|
252
|
+
|
253
|
+
<meta charset="utf-8">
|
254
|
+
|
255
|
+
<title><?php echo $room_name ?> - チャット</title>
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
<link href="css/main.css" rel="stylesheet" type="text/css">
|
260
|
+
|
261
|
+
<script src="js/jquery.js" type="text/javascript"></script>
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
<script src="js/lib/eventsource.js"></script>
|
266
|
+
|
267
|
+
<script type="text/javascript" src="js/script_room.js"></script>
|
268
|
+
|
269
|
+
<script type="text/javascript" src="js/jquery.cookie.js"></script>
|
270
|
+
|
271
|
+
<script type="text/javascript">
|
272
|
+
|
273
|
+
<!--
|
274
|
+
|
275
|
+
$(document).ready(function(){
|
276
|
+
|
277
|
+
initScript();
|
278
|
+
|
279
|
+
});
|
280
|
+
|
281
|
+
-->
|
282
|
+
|
283
|
+
</script>
|
284
|
+
|
285
|
+
</head>
|
286
|
+
|
287
|
+
<body>
|
288
|
+
|
289
|
+
<article id="mainbox" ontouchstart="">
|
290
|
+
|
291
|
+
<h1><?php echo $room_name ?></h1>
|
292
|
+
|
293
|
+
<section id="userform" class="on">
|
294
|
+
|
295
|
+
<form action="php/userinout.php" method="post">
|
296
|
+
|
297
|
+
<input type="hidden" name="State" value="in">
|
298
|
+
|
299
|
+
<input type="text" name="Name" maxlength="20" value="" placeholder="お名前(最大20文字)"/>
|
300
|
+
|
301
|
+
<input name="Passcode" size="40" type="text" maxlength="10" value="" placeholder="トリップ(最大10文字)">
|
302
|
+
|
303
|
+
<script language="JavaScript" type="text/javascript">
|
304
|
+
|
305
|
+
<!--
|
306
|
+
|
307
|
+
document.write('<input type="submit" id="submit" name="submit" value="入室"/>');
|
308
|
+
|
309
|
+
-->
|
310
|
+
|
311
|
+
</script>
|
312
|
+
|
313
|
+
<noscript>JavaScriptを有効にしてください</noscript>
|
314
|
+
|
315
|
+
</form>
|
316
|
+
|
317
|
+
</section>
|
318
|
+
|
319
|
+
<section id="sendform" class="on">
|
320
|
+
|
321
|
+
<form action="php/send.php" method="post">
|
322
|
+
|
323
|
+
<input type="hidden" name="csrf_token" value="<?php echo $csrf_token ?>">
|
324
|
+
|
325
|
+
<input type="hidden" name="Type" value="normal">
|
326
|
+
|
327
|
+
<input name="Message" placeholder="メッセージ(最大200文字)" maxlength="200"></textarea>
|
328
|
+
|
329
|
+
<script language="JavaScript" type="text/javascript">
|
330
|
+
|
331
|
+
<!--
|
332
|
+
|
333
|
+
document.write('<input type="submit" id="submit" name="submit" value="送信"/>');
|
334
|
+
|
335
|
+
-->
|
336
|
+
|
337
|
+
</script>
|
338
|
+
|
339
|
+
<noscript>JavaScriptを有効にしてください</noscript>
|
340
|
+
|
341
|
+
</form>
|
342
|
+
|
343
|
+
<button id="chatout-btn" href="javascript:void(0);" onclick="chatOut();">退室する</a>
|
344
|
+
|
345
|
+
</section>
|
346
|
+
|
347
|
+
<p id="formerror"></p>
|
348
|
+
|
349
|
+
<span class="usercount">入室者 0人</span>
|
350
|
+
|
351
|
+
<span class="romcount">閲覧者 0人</span>
|
352
|
+
|
353
|
+
<hr>
|
354
|
+
|
355
|
+
<section id="log-frame">
|
356
|
+
|
357
|
+
</section>
|
358
|
+
|
359
|
+
</article>
|
360
|
+
|
361
|
+
<footer>
|
362
|
+
|
363
|
+
<p><small>Copyright© 2019 XXX</small></p>
|
364
|
+
|
365
|
+
</footer>
|
366
|
+
|
367
|
+
</body>
|
368
|
+
|
369
|
+
</html>
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
```
|
374
|
+
|
375
|
+
//「script_room.js」javascript
|
376
|
+
|
377
|
+
※文字数制限のためajax通信部分のみ記載します
|
378
|
+
|
379
|
+
```javascript
|
380
|
+
|
381
|
+
if($('#sendform')){
|
382
|
+
|
383
|
+
$("#sendform form").submit(function(e){
|
384
|
+
|
385
|
+
e.preventDefault();
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
if ($("input[name='Message']").val() == '') {
|
390
|
+
|
391
|
+
$("#formerror").text("メッセージを入力してください");
|
392
|
+
|
393
|
+
return false;
|
394
|
+
|
395
|
+
}else if (hasNGWords($("input[name='Message']").val(), ngwords)){
|
396
|
+
|
397
|
+
$("#formerror").text("メッセージに禁止ワードが含まれています");
|
398
|
+
|
399
|
+
return false;
|
400
|
+
|
401
|
+
}else if ($("input[name='Message']").val().length > 200) {
|
402
|
+
|
403
|
+
$("#formerror").text("メッセージが長すぎます(最大200文字)");
|
404
|
+
|
405
|
+
return false;
|
406
|
+
|
407
|
+
}else{
|
408
|
+
|
409
|
+
$("#formerror").text("");
|
410
|
+
|
411
|
+
$.ajax({
|
412
|
+
|
413
|
+
type: $(this).attr('method'),
|
414
|
+
|
415
|
+
url: $(this).attr('action'),
|
416
|
+
|
417
|
+
data: $(this).serialize(),
|
418
|
+
|
419
|
+
timeout: 10000, // 単位はミリ秒
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
// 送信前
|
424
|
+
|
425
|
+
beforeSend: function(xhr, settings) {
|
426
|
+
|
427
|
+
// ボタンを無効化し、二重送信を防止
|
428
|
+
|
429
|
+
$("#sendform #submit").val("送信中…").prop("disabled",true);
|
430
|
+
|
431
|
+
},
|
432
|
+
|
433
|
+
// 応答後
|
434
|
+
|
435
|
+
complete: function(xhr, textStatus) {
|
436
|
+
|
437
|
+
// ボタンを有効化し、再送信を許可
|
438
|
+
|
439
|
+
//$.cookie("SendRegulation", "true", {expires: date, path: "/", domain: ""});
|
440
|
+
|
441
|
+
},
|
442
|
+
|
443
|
+
success: function(result, textStatus, xhr, data) {
|
444
|
+
|
445
|
+
console.log(result);
|
446
|
+
|
447
|
+
$("input[name = 'Message']").val('');
|
448
|
+
|
449
|
+
$("#sendform #submit").val("送信").prop("disabled",false);
|
450
|
+
|
451
|
+
//logDataRead();
|
452
|
+
|
453
|
+
},
|
454
|
+
|
455
|
+
// 通信失敗時の処理
|
456
|
+
|
457
|
+
error: function(xhr, textStatus, error) {
|
458
|
+
|
459
|
+
$("#formerror").text("送信に失敗しました");
|
460
|
+
|
461
|
+
}
|
462
|
+
|
463
|
+
});
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
return false;
|
468
|
+
|
469
|
+
}
|
470
|
+
|
471
|
+
return false;
|
472
|
+
|
473
|
+
});
|
474
|
+
|
475
|
+
}
|
476
|
+
|
477
|
+
}
|
478
|
+
|
479
|
+
```
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -139,3 +139,15 @@
|
|
139
139
|
?>
|
140
140
|
|
141
141
|
```
|
142
|
+
|
143
|
+
【追記】
|
144
|
+
|
145
|
+
var_dump($_SESSION);した結果を記載します。
|
146
|
+
|
147
|
+
※「◆◆◆」は諸事情により伏字にしてあります
|
148
|
+
|
149
|
+
```php
|
150
|
+
|
151
|
+
array(11) { ["room_id"]=> string(8) "◆◆◆" ["user_name"]=> string(9) "◆◆◆" ["user_trip"]=> string(0) "" ["user_state"]=> string(0) "" ["last_log"]=> array(5) { ["num"]=> int(12) ["type"]=> string(4) "info" ["unixtime"]=> int(1567731477) ["name"]=> string(12) "◆◆◆" ["message"]=> string(43) "◆◆◆" } ["last_log_num"]=> int(12) ["name_color"]=> string(5) "black" ["text_color"]=> string(5) "black" ["csrf_token"]=> string(32) "0e82781dc1bc513c6118aa753eb94d14" ["username"]=> string(5) "◆◆◆" ["user_log"]=> string(0) "" }
|
152
|
+
|
153
|
+
```
|