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';
 break;

 case 1 :
  echo 'You are a member';
 break;

 case 2 :
  echo 'You are a admin';
 break;

}

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: */
 $_SESSION['LOGINDATA']['AUTH'] = 0;

} else {

 /* Converting the value to an integer, to prevent errors: */
 $_SESSION['LOGINDATA']['AUTH'] = intval($_SESSION['LOGINDATA']['AUTH']);

}

~G

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.