2. Buat Tabel "user" dengan Struktur Database Seperti :
Atau
CREATE TABLE `user` ( `id` int(11) NOT NULL auto_increment, `username` varchar(255) collate latin1_general_ci NOT NULL, `password` varchar(255) collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ; INSERT INTO `user` (`id`, `username`, `password`) VALUES (1, 'admin', '21232f297a57a5a743894a0e4a801fc3 ');21232f297a57a5a743894a0e4a801fc3 Adalah MD5 dari admin
Username : admin
Password : admin
3. Buat file "koneksi.php" dengan code sebagai berikut :
<?php // FIle koneksi.php $mysql_server = "localhost";// mysql server $mysql_username = "root";// mysql sername $mysql_password = "";// mysql password $mysql_database = "login";// nama Database mysql_connect("$mysql_server","$mysql_username","$mysql_password") or die ("Tidak Konek Ke Server"); mysql_select_db("$mysql_database") or die ("Database Tidak Di Temukan"); ?>
4. Buat file "index.php" dengan code sebagai berikut :
<?php // File index.php session_start(); ?> <html> <head> <title>Halaman Login By Poticous</title> </head> <body> <? include "koneksi.php"; if(!isset($_SESSION['user'])){ if($_SESSION['gagal']){ echo($_SESSION['gagal'] . '<br/>'); unset($_SESSION['gagal']); } ?> <form method="post" action="login.php"> Username : <br/><input type="text" name="username"/><br/> Password : <br/><input type="password" name="password"/><br/><br/> <input type="submit" value="Login"/> </form> <? }else{ echo "<a href='logout.php' >Logout</a>"; } ?> </body> </html>
5. Buat File "login.php" dengan code sebagai berikut :
<? session_start(); include "koneksi.php"; $username = addslashes(htmlspecialchars($_POST['username'])); $password = addslashes(htmlspecialchars(md5($_POST['password']))); $result = mysql_query("select * from user where username='{$username}' and password='{$password}'"); if($row = mysql_fetch_array($result)){ $_SESSION['user']['id'] = $row['id']; $_SESSION['user']['username'] = $row['username']; $_SESSION['user']['password'] = $row['password']; }else{ $_SESSION['gagal'] = '<h4>Username Dan Password Anda Salah.</h4>'; } mysql_free_result($result); header("Location:index.php"); ?>
6. Buat File "logout.php" dengan code sebagai berikut :
<? session_start(); unset($_SESSION['user']); header("Location:index.php"); ?>
7. Halaman Login anda sudah jadi..
Sumber : Poticous
ane coba om poti :mohon
BalasHapus