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.
If you see this you know that the user is a admin.
If you see this you know that the user is a mod.
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
$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
<?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
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