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...
create access level in php
Moderator: General Moderators
-
killingbegin
- Forum Newbie
- Posts: 20
- Joined: Sun Feb 08, 2009 5:07 am
Re: create access level in php
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}
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
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...
so how can i manage both levels...
-
sharad99088
- Forum Newbie
- Posts: 2
- Joined: Sun Feb 08, 2009 11:10 am
Re: create access level in php
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
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
-
killingbegin
- Forum Newbie
- Posts: 20
- Joined: Sun Feb 08, 2009 5:07 am
Re: create access level in php
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
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
-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>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