質問編集履歴
1
コードの省略部を入れました
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,9 +36,141 @@
|
|
36
36
|
|
37
37
|
error_reporting(E_ALL);
|
38
38
|
|
39
|
-
|
39
|
+
get_request();
|
40
|
+
|
40
|
-
|
41
|
+
check_session();
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
if(isset($_POST['user_name'],$_POST['user_passwd'])){
|
46
|
+
|
47
|
+
log_in($_POST['user_name'],$_POST['user_passwd']);
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
41
|
-
//
|
55
|
+
//functions for login program
|
56
|
+
|
57
|
+
function log_in($user,$passwd){
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
if(isset($user,$passwd)){
|
62
|
+
|
63
|
+
/*connect database*/
|
64
|
+
|
65
|
+
$mysqli = new mysqli('localhost','**********','**********','ch_users');
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
if($mysqli->connect_errno){
|
70
|
+
|
71
|
+
echo $mysqli->connect_errno . ' : ' . $mysqli->connect_error;
|
72
|
+
|
73
|
+
exit();
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
if($result = $mysqli->query("SELECT * FROM chat_users WHERE user_name = '" . $user . "' AND user_passwd = '" . $passwd . "' ")){
|
80
|
+
|
81
|
+
$num_rows = $result->num_rows;
|
82
|
+
|
83
|
+
if($num_rows == 1){
|
84
|
+
|
85
|
+
$_SESSION['login'] = true;
|
86
|
+
|
87
|
+
header('Location:/');
|
88
|
+
|
89
|
+
exit();
|
90
|
+
|
91
|
+
}else{
|
92
|
+
|
93
|
+
header('Location:login?action=error');
|
94
|
+
|
95
|
+
exit();
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
$result->close();
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
db_close();
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
function logged_out(){
|
112
|
+
|
113
|
+
session_start();
|
114
|
+
|
115
|
+
$_SESSION = array();
|
116
|
+
|
117
|
+
session_destroy();
|
118
|
+
|
119
|
+
header('Location:login');
|
120
|
+
|
121
|
+
exit();
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
function get_request(){
|
128
|
+
|
129
|
+
if(isset($_GET['action'])){
|
130
|
+
|
131
|
+
$action = $_GET['action'];
|
132
|
+
|
133
|
+
if($action == "loggedout"){
|
134
|
+
|
135
|
+
$page_title = "サインアウトしました";
|
136
|
+
|
137
|
+
logged_out();
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
}elseif($action == "error"){
|
142
|
+
|
143
|
+
$error == true;
|
144
|
+
|
145
|
+
$page_title = "エラー";
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
function check_session(){
|
156
|
+
|
157
|
+
@session_start();
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
if(isset($_SESSION['login'])){
|
162
|
+
|
163
|
+
if($_SESSION['login'] == true){
|
164
|
+
|
165
|
+
header('Location:/');
|
166
|
+
|
167
|
+
exit();
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
}
|
42
174
|
|
43
175
|
|
44
176
|
|