PDA

View Full Version : user groups


owner
09-10-2007, 03:19 AM
Ok, here is my next help question. (Told ya I would have a ton!)

I want to make user groups.

Example: Admin, Moderator, normal user, banned

How do you do this?

also, how can you encrypt a users password so in the database it doesnt show the users exact password.

davidj
09-10-2007, 06:51 AM
create a usergroup column in the db and give each group a number

admin = 1
mod = 2
user = 3
banned = 0

when you create an account you need to add a usergroup dropdown which passes that value into the relevent field in the db

then when you login just assign this value to a session and carry it around. You need then in your security include file to check the group session.

if your using groups then you can build the navigation through php depending on the group level. This means that a user does not see buttons the he is not allowed to click

i can give you an example of this dynamic navigation

owner
09-11-2007, 12:05 AM
Ok, I think I have everything done on the database side. Now, how do I actually use a checking method to figure out what the user is?

Also, how can I make it so that when a user signs up the default group id number stored in the database is whatever number I want.

Example:

admin = 1
mod = 2
user = 3
banned = 0

I would want the default number assigned to people to be 3. Then if I want them mod/admin I would change that in the admin cp.

davidj
09-11-2007, 06:44 AM
use a dropdown with the initial option set as your default so when you do a submit the initial value (3) would always be your default

////

as you have a user table you should have a group column so when you peform your login and match the username and password and then set the username to a session. At this stage you need to set the group to a session and then call your menu. i can show you how to do this

owner
09-11-2007, 01:23 PM
use a dropdown with the initial option set as your default so when you do a submit the initial value (3) would always be your default

////

as you have a user table you should have a group column so when you peform your login and match the username and password and then set the username to a session. At this stage you need to set the group to a session and then call your menu. i can show you how to do this

1. Wont that be unsecure using a dropdown menu as someone could download the page remotely and change the variable from 3 to whatever and gain administrative access?

2. I will probably need your help on that.

davidj
09-11-2007, 01:27 PM
how can you change the value of a dropdown which is hardcoded ?

owner
09-11-2007, 01:31 PM
Erm, I think I read what you were talking about a bit wrong.

I have my groups and stuff setup in the database and another part in the users where it shows the group they are in. Now, how do I check what their id is when they login to have an id of X or X

davidj
09-11-2007, 01:43 PM
post your login script

owner
09-11-2007, 11:56 PM
Hello,

I really wouldn't like to post my login script, would you mind just giving me an example and then I can try to implement it myself. I would prefer this way anyways instead of just copying what you did to my original script so I can learn a bit more off this way.

Thank you,
-Owner

owner
09-13-2007, 01:34 PM
bump,
anyone?

davidj
09-13-2007, 01:38 PM
im not writing one and doing this for you although i will take a fee for this.

owner
09-14-2007, 01:18 AM
Well, all I want is an example code, and I don't want you to implement it, I will do that. I just want to learn off the code. If not, I will go somewhere else and look for an example.

Either way is fine as you have helped me a lot already.

-Owner

davidj
09-14-2007, 06:47 AM
i will write an example but you may have to wait until the weekend

edbr
09-14-2007, 08:36 AM
I got question about this. If there is a form for registering can't there just be a value 3 put in the insert code then an edit form for the admin to change afterwards?
I am asking because I am working along this line myself.

davidj
09-14-2007, 09:59 AM
yes you can do it that way but why would you want to add a user then edit the same user to adjust his group?

its an extra process which need'nt be there. Just set the level from the first step. You could use a dropdown to set the group but default it to the lowest group level

edbr
09-14-2007, 10:08 AM
my thinking was from default to member after fee was received.

davidj
09-15-2007, 03:10 PM
Owner

please write a dummy login script and post that

i need you to do the leg work if im going to write the solution

owner
09-15-2007, 03:49 PM
<?php
/*
Database Connection
*/

$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];

if ($userid && $password) {
$query = sprintf("SELECT * FROM users where id='$userid' and password ='$password'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
}

if ($rowAccount){

header( 'Location: home.php' ) ;
exit;

}elseif($submitted){

echo "Something is wrong with the information you submitted, try again";

}
?>

davidj
09-15-2007, 03:56 PM
ok mate

set your group like this...


<?php
/*
Database Connection
*/
session_start():

$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];

if ($userid && $password) {

$query = sprintf("SELECT * FROM users where id='$userid' and password ='$password'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
}

if ($rowAccount){

$_SESSION['username'] = $rowAccount['user_name'];
$_SESSION['group'] = $rowAccount['group']; //<< **********

header( 'Location: home.php' ) ;
exit;

}elseif($submitted){

echo "Something is wrong with the information you submitted, try again";

}

?>

owner
09-15-2007, 04:04 PM
Ok, then just do an if statement using the group to allow them to do whatever?

davidj
09-15-2007, 04:09 PM
you need to write a dynamic menu which is drawn on the fly

post your full menu and <div>'s or tables (however you have done it) and ill show you how

owner
09-15-2007, 04:17 PM
<div id="nav">
<div class="boxtop">
<h4 style="margin: 0px; font-size: 10px;">Navigation</h4>
</div>
<div class="boxbottom leftside">
<ul>
<li>
<h4 style="margin: 0px; font-size: 10px;">Off The Topic</h4>
</li>
<li>&nbsp;&nbsp;&nbsp;- <a href="./" title="Home - News/Updates">News &amp;
Updates</a></li>
<li>
<h4 style="margin: 0px; font-size: 10px;">Archive</h4>
</li>
<li>&nbsp;&nbsp;&nbsp;- <a href="./archive_news.php" title="News/Updates Archive">News &amp;
Updates Archive</a></li>
<li>
<h4 style="margin: 0px; font-size: 10px;">Miscellaneous</h4>
</li>
<li>&nbsp;&nbsp;&nbsp;- <a href="./links.php" title="Link To Us!">Like To Us</a></li>
</ul>
</div>
<div class="boxtop">
<h4 style="margin: 0px; font-size: 10px;">Extra Block</h4>
</div>
<div class="boxbottom leftside">
<ul>
<?php
if ($id = $_SESSION['id']){
?>
<li>
<?php
echo 'You are already logged in!';
?>
</li>
<li> &nbsp;&nbsp;&nbsp;- <a href="./home.php" title="Home Control Panel">Home CP</a> </li>
<li>
<input type="button" name="Logoff" value="Log off" onclick="document.location.href='logoff.php'" />
</li>
</ul>
</div>
</div>
<?php

}else{
?>
<li> &nbsp;&nbsp;&nbsp;- <a href="./login.php" title="Login">Login</a> </li>
</ul>
</div>
</div>
<?php
}
?>