login multi user langsung ke folder yang dituju

chanif fadhila · Jun 9, 2012
saya mau bertanya gmn caranya membedakan login user/admin langsung ke beda folder yang di tuju tanpa harus masuk menu.php sbg pembeda masuk sbg user/admin. jadi intinya index.php --> periksa.php --> connect.php --> masuk folder user / admin tanpa include menu.php dari periksa.php
ini kodenya...

index.php
<html>
<head>
<title>Inventory Order</title>
<script language="javascript">
function validasi(form){
  if (form.username.value == ""){
    alert("Anda belum mengisikan Username.");
    form.username.focus();
    return (false);
  }
     
  if (form.password.value == ""){
    alert("Anda belum mengisikan Password.");
    form.password.focus();
    return (false);
  }
  return (true);
}
</script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body OnLoad="document.login.username.focus();">
<div id="header">
  <div id="content">
		<h2>Welcome Login Inventory Order PT. POS INDONESIA</h2>
    <img src="images/login-welcome.jpg" width="97" height="105" hspace="10" align="left">

<form name="login" action="periksa.php" method="POST" onSubmit="return validasi(this)">
<table>
<tr><td>Username</td><td> : <input type="text" name="username"></td></tr>
<tr><td>Password</td><td> : <input type="password" name="password"></td></tr>
<tr><td align="center" colspan="2"><input type="submit" value="Login"><input type="reset" value="Reset"></td></tr>
</table>
</form>

<p>&nbsp;</p>
  </div>
	<div id="footer">
			Copyright Muschlefreak | @2012 by Muschlefreak Design. All rights reserved.
	</div>
</div>
</body>
</html>


periksa.php
<?php
session_start(); //memulai session
include "connect.php";//mengambil isian username dan password dari form
$username = $_POST['username'];
$password = $_POST['password'];
//query untuk mengambil data user dari database sesuai dengan username inputan form
$q = "SELECT * FROM tb_user WHERE username = '$username' ";
$result = mysql_query($q);
$data = mysql_fetch_array($result);
//cek kesesuaian password masukan dengan database
if ($password == $data['password']) {
//menyimpan tipe user dan username dalam session
$_SESSION['tipe'] = $data['tipe'];
$_SESSION['username'] = $data['username'];
include "menu.php";
}
//jika password tidak sesuai
else {
$warning = "<h1>Username / Password Salah</h1>";
echo $warning;
}
?>
<body style="background-color:#FF4500">


connect.php
<?php
$host = "localhost";
$user = "root"; //sesuaikan dengan user mysql anda
$pass = ""; //sesuaikan dengan password mysql anda
$dbName = "inventory_order";
mysql_connect($host, $user, $pass);
mysql_select_db($dbName)
or die ("Koneksi Gagal : ".mysql_error());
?>

menu.php
<html>
<head>
</head>
<body style="background-color:#FF4500">
<body>
<br><br>
<?php
session_start();
include "connect.php";
echo "<center>";
echo "<h1> Menu </h1>";
if ($_SESSION['tipe'] == "admin") {
echo " <h1>Selamat Datang di Web PT. POS Indonesia</h1>";
echo "<br>";
echo " <h2>Anda Login sebagai Admin</h2>";
echo "<br>";
echo "<td height='18' valign='top'></td>";
echo "<form id='enter' method='post' name='ENTER' action='admin/index.php'>";
echo "<td valign='middle'>";
echo "<input name='login' type='submit' id='login' value='ADMIN'>";

}
else if ($_SESSION['tipe'] == "user") {
echo " <h1>Selamat Datang di Web PT. POS Indonesia</h1>";
echo "<br>";
echo " <h2>Anda Login sebagai User</h2>";
echo "<br>";
echo "<td height='18' valign='top'></td>";
echo "<form id='enter' method='post' name='ENTER' action='user/index.php'>";
echo "<td valign='middle'>";
echo "<input name='login' type='submit' id='login' value='USER'>";

}
?> 
</body>
</html>
Silahkan login untuk menjawab!