150
18 19
20 21
22 23
24 25
26 27
28 redirect
admin ;
} else
{ header
location: .
base_url .
index.phplogingagal_login ;
} }
publicfunction gagal_login
{ echo
Password atau username salah, Silahkan periksa kembali ;
} }
4. Buka file login.html, tuliskan kode dibawah ini, kemudian simpan dengan nama login.php
C:xampphtdocsmyproyekapplication
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 DOCTYPE html
html lang
= en
head meta
charset =
utf-8 meta
name =
viewport content
= width=device-width, initial-scale=1
title Signin
title -- Bootstrap core CSS --
link href
= ?php
echo base_url
? assetscssbootstrap.min.css
rel =
stylesheet link
href =
?php echo
base_url ?
assetsstylesignin.css rel
= stylesheet
head body
div class
= container
form class
= form-signin
action =
?php echo
base_url ?
index.phploginvalidasi_user method
= POST
h2 class
= form-signin-heading
Silahkan masuk h2
label for
= text
class =
sr-only Alamat Email
label input
name =
username type
= text
id =
username class
= form-
control placeholder
= Username
requiredautofocus label
for =
inputPassword class
= sr-only
Password label
input name
= password
type =
password id
= inputPassword
class =
form- control
placeholder =
Password required
div class
= checkbox
label input
type =
checkbox value
= remember-me
Ingat saya label
div button
class =
btn btn-lg
btn-primary btn-block
type =
submit Sign
in button
form div
-- container --
body html
5. Buat class Akun_model, tuliskan code dibawah ini, simpan dengan nama Akun_model.php
C:xampphtdocsmyproyekapplication
151
1 2
3 4
5 6
7 8
9 10
?php if
defined BASEPATH
exit No direct script access allowed
; class
Akun_model extends
CI_Model {
publicfunction verifikasi_data
username ,
password {
this -
db -
where username
, username
; this
- db
- where
password ,
password ;
query =
this -
db -
get akun
; return
query ;
} }
6. Buka controller admin, tambahkan kode fungsi dibawah ini
C:xampphtdocsmyproyekapplication
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
publicfunction__construct {
parent ::
__construct ;
this -
is_logged_in ;
} publicfunction
is_logged_in {
logged_in =
this -
session -
userdata logged_in
; if
isset logged_in
|| logged_in
= TRUE
{ echo
Kamu tidak memiliki izin unntuk mengakses halaman ini, Silahkan login terlebih dahulu
; die
; }
} publicfunction
logout {
session =
this -
session -
userdata logged_in
; if
session =
TRUE {
header location:
. base_url
. index.phplogin
; }
else {
this -
session -
sess_destroy ;
header location:
. base_url
. index.phplogin
; }
}
7. Jalankan program pada web browser tampilkan dan analisis hasilnya.
E. Studi Kasus
Lakukan pengujian system autentikasi yang telah anda bangun, coba kunjungi URL:
http:localhostmyproyekindex.phpadmin tanpa login terlebih dahulu,
apabila halaman admin masih bisa diakses tanpa login berarti sisem masih gagal, dan apabila halaman admin sudah tidak bisa diakses, berarti system autentikasi
telah berhasil dibangun.