Paling pertama sekali ialah membuat database dan tabelnya untuk username dan passwordnya
silahkan lihat gambar berikut:
lakukan lah dengan benar jangan sampe suntuk ea... :)
Lalu kita harus membuat file index.php sebagai form loginnya.
ini copy saja kodingnya... !!!! :)
Index.php
<?php
include('login.php'); // Memasuk-kan skrip Login
if(isset($_SESSION['login_user'])){
header("location: profile.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<!--
Skrip CSS -->
<link
href="style.css" rel="stylesheet"
type="text/css">
</head>
<body > <p align="center">
<div
class="container">
<div
class="main">
<form action=""
method="post">
<h2>Login</h2><hr/>
<label>Username
:</label>
<input
id="name" name="username" placeholder="user"
type="text">
<label>Password
:</label>
<input
id="password" name="password"
placeholder="password" type="password">
<input
type="submit" name="submit" id="submit"
value="Login">
</form>
</div>
</div>
</P>
</body>
</html>lalu simpan dengan nama index.php dan ini di simpan pada folder xampp -> htdocs
Langkah kedua yaitu mengoding login.php ga usah cemas ini kodingnya....!!!
Login.php
<?php
session_start(); // Memulai Session
$error=''; // Variabel untuk menyimpan pesan error
if (isset($_POST['submit'])) {
if (empty($_POST['username']) ||
empty($_POST['password'])) {
$error = "Username or Password is
invalid";
}
else
{
// Variabel username dan password
$username=$_POST['username'];
$password=$_POST['password'];
// Membangun koneksi ke database
$connection = mysql_connect("localhost",
"root", "");
// Mencegah MySQL injection
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Seleksi Database
$db = mysql_select_db("mee", $connection);
// SQL query untuk memeriksa apakah karyawan
terdapat di database?
$query = mysql_query("select * from server
where Password='$password' AND Nama='$username'")or die (mysql_error());
$rows = mysql_num_rows($query);
if ($rows == 1)
{
$_SESSION['login_user']=$username;
// Membuat Sesi/session
header("location:
profile.php"); // Mengarahkan ke halaman profil
echo
'<script language="javascript">alert("Anda berhasil Login
Admin!");document.location="s/index.php";</script>';
}
else
{
$error = "Username atau Password belum
terdaftar";
}
mysql_close($connection); // Menutup koneksi
}
}
?>lalu simpan dengan login.php
setelah itu kita buat lagi koding profil.php dannnn... ini kodingnya....
Profile.php
<?php
include('session.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Success...!!!</title>
<link href="style.css"
rel="stylesheet" type="text/css">
</head>
<body>
<div id="profile">
<b id="welcome"><i><?php
echo $login_session; ?></i></b>
<table border=1 width="1000" align="center">
<tr>
<td
colspan="3"><img src="Unti.jpg"
width="1050" height="100"
align="center"></td>
</tr>
<tr>
<td
colspan="3"><img src="Menu.jpg"
width="1050" height="30"></td>
</tr>
<tr>
<td
height="500" width="100"><img
src="Menu_kiri.jpg" width="100" height="20"></td>
<td><img
src="Content.jpg" width="838"
height="500"></td>
<td height="500"
width="100"><img src="Menu_kanan.jpg"
width="100" height="20"></td>
</tr>
<tr>
<td
colspan ="3"><marquee><img src="Footer.jpg"
width="1050" height="20"></marquee></td>
</tr>
</table>
<b id="logout"
align="center"><a href="logout.php" >Log
Out</a></b>
</div>
</body>
</html>lalu simpan sesuai dengan namanya yaitu profil.php
setelah semuanya jadi maka kita perlu yang namanya style atau gaya yang menarik untuk form login kita, agar yang menggunakannya tidak merasa muak dengan tampilan html kita...
baik lah ga perlu banyak bacot langsing ajha.... ini dia.....
Style.css
.container {
width:
50%;
margin: 0
auto; }
h2{
background:
linear-gradient(#d7d890 5%, #07f8f5 100%);
padding: 30px
35px;
margin: -10px
-50px;
text-align:center;
color:
#525b52;
text-shadow:
0 1px 0 blue;}
span{
display:
block;
margin-bottom: 20px;
color: red;}
.success{
display:
block;
margin-top:
20px;
margin-bottom: 0;
font-size:
14px;}
b{
color:green;}
hr{
margin: 10px
-50px;
border: 0;
border-top:
1px solid #ccc;
margin-bottom: 25px;}
div.main{
width: 306px;
padding: 10px
50px 30px;
border: 2px
solid gray;
font-family:
raleway;
float:left;
margin-top:15px;}
input[type=text]{
width: 96%;
height: 25px;
padding: 5px;
margin-bottom: 25px;
margin-top:
5px;
border: 2px
solid #ccc;
color:
#53bd84;
font-size:
16px;}
input[type=password]{
width: 96%;
height: 25px;
padding: 5px;
margin-bottom: 25px;
margin-top:
5px;
border: 2px
solid #ccc;
color:
#53bd84;
font-size:
16px;}
label{
color:
#f7fa05;
text-shadow:
0 1px 0 RED;
font-size:
18px;
font-weight:
none;}
input[type=submit]{
font-size:
16px;
background:
linear-gradient(#07f8f5 5%, #d7d890 100%);
color:
#4E4D4B;
font-weight:
bold;
cursor:
pointer;
width: 100%;
padding: 10px
0;
outline:none;
text-shadow:
0 1px 0 RED;}
#profile {
padding:50px;
border:1px solid grey;
font-size:20px;
background-color:#07f807;}
#logout {
float:center;
padding:2px;
border:1px gray;}
a {
text-decoration:none;
color:#6495ed}
i {color:#6495ed}simpan dengan nama style.css difolder yang sama jua ea... :)
Oooohhh iya satu lagi ada yang kurang kita harus keluar juga kan biar orang yang menggunakan komputer yng sama tidak merusak data kita,,,,, ini dia
logout.php
<?php
session_start();
if(session_destroy()) // Menghapus Sessions
{
header("Location: index.php"); // Langsung
mengarah ke Home index.php
}
?>
simpan dengan nama logout.php
setelah itu jalankan deh....
thanks itu saja yng mungkin bisa saya share pada kesempatan kali ini... jika ada yang kurang berkenan saya mohonn maaf yng sebesar besarnya....
------------------------------------GOOD LUCK---------------------------------------
------------------------------------GOOD LUCK---------------------------------------



0 komentar:
Posting Komentar