01.
<?php
02.
class
Authen
extends
CI_Controller
03.
{
04.
function
__construct()
05.
{
06.
parent::__construct();
07.
$user
=
$this
->session->userdata(
"SESS_USERNAME"
);
08.
if
(
$user
!=
''
)
09.
{
10.
redirect(
"/main"
,
"refresh"
);
11.
}
12.
}
13.
14.
function
index()
15.
{
16.
$this
->load->view(
"login"
);
17.
}
18.
function
chklogin()
19.
{
20.
$data
[
"user"
]=
$this
->input->post(
"username"
);
21.
$data
[
"pass"
]=
$this
->input->post(
"password"
);
22.
$this
->load->model(
"Login_model"
);
23.
24.
$num
=
$this
->Login_model->checklogin(
$data
);
25.
if
(
$num
==0)
26.
{
27.
redirect(
"/loginerror"
,
"refresh"
);
28.
}
else
29.
{
30.
$this
->session->set_userdata(
"SESS_USERNAME"
,
$data
[
'user'
]);
31.
redirect(
"/main"
,
"refresh"
);
32.
}
33.
}
34.
35.
function
logout()
36.
{
37.
$this
->session->unset_userdata(
"SESS_USERNAME"
);
38.
$this
->session->sess_destroy();
39.
redirect(
"/authen"
,
"refresh"
);
40.
}
41.
}
42.
?>