Cara membuat form login dengan Php [TUTORIAL LENGKAP]

Posted by


Assalammualaikum om tante nyak babe :D
ketemu lagi nih ama aa teguh :D karna udah lama bgt ga posting,skarang mau posing lagi ni tentang cara bikin form login sampe logout dijamin lengkap dah tutornya :D

oke skarang qta bikin dulu databasenya,saya bkin database dgn nama login dan nama tabelnya data_user…







selanjutnya isi skalian yaak data2nya (username,nama,password).



gimana udah belom bikin databasenya??
kalo udah,sekarang bikin file2 phpnya.

buat file baru (login.php)
<body>
<form id="form1" name="form1" method="post" action="cek.php">
  <table width="218" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td colspan="2"><div align="center">LOGIN AREA </div></td>
    </tr>
    <tr>
      <td width="74">Username</td>
      <td width="144"><input name="username" type="text" id="username" /></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input name="password" type="password" id="password" /></td>
    </tr>
    <tr>
      <td colspan="2"><input name="Login" type="submit" id="Login" value="Login" /> <input name="Batal" type="reset" id="Batal" value="Batal" /></td>
    </tr>
  </table>
</form>
</body>

buat file baru (koneksi.php)
<?php
mysql_connect("localhost","root","password");
mysql_select_db("login");
?>

buat file baru (cek.php)
<?php
session_start();
include "koneksi.php";
$username=$_POST['username'];
$password=$_POST['password'];
if($username==""||$password==""){
echo"<script>alert('Username dan password belum terisi')</script>";
echo"<script>location='login.php'</script>";
}
$cek="SELECT * from data_user where username='$username' and password='$password'";
$hasil=mysql_query($cek);
$data=mysql_fetch_array($hasil);
if($data['username']<>$username and $data['password']<>$password){
echo"<script>alert('Anda Gagal Login! periksa Kembali Username dan Password')</script>";
echo"<script>location='login.php'</script>";
}
else
{
$_SESSION['username']=$data['username'];
$_SESSION['password']=$data['password'];
echo"<script>alert('Selamat Datang Om/Tante ".$_SESSION['username']." diruang Login')</script>";
echo"<script>location='home.php'</script>";
}
?>

buat file baru (home.php)
<body>
<h2>Selamat Datang Di Halaman User</h2> || <a href="logout.php">Keluar</a>
</body>

<a href="#" title="TEGUH TRIYONO">Copyright@2014</a>

buat file baru (logout.php)
<?php
session_start();
echo"<script>alert('Anda Telah Logout')</script>";
echo"<script>location='login.php'</script>";
?>

Jika sudah selesai buka web browser anda. ketikan.

localhost/nama folder/login.php

monggo dicoba yaa... :) #usahain diketik aja jangan dicopas biar paham apa yang sedang anda kerjakan hhe


Blog, Updated at: Mei 22, 2014

0 komentar:

Posting Komentar

Informasi

Website sedang maintenance !

Gabung Obrolan