Maksudnya bagaimana ya mas..?? Mohon dijelaskan..
Saya menggunakan Script seperti ini untuk halaman index :
<?php
session_start();
include("config.php");
if(!isset($_SESSION['userid'])){
header("location:login.php");
}
if($_SESSION['level'] == "user"){
header("location:user.php");
}
if($_SESSION['level'] == "admin"){
header("location:admin.php");
}
?>
Jika belum melakukan login, maka akan di pindah ke halaman login.php
<html>
<head>
<title>LOGIN</title>
</head>
<body style="background: url(images/bglogin.png) #CC0 center 150px no-repeat;">
<center>
<h1 style="color:#FFF; margin-top:200px; padding:10px; width:300px; margin-bottom:0px;">LOGIN</h1>
<?php
//kode php ini kita gunakan untuk menampilkan pesan eror
if (!empty($_GET['error'])) {
if ($_GET['error'] == 1) {
echo '<h3>Username dan Password belum diisi!</h3>';
} else if ($_GET['error'] == 2) {
echo '<h3>Username belum diisi!</h3>';
} else if ($_GET['error'] == 3) {
echo '<h3>Password belum diisi!</h3>';
} else if ($_GET['error'] == 4) {
echo '<h3>Username dan Password tidak terdaftar!</h3>';
}
}
?>
<form action="log.php?op=in" method="post">
<table border="0" cellpadding="5" cellspacing="0" style="color:#fff; width:320px; text-align:center;">
<tr>
<td>Username</td>
<td>:</td>
<td><input type="text" name="userid" /></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="psw" /></td>
</tr>
<tr align="center">
<td colspan="3"><input type="submit" name="login" value="Login" /></td>
</tr>
</table>
</form>
</center>
</body>
</html>
Dari halaman login tadi akan dieksekusi di halaman log.php
<?php
session_start();
mysql_connect("127.0.0.1","root","") or die("Nggak bisa koneksi");
mysql_select_db("elearning");
$userid = $_POST['userid'];
$psw = $_POST['psw'];
$op = $_GET['op'];
if($op=="in"){
$cek = mysql_query("SELECT * FROM tabeluser WHERE userid='$userid' AND password='$psw'");
if(mysql_num_rows($cek)==1){
$c = mysql_fetch_array($cek);
$_SESSION['userid'] = $c['userid'];
$_SESSION['level'] = $c['level'];
if($c['level']=="admin"){
header("location:admin.php");
}else if($c['level']=="user"){
header("location:user.php");
}
}else{
header("location:login.php");
}
}else if($op=="out"){
unset($_SESSION['userid']);
unset($_SESSION['level']);
header("location:index.php");
}
?>
Jika user benar memasukkan login n password maka akan tampil halaman user.php atau admin.php sesuai level id yang terdaftar di database..
Pada halaman user saya menggunakan script ini..
<?php
session_start();
include('config.php');
//cek apakah user sudah login
if(!isset($_SESSION['userid'])){
die("Anda belum login <a href=\"javascript:history.back()\">kembali</a>");//jika belum login jangan lanjut..
}
//cek level user
if($_SESSION['level']!="user"){
die("Anda bukan user");//jika bukan user jangan lanjut
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>iKnowSmart e-Learning</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<style type="text/css">
img, div, input { behavior: url("iepngfix.htc") }
</style>
<script type="text/javascript">
</script>
</head>
<body>
<div id="wrapper">
<div id="container">
<div id="ltcontent">
<div id="hdlogo" align="center"><img src="images/topbanner.jpg" alt=""/></div>
<div id="about"><div class="inner_copy"><div class="inner_copy">All <a href="http://www.magentothemesworld.com" title="Best Magento Templates">premium Magento themes</a> at magentothemesworld.com!</div></div>
<div class="lthead" align="center"><span class="tphead">wise words of this week's
</span></div>
<div class="ltdetail">
A fool thinks himself to be wise but a wise man knows himself to be a fool.
</div>
<div class="link">Get in touch with us</div>
</div>
<div class="ltgap"></div>
<div id="mostpop">
<div class="lthead"><span>most popular posts</span></div>
<div class="ltposts">
<ul>
<li><a href="#">Vero</a></li>
<li><a href="#">Harum</a></li>
<li><a href="#">Expedia</a></li>
<li><a href="#">Omnis</a></li>
<li><a href="#">Voluptatum</a></li>
</ul>
</div>
<div class="rtposts">
<ul>
<li><a href="#">Nauts</a></li>
<li><a href="#">Video 3</a></li>
<li><a href="#">Adipisci</a></li>
<li><a href="#">Numquam</a></li>
<li><a href="#">Vel Illium</a></li>
</ul>
</div>
<div class="clear"></div>
</div>
<div class="ltgap"></div>
<div id="search">
<div class="input">
<input type="text" name="search" class="textbox"/>
<input type="submit" value="SEARCH" class="searchBut" />
</div>
</div>
<div class="ltgap"></div>
<div id="feeds">
<div class="lthead" align="center"><span class="tphead">subscribe to feeds</span></div>
<div class="ltdetail">
<ul>
<li><a href="#">Subscribe to blog updates</a></li>
<li><a href="#">Subscribe to screen-cast updates</a></li>
</ul>
</div>
</div>
<div class="ltgap"></div>
<div id="social">
<div class="lthead"><span>my social networks</span></div>
<div>
<a href="#"><img src="images/link1.png" alt="" /></a>
<a href="#"><img src="images/link2.png" alt="" /></a>
<a href="#"><img src="images/link3.png" alt="" /></a>
<a href="#"><img src="images/link4.png" alt="" /></a>
<a href="#"><img src="images/link5.png" alt="" /></a>
</div>
</div>
</div>
<div id="rtcontent">
<div class="publish">
<div style="float:left; "><?php $aksi = " select * from tabeluser where userid = '".$_SESSION['userid']."'";
$hasil = mysql_query($aksi);
$muncul = mysql_fetch_array ($hasil);
echo "Selamat Datang $muncul[userid], $muncul[kelas]";
?>
Sekolah APD - Apanya Dong</div>
<div style="float:right; width:100px;"><a href="logout.php">Logout</a></div>
</div>
<div class="head">e - Learning</div>
<div class="tagln">
It is a <span class="italics">long</span> established fact <span class="italics">that</span> a reader<br />will love your work, as long as you put all you have into the project
</div>
<div id="menulinks">
<ul>
<li><a href="#">Announce</a></li>
<li><a href="#">Library</a></li>
<li><a href="#">Quiz</a></li>
<li><a href="#" class="scrcast">My Files</a></li>
</ul>
</div>
<div class="clear"></div>
<?php //buat query terlebih dahulu
include('config.php');
$query=mysql_query("select * from feeds order by id_feed desc ");
//cek apakah kita sudah memposting artikel atau belum
if (mysql_num_rows($query) == 0) {
//tampilkan pesan kalau artikel belum ada
echo 'maaf, belum ada berita terkini, silahkan chek beberapa saat lagi';
} else {
//buat pengulangan untuk menampilkan data artikel dengan menggunakan while dan definisikan kedalam variabel data
while ($data = mysql_fetch_array($query)) {
//kita akan menampilkan judul artikel
echo '<div class="document"><div> </div><div class="dochead"><span class="dhead">'.$data['judul'].'</span></div>';
echo '<div style="color:#000;font:12px Tahoma, Geneva, sans-serif; margin-left:15px; margin-top:5px;"> Data Khusus Kelas ' .$data['kelas']. '</div>';
//menampilkan tanggal posting
echo '<div><span class="post"> Waktu posting ' .$data['waktu']. '</span></div>';
//menampilkan isi artikel yang sudah kita buat
echo '<div class="dcontent">'.$data['isi'].'</div></div><div class="rtboxbg"> </div><div class="gap"></div>';
//tutup koneksi database
}} mysql_close(); ?>
</div>
<div class="rtboxbg"> </div>
<div class="gap"></div>
</div>
<div class="clear"></div><br />
<div id="features">
<div id="tranbox">
<div class="tranhead">1914 translation</div>
<span class="trapost">posted by admin | september 3, 2010</span>
<div class="tracontent">
On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain.
</div>
</div>
<div id="video"><img src="images/video.jpg" alt=""/></div>
<div class="clear"></div>
</div>
<div id="footer">
<div class="flinks">
<span><a href="#">HOME</a></span><span class="separator"> | </span>
<span><a href="#">ABOUT</a></span><span class="separator"> | </span>
<span><a href="#">REEL</a></span><span class="separator"> | </span>
<span><a href="#">SCREENCASTS</a></span><span class="separator"> | </span>
<span><a href="#">CONTACT</a></span>
</div>
<br/><br/><p>More <a href="../index.php">iKnowSmart</a> </p>
</div>
</div>
</div>
</body>
</html>