i need some help in putting user level access in my codes.
what i have in my database are:
database name = test
table name = members
and inside members i have: username, password and access
in the access i have 1,2,3,4. the 1 is the admin, 2 is the power user, 3 is the user and 4 is only a viewer.
im new in programming and i am having a hard time in understanding the use of session. thats why i really need your help.
i dont know what to put on my codes. example on my account.php i want the power user can only access it, the billing.php only the user can access it. and the admin can access them all.
here is my main_login.php
[php]
|
then here is my checklogin.php
[php]
<?php session_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password="LNKmis000"; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); if($count==1){ $_SESSION['isLogged'] = true; session_register("myusername"); session_register("mypassword"); header("location:index.php"); } else { echo "Wrong Username or Password"; } ?><p><a href="main_login.php">back</a></p>
[/php]
and next is the index.php
[php]<?php
session_start();
if(!isset($_SESSION[‘isLogged’])){
header(“location: main_login.php”);
}
?>
L&K Billing SystemWelcome to L&K Billing System.
To get started please use the navigation button on the right side.
Below navigation are the choices available:
<?php include('includes/sidebar.php'); ?>
<?php include('includes/footer.php'); ?>
</div> <!-- End #wrapper -->
</body>
[/php]