Kamis, 03 Februari 2011

Membuat form login, register, & logout tanpa md5 dengan PHP MYSQL

Step1:
Buat databasenya terlebih dahulu (buat di phpmyadmin)
nama database: dblogin
buat 1 table dengan nama : tlogin
buat 2 field di table tlogin:id varchar(20) primary key, password varchar(20);
Step 2:
buat halaman index.html
<html>
<form name="form1" method="post" action="login.php">
<table width="273" border="0">
<tr>
<td width="92">ID</td>
<td width="171"><input type="text" name="txtid" id="txtid"></td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="text" name="txtpassword" id="txtpassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="login" id="login" value="login">
<a href="/regis.php">register</a></td>
</tr>
</table>
</form>
</html>
Step 3 :
buat halaman regis.php
<html>
<body>
<form id="form1" name="form1" method="post" action="regisq.php">
<table width="366" border="0">
<tr>
<td colspan="2"><div align="center">REGISTER</div></td>
</tr>
<tr>
<td width="179">ID</td>
<td width="177"><input type="text" name="txtid" id="txtid" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="text" name="txtpassword" id="txtpassword" /></td>
</tr>
<tr>
<td>CONFIRM PASSWORD</td>
<td><input type="text" name="txtconfirm" id="txtconfirm" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
Step 4 :
buat halaman regisq.php
<?
mysql_connect('willy','root','wilian');
mysql_select_db("dblogin");
$id=trim($_POST[txtid]);
$password=trim($_POST[txtpassword]);
$confirm=trim($_POST[txtconfirm]);
if(empty($id) || empty($password) || empty($confirm) )  { echo "<script>alert('isi semua'); window.location.href='regis.php'</script>"; }
if($password!=$confirm) {
echo "<script>alert('confirm tidak sama'); window.location.href='regis.php'</script>"; return false; break;
}
mysql_query("insert into tlogin values('$id','$password')");
echo "<script>alert('berhasil register'); window.location.href='index.html'</script>";
?>
Step 5 :
buat halaman login.php
<?  session_start();
mysql_connect('willy','root','wilian');
mysql_select_db("dblogin");
$id=trim($_POST[txtid]);
$password=trim($_POST[txtpassword]);
$query=mysql_num_rows(mysql_query("select * from tlogin where id='$id' and password='$password'"));
if ($query>0) { $_SESSION['login']='login';  echo "<script>alert('sukses login'); window.location.href='menu.php'</script>";  }
else { echo "<script>alert('username belum terdaftar'); window.location.href='index.html'</script>";  }
?>
Step 6 :
buat halaman menu.php
<? include 'session.php'; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><a href="/logout.php">logout</a></p>
<p>menu login
</p>
</body>
</html>
Step 7 :
buat halaman logout.php
<?
session_start();
UNSET($_SESSION['login']);
header("location:index.html");
session_destroy();
?>
Step 8 :
buat halaman session.php
<?  session_start();
if(!isset($_SESSION['login'])) {
session_destroy();
header("location:index.html");
}
?>

1 komentar:

bountooth mengatakan...

thanx bro :)

Copyright FARID SUTIMAN LAMAKARATE