Jump to content

How to make permissions?


CrazeD

Recommended Posts

that is exactly what i do, but i only have 2 levels of users, admin "1" or non admin "0".  Everybody that signs up automatically gets a "0" (non admin) then using a simple "change user permissions page" i can select a user and change them to admin or not.

 

Then a number is stored in a session and when they go to certain pages it calls that number and checks it if they are admin ...... if they are not ......

 

If( $_session['admin'] = 1){ echo 'You are and admin'; }else{ echo 'you are a nobody';};

 

so yes it is just an if else deal.

 

The reason i use the numbering system is that if i want i can make different levels of admin in the future. so i could make a level 2 admin that has more rights, then it would look like

 

If( $_session['admin'] = 1 OR $_session['admin'] = 2 ){ echo 'You are and admin'; }else{ echo 'you are a nobody';};

 

and now for the really confusing code

 

If( $_session['admin'] = 1 OR $_session['admin'] = 2 ){

      If( $_session['admin'] = 2){

      echo 'you are a level 2 admin';

      }else{

      echo 'You are and admin';

      };

}else{

echo 'you are a nobody';};

 

(it is a if else nested in a if else)

(there has to be a better way to do that nesting)

yes

 

Then when the user logs in

 

$_session['group'] = @mysql_result($result, 0, group);

 

then whenever you need to check if they are an admin

 

IF( $_session['group'] == 1){

Whatever you want to happen if they are an admin

}ELSE{

Whatever you want to happen if they are not an admin

};

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.