Page 1 of 1

create access level in php

Posted: Sun Feb 08, 2009 3:39 am
by dheeraj
hello guys i m in a trouble of giving access level for my site....

i want two access levels one for user & 2nd for admin...

i think it will be done by using session but i m not getting how to do tht...

Re: create access level in php

Posted: Sun Feb 08, 2009 5:13 am
by killingbegin
Hi my friend i think yea you using lvls with sessions.i tryied it once.
You also need for every user reg 1 more column in your table with name level
and a new table named lever or level_Access or what you want.
You need to merge those 2 tables with the primary key wich soud be i think the username here.

So with that you can control users to give em access from a dynamic combobox.and make a php page doing smthing

if (user lvl is 1)
{
he can do that
and that and that
}
else
if( lvl= 2){
do that
do that got access there there there}

Re: create access level in php

Posted: Sun Feb 08, 2009 11:11 am
by dheeraj
oh thanx for ur answer, but actually my problem is i hv two login froms one for user & 2nd for admin & i hd restricted sme of the pages, now the problem is tht whn a user logins through user login form he get the key to access admin data, i think this is hapning becoz of session..

so how can i manage both levels...

Re: create access level in php

Posted: Sun Feb 08, 2009 11:22 am
by sharad99088
You simply add a new field called "user_level" in your user table against all user. For admin it should be 1 and for users it should be 2 or something depending on there access level.

When the user will login ,create a session using his ID ( primary key).



so in any page add this piece of code



$result = mysql_query("SELECT user_level from tablename WHERE id=$_SESSION['id']");

while( $val = mysql_fetch_assoc($result))
{
$user_level = $val['user_level'];
}

if ( $user_level != 1)
{
header(Location:homepage.php); //if userlevel is not 1 that mean he is not an admin and cant access this page
}


Bye :-)

sharad.sjce@gmail.com

Re: create access level in php

Posted: Tue Feb 10, 2009 3:53 pm
by killingbegin
lets see
-create 1 more column at your users table with name lvl
To be honest you dont need a new table with lvl access if you know that you will have 1-5 lvls so your combo lvl dont need to be dynamic

And now lets say that users = 1, admins =2, Site creator(you) = 3

-use only 1 form for registration

-Create a .php page that can only see lvl 2 and 3
-create a set.php that will set the lvls for the users

the 1st page with result all your users that have reg at your database and anyone will have a link

Code: Select all

<a href=set.php?id=<?php echo $id_username?>Username</a>
also at that site you will have a
combobox with options 1-2-3

and a submit button

when you submit set.php will get the username id like set.php?id=1
and the value 1 , 2 ,or 3 or more via $_GET['']; method
and your query will be the update set smthing where id = '1'

So know Your 1st admin can control the users.also you can

when you will work with session "im not playing expert with that i dont have work a lot with sessions."
you will see that if the username that is loged in at the moment is set you will get with a query the lvl from the database and

you will make your conditions as you like.
Also if yyou wanna make smthing that for example
if the user can be a admin if he post more than 5000 posts you will update his data with lvl 2.
i hope that i helped a litle