CREATE TABLE IF NOT EXISTS `admins` (
`id_user` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) COLLATE latin1_general_ci NOT NULL,
`password` varchar(50) COLLATE latin1_general_ci NOT NULL,
`nama_lengkap` varchar(100) COLLATE latin1_general_ci NOT NULL,
`email` varchar(100) COLLATE latin1_general_ci NOT NULL,
`no_telp` varchar(20) COLLATE latin1_general_ci NOT NULL,
`level` varchar(20) COLLATE latin1_general_ci NOT NULL DEFAULT 'user',
`blokir` enum('Y','N') COLLATE latin1_general_ci NOT NULL DEFAULT 'N',
PRIMARY KEY (`id_user`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ;
file cek_login.php
<?php
include "koneksi.php";
function antiinjection($data){
$filter_sql = mysql_real_escape_string(stripslashes(strip_tags(htmlspecialchars($data,ENT_QUOTES))));
return $filter_sql;
}
$username = antiinjection($_POST['username']);
$pass = antiinjection(md5($_POST['password']));
$login=mysql_query("SELECT * FROM admins WHERE username='$username' AND password='$pass' AND blokir='N'");
$ketemu=mysql_num_rows($login);
$r=mysql_fetch_array($login);
// Apabila username dan password ditemukan
if ($ketemu > 0){
session_start();
session_register("namauser");
session_register("namalengkap");
session_register("passuser");
session_register("leveluser");
$_SESSION[namauser] = $r[username];
$_SESSION[namalengkap] = $r[nama_lengkap];
$_SESSION[passuser] = $r[password];
$_SESSION[leveluser] = $r[level];
header('location:media.php');
}
else{
echo "<link href=../config/adminstyle.css rel=stylesheet type=text/css>";
echo "<center>LOGIN GAGAL! <br>
Username atau Password Anda tidak benar.<br>
Atau account Anda sedang diblokir.<br>";
echo "<a href=index.php><b>ULANGI LAGI</b></a></center>";
}
?>
form login.php
<form name="login" action="cek_login.php" method="POST" onSubmit="return validasi(this)">
<table>
<tr><td>Username</td><td> : <input type="text" name="username"></td></tr>
<tr><td>Password</td><td> : <input type="password" name="password"></td></tr>
<tr><td colspan="2"><input type="submit" value="Login"></td></tr>
</table>
</form>
0 Comments