Translate

Rabu, 15 Februari 2012

Cara Membuat Login Member

 
1.CREATE TABLE user (
2.username varchar(20),
3.password varchar(20),
4.level varchar(20),
5.PRIMARY KEY(username)
6.);
1.INSERT INTO `user` VALUES ('a', 'pass1', 'admin');
2.INSERT INTO `user` VALUES ('b', 'pass2', 'admin');
3.INSERT INTO `user` VALUES ('c', 'pass3', 'user');
4.INSERT INTO `user` VALUES ('d', 'pass4', 'user');
5.INSERT INTO `user` VALUES ('e', 'pass5', 'user');


Tempelkan Tag HTML di bawah ini di blog.
<form method="post" action="loginsubmit.php">
<table border="0">
<tr>
<td>Masukkan Username </td>
<td><input name="username" type="text"></td>
</tr>
<tr>
<td>Masukkan Password </td>
<td><input name="pass" type="password"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
mysql_connect('dbhost', 'dbuser', 'dbpass');
mysql_select_db('dbname');
$username = $_POST['username'];
$password = $_POST['pass'];
$query = "SELECT * FROM user WHERE username = '$username'";
$hasil = mysql_query($query);
$data = mysql_fetch_array($hasil);
if ($password == $data['password'])
{
echo "<h1>Login Sukses</h1>";
$_SESSION['level'] = $data['level'];
$_SESSION['username'] = $data['username'];
include "menu.php";
}
else echo "<h1>Login gagal</h1>";
?>
<?php
session_start();
if ($_SESSION['level'] == "admin")
{
echo "<a href='hal1.php'>Halaman 1</a> ";
echo "<a href='hal2.php'>Halaman 2</a> ";
echo "<a href='hal3.php'>Halaman 3</a> ";
echo "<a href='logout.php'>Logout</a> ";
}
else if ($_SESSION['level'] == "user")
{
echo "<a href='hal3.php'>Halaman 3</a>";
echo "<a href='logout.php'>Logout</a> ";
}
?>
if (isset($_SESSION['level']) && isset($_SESSION['username']))
{
include "menu.php";
if ($_SESSION['level'] == "admin")
{
echo "<h1>Halaman 1</h1>";
echo "<p>Selamat datang di halaman satu wahai user : ".$_SESSION['username']."</p>";
echo "<p>Ini adalah konten halaman 1</p>";
}
else
{
echo "<h1>Maaf.. Anda bukan user berlevel Administrator</h1>";
}
}
else
{
echo "<h1>Nah.. Anda pasti mencoba akses halaman ini tanpa login ya?</h1>";
}
?>
session_start();
if (isset($_SESSION['level']) && isset($_SESSION['username']))
{
include "menu.php";
if (($_SESSION['level'] == "admin") || ($_SESSION['level'] == "user"))
{
echo "<h1>Halaman 3</h1>";
echo "<p>Selamat datang di halaman tiga wahai user : $_SESSION['username']."</p>";
echo "<p>Ini adalah konten halaman 3</p>";
}
}
else
{
echo "<h1>Nah.. Anda pasti mencoba akses halaman ini tanpa login ya?</h1>";
}
?>
session_start();
session_destroy();
echo "<h1>Anda sudah logout</h1>";
echo "<p><a href='formlogin.htm'>Login Kembali</a></p>";
?>























 

Welcome In Anca Community Blogg's

Memasang Audio Streaming

Ahlan Wasahlan atas kesedian antum berkunjung di halaman blog ini. Login Form ini hanyalah variasi blog, karena blogspot merupakan blog terbuka, tetapi kami tidak menjadikan kecewa antum, walau tidak bisa login, sebagai gantinya kami berikan Tutorial Cara memasang Audio Streaming

Pasangkan

Untuk memasang audio : Klik Disini

Member Login

Lost your password?

Not a member yet? Sign Up!