hi all. im looking for a tutorial or a guide to code php script for login access for mutiple use types for eg. guest member staff admin

do any any of you have any tutorial or guide me through it. i know basic login creation and mysql data handling. another thing i am interested is how to show a certain page to certain user. for example when a person visits the site he is able to see the guest page and when if he logs in the system determines if its member staff or admin and displays the relative page.

i am trying to do this by having another coloumn in my database as access level.so what i do is basically check the access level and redirect to another page and when the user logs out kill session and redirect to index or the guest page.

but is this the correct way?

Yes it is ;)

You basically set session variable in which you declare various levels of authorization:

$_SESSION['LOGINDATA']['AUTH'] = 2; // 0 = guest, 1 = member, 2 = admin

And then you check on any page what to show:

switch ($_SESSION['LOGINDATA']['AUTH']) {

 case 0 :
  echo 'You are a guest';

 case 1 :
  echo 'You are a member';

 case 2 :
  echo 'You are a admin';


And if you need to check on a random page, to show a login message or not:

if ($_SESSION['LOGINDATA']['AUTH'] > 0) {
  echo 'You are not logged in, <a href="login.php">log in</a>?';

Also you need to add this to the top of you page, to make sure if the login session data is not set, you set it to default:

if (!isset($_SESSION['LOGINDATA']['AUTH'])) {

 /* Setting default value: */

} else {

 /* Converting the value to an integer, to prevent errors: */



PS: You always need to start a session at the top of every page ( session_start() )