Help - Search - Members - Calendar
Full Version: Groups
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
shinjiketojapann
Yeah...ummm well im building a website for myself and im building in the ACP and MCP and UCP but i cant think of a way to make user groups, admin, mod, user, etc.

and then pages where only users of that group can view.

so I'm asking, is there a tutorial that does this?

so thanks in advance happy.gif
uncled1023
um, what i would do is have a slot in your users table named group, and for each group is a specific number. Then, when you have the user authenthication for each page, you can have it check to see if they have the right group in the database.
Jetteh22
Yep. What UncleD said - Create a "Group" column in your users database. Make it in order.. 1=admin, 2=mod, 3=user.

How you can do this easily as at the very top of the page, use PHP to authenticate it. Using #'s as the group #'s makes it easier.

If, say, ANYONE can view the page, then don't do an authentication script.
If only mods & admins can view the page than have it say something like

if(group > 2) { //group being greater than 2 would mean not a admin/mod
REDIRECT TO NOT AUTHENTICATED PAGE
}
else{
show rest of page
}

you can do same thing. if only admins need to see it ten say if group is > 1
shinjiketojapann
if i do this through a session wouldn't someone be able to change the variable and make them self an admin?

my pages look like this,

header.php
(forum.php, news.php, downloads.php, and so on)
footer.com
Jetteh22
I don't think sessions can be change.. I'm not postive though.
The cookie designed by a session is completely random, unless you change it (I believe).
swordz
Correct Jetteh22. When you start a session, a session Cookie with a unique identifier is stored on the users computer. All the variables are then stored on the server, with that unique identifier so that only that user can access them. The only thing the user has access to is his identifier, and if he changes that, he'll lose all of his variables.

If you still don't think they're secure however, just get the admin/mod level at the beginning of every page - then you won't need sessions. However, it was precisly to stop this that sessions were created for.

swordz
shinjiketojapann
ok thanks,
helped a lot after i read the thing about sessions/cookies
shinjiketojapann
It wont work,

here is my page

QUOTE
<?php

session_start();

require('./template/header.php');

if($_SESSION["group"] > 2) { //group being greater than 2 would mean not a admin/mod
echo "<h2>Error</h2>";
echo "<P>Not Loged in</P>";
}
else{

?>
<h2> Header Title </h2>
<p>Admin Body</p>

<?php
}
require('template/footer.php');
?>


What i mean is that,
well...when i go to the page when I'm logged out, it still shows the regular page,
and not the logged out stuff.
uncled1023
try putting a space between the else and the bracket so instead of else{ put else {
shinjiketojapann
it didn't work T_T
NDBoost
QUOTE(uncled1023 @ Jan 8 2009, 03:05 AM) *
try putting a space between the else and the bracket so instead of else{ put else {


PHP is non space sensitive when it comes to brackets and if/else statements.. you can have it on as many lines and spaces as you like and it wouldn't make a difference.


QUOTE(shinjiketojapann @ Jan 8 2009, 06:18 AM) *
it didn't work T_T

As far as this goes, try doing this:

CODE
<?php
session_start();
$group = $_SESSION['group'];
echo $group;
require('./template/header.php');
if($group > 2) { //group being greater than 2 would mean not a admin/mod
echo "<h2>Error</h2><P>Not Logged in</P>";
}else{
echo "<h2> Header Title </h2><p>Admin Body</p>";
}
require('template/footer.php');
?>


Echo the session $group back and see if it returns >2..

If you have further questions PM me, or aim/msn me and i can help

edit:
i would also suggest defining this as a function, and then calling the function at the top of each page.. that way you dont have to edit 20 pages anytime you want to modify this if/else statement.
shinjiketojapann
its not working, when i try to use it in my acp index.php page it shows the logged in txt
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.