hi to everyone,
I am working on this project where I have to develop a system where the user is directed to specific areas of the website according to his role (admin – editor – publisher) and to the usergroup he belongs to (student – teacher – staff).
I have a table in the database where i store the username, password, user group and user role. When the user logs in I have the following logincheck.php where I validate the login form and register the 4 variables in a session.
[CODE]
<?php
include(“include/config.inc.php”);
$con=mysql_connect($dbServer,$dbUser,$dbPass)
or exit (“error connecting db”);
if(isset($_POST[“login”])){
//elements sent from registration form
$username=$_POST[“username”];
$password=md5($_POST[“password”]);
//check if username and password exist
$sql1=”SELECT * FROM users WHERE username=’$username’ AND password=’$password’ AND active=’1′”;
$res1=mysql_db_query($dbDatabase,$sql1);
$rows1=mysql_num_rows($res1);
$type=$res1[“user_type”];
$group=$res1[“user_group”];
if($rows1==1){
session_register(“username”);
session_register(“password”);
session_register(“type”);
session_register(“group”);
header(“location:login_success.php”);
}
else {
header(“location:login.php?status=1”);
}
}
?>
the login_success.php is the following
[CODE]
<!–Check if session is not registered , redirect back to main page.
Put this code in first line of web page.–>
<?php
session_start();
if(!session_is_registered(“username”)){
header(“location:login.php”);
}
else
header(“location:index.php”);
?>
when I am directed to index.php after a successful login how do I retrieve the variables I registered in the session?
What I want to do do is to check if a user is an teacher / student /staff and if he is an editor/author/admin to load different menus and links and content. So I guess there has to be some way to retrieve the user role and user group since I have stored it in the session. In he index page I do the following session_is_registered(“username”) but tha does not give u the value of username…
Any help is welcome.
Thnx in advance!
Yona