Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 201
0 Users 4 Guests Online

Creating a Admin page!

In this tutorial, I will show you how to create a working admin page! I will also show you how to make it on every page!

Alright lets start off.

Admin.php:
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
include('config.php'); // gets the database and sitename if needed
session_start(); // starts session
if($logged[username]){
$checkuser $logged['username']; // gets the username for the code below
$user mysql_query("SELECT userlevel FROM members WHERE username = '$checkuser' ORDER BY id DESC LIMIT 1") or die (mysql_error());
$fetchuser mysql_fetch_assoc($user);
$admin $fetchuser['userlevel']; // will get the userlevel from the sql database
if($admin == 2) {
    echo 
"Zup, admin? Your userlevel is $admin"// displays admin message (userlevel 6)
    
}
if(
$admin == 4) {
    echo 
"Zup Mod? Your Userlevel is $admin"// displays mod message (userlevel 4)
    
}
if(
$admin == 6) {
    echo 
"Sorry, members do not have access to this page."// displays normal user message (userlevel 2)
}
} else {
    echo 
"You are not logged in, login, then come back this this page."// no account logged in
}
?>


As you can see each level has its own spot, which you can change.

PHP Code
1
if($admin == 2)

If you see this you know that the user is a admin.

PHP Code
1
if($admin == 4)

If you see this you know that the user is a mod.

PHP Code
1
if($admin == 6)

If you see this you know that the user is a member (no access).

Unlike the other Admin page, this one uses MYSQL to actually get the user level on the page, and I tested it, it works.

Now, if you want to only allow some pages to be accessed by admins or mods without a huge chunk of code then do these steps:

1. Open config.php
2. At the end of the script before the ?> add:

PHP Code
1
2
3
4
$checkuser = $logged['username']; // gets the username for the code below
$user = mysql_query("SELECT userlevel FROM members WHERE username = '$checkuser' ORDER BY id DESC LIMIT 1") or die (mysql_error());
$fetchuser = mysql_fetch_assoc($user);
$admin = $fetchuser['userlevel'];


Alright, so now we just made the mysql in the config file so that we can access it from anywhere as long as we include the config file. Heres an example:

PHP Code
1
2
3
4
5
6
7
<?php
include('config.php');

if(
$admin == 6) {
echo 
"Admin";
}
?>


If you include the config file, you can always use the $admin variable as long as you include that config.

It is a simple way of making a admin page, but it works.

Changing the pages for admins / mods / ect. :

Alright, its fairly simple, If you seen the code above, then its easy. Here:

PHP Code
1
2
3
if($admin == 6) {
    echo "Zup, admin? Your userlevel is $admin"; // displays admin message (userlevel 6)
    }


That code above in the "echo" will show that message if the user is an admin. To change the messages for that user just take the " and " and change it to the level you want. Make sure if you are using a form to put ' instead of ".
I hope this tutorial helps you a lot. s
Diablosblizz
Views:
2599
Rating:
Posted on Thursday 21st June 2007 at 02:40 PM
new2old
new2old
MCP you need to add them yourself
Posted on Saturday 9th June 2007 at 01:15 PM
ShadowMage
ShadowMage
Code

if($admin == 2) {
echo "Zup, admin? Your userlevel is $admin"; // displays admin message (userlevel 6)
}
if($admin == 4) {
echo "Zup Mod? Your Userlevel is $admin"; // displays mod message (userlevel 4)
}
if($admin == 6) {
echo "Sorry, members do not have access to this page."; // displays normal user message (userlevel 2)
}


The problem with that is level 2 is member and level 6 is admin :P
Posted on Tuesday 29th May 2007 at 01:32 AM
MCP
MCP
NVM I fixed that. Now it says "Zup, admin? Your userlevel is 6" Where do I see the admin controls now?
Posted on Tuesday 29th May 2007 at 01:30 AM
MCP
MCP
I use this script and it says I am not admin. I set myself to admin. Why can't I access this panel?
Posted on Monday 14th May 2007 at 12:30 PM
ShadowMage
ShadowMage
same with
PHP Code
1
2
3
4
<?
echo "<a href="link">name</a>";
?>
Posted on Monday 14th May 2007 at 10:49 AM
Dean
Dean
yes but if you do echo(" <a href="link.php"> "); you will get a T String error on line w,e
Posted on Sunday 13th May 2007 at 01:46 PM
Diablosblizz
Diablosblizz
Same thing. echo (" ....... ") is the same as echo ".......";
Posted on Saturday 12th May 2007 at 10:41 PM
Dean
Dean
if you do echo(" <a href="link.php"> "); you will need to make it echo(" <a href='link.php'> "); OR echo(" <a href="link.php"> ");
Posted on Saturday 12th May 2007 at 09:43 PM
Diablosblizz
Diablosblizz
True. I tend to use the ' more because its simple. But " does work too.
Posted on Saturday 12th May 2007 at 09:37 PM
SkillMaster
SkillMaster
Make sure if you are using a form to put ' instead of ".

Or just use before " or '