-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.php
More file actions
131 lines (101 loc) · 3.8 KB
/
chat.php
File metadata and controls
131 lines (101 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
include("./sql_info.php");
session_start();
function h($s){
return htmlspecialchars($s, ENT_QUOTES, 'utf-8');
}
$user_found = false; //ユーザーが見つかったか
//ユーザー名の存在を確認
if(isset($_GET["u"])){
$user_name = $_GET["u"]; //search keyword
if(!preg_match("/^[0-9A-Za-z]+$/", $user_name)){
exit();
}
try{
$dbh = new PDO($dsn, $sql_user, $sql_password);
//userが存在しているか
$result = $dbh->query("select * from users where id='".$user_name."';");
foreach($result as $row){
if($row["id"] === $user_name){
$user_found = true;
}
}
}catch (PDOException $e){
print('Error:'.$e->getMessage());
die();
}
}
if($user_found == false){
echo("404 Not found.");
exit();
}
?>
<html>
<head>
<meta charset="UTF-8">
<title>easeLp Help Chat - <?php
//ユーザー名を表示
if($user_found == false){
//userが存在しなかったら
echo('Not Not found this user');
}else{
//存在したら
echo($user_name);
}?></title>
<link rel="stylesheet" href="./css/style.css">
<link rel="stylesheet" href="./css/chat.css">
<link rel="preconnect" href="https://rsms.me/">
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
<link rel="preconnect" href="https://fonts.googleapis.com/">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Quicksand:300,400,500,700">
<link rel="icon" type="image/svg+xml" href="./logo.svg" />
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/a11y-dark.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
</head>
<body>
<header>
<?php include("./header.php"); ?>
</header>
<div id="chat_area">
<?php
if($user_found){
echo(
<div class="chat_title">Chat Help - '.$user_name.'</div>
<div id="chat_main">
<div class="chat_text bot">
Hello,Do you have any questions about '.$user_name.'?<br>
words: <input id="word_num" type="number" value="50">
</div>
</div>
<div id="chat_textbox_block">
<input id="chat_textbox" placeholder="here your question.">
</div>
');
}else{
echo('<div class="chat_title" style="color:#ff0055;font-weight:200;">404 Not found</div>');
}
?>
</div>
<script>
<?php
if($user_found == false){
//userが存在しなかったら空
echo('const user_name = "";');
}else{
//存在したら変数に追加
echo('const user_name = "'.$user_name.'";');
}
//ログイン状態
if(isset($_SESSION['id'])){
echo('const user_id = "'.h($_SESSION['id']).'";');
}else{
echo('const user_id = "";');
}
?>
</script>
<script src="main.js"></script>
<script src="js/chatbot.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
</body>
</html>