Creating multi user role based admin using php mysql and bootstrap

by  
Share:
Creating multi user role based admin using php mysql and bootstrap

Last two weeks I was quite busy with projects and hardly had any spare time left for writing blogs. I had a huge backlog of mails requesting for tutorials. One thing I found common among them was creating a multi user role based admin feature. I googled for the article so I can give them links but I was not able to find useful tutorial. So i decided to make it myself for my readers. In this tutorial I will be Creating multi user role based admin using php mysql and bootstrap library.

View Demo

What is multi user role based admin?

For novice users let me explain what this article is all about. Suppose you have an online inventory store. You have multiple employee each has their specific roles. i.e some person are responsible for feeding data (Data Operator), some are responsible for customer support and some for sales. In this case you don’t want all your modules/data to be available to every one of them. So what you have to do is to assign a role to them, and then they will have the privilege to access limited data only.

In this tutorial I am not going to make a full fledged admin panel. I will show the trick using mysql database and php logic to create multi user admin. Follow the steps below.

Step 1. Create a database and add modules,system users, role and their rights.

The first step is to create a database. I have created a database named multi-admin. Create some modules that you will be using in your application. Check the sample sql below.

CREATE DATABASE `multi-admin`;
USE `multi-admin`;

CREATE TABLE IF NOT EXISTS `module` (
  `mod_modulegroupcode` varchar(25) NOT NULL,
  `mod_modulegroupname` varchar(50) NOT NULL,
  `mod_modulecode` varchar(25) NOT NULL,
  `mod_modulename` varchar(50) NOT NULL,
  `mod_modulegrouporder` int(3) NOT NULL,
  `mod_moduleorder` int(3) NOT NULL,
  `mod_modulepagename` varchar(255) NOT NULL,
  PRIMARY KEY (`mod_modulegroupcode`,`mod_modulecode`),
  UNIQUE(`mod_modulecode`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

Once you have created modules table, feed some data into it. I have used purchases, sales, stocks and Shipping, payment and taxes. So there are 6 modules in two groups.
INSERT INTO module (mod_modulegroupcode, mod_modulegroupname, mod_modulecode, mod_modulename, mod_modulegrouporder, mod_moduleorder, mod_modulepagename) VALUES 
("INVT","Inventory", "PURCHASES","Purchases", 2, 1,'purchases.php'),
("INVT","Inventory", "STOCKS","Stocks", 2, 2,'stocks.php'),
("INVT","Inventory", "SALES","Sales", 2, 3,'sales.php'),
("CHECKOUT","Checkout","SHIPPING","Shipping", 3, 1,'shipping.php'),
("CHECKOUT","Checkout","PAYMENT","Payment", 3, 2,'payment.php'),
("CHECKOUT","Checkout","TAX","Tax", 3, 3,'tax.php');

Create roles that will be assigned to the admins.
CREATE TABLE IF NOT EXISTS `role` (
  `role_rolecode` varchar(50) NOT NULL,
  `role_rolename` varchar(50) NOT NULL,
  PRIMARY KEY (`role_rolecode`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

INSERT INTO `role` (`role_rolecode`, `role_rolename`) VALUES
('SUPERADMIN', 'Super Admin'),
('ADMIN', 'Administrator');

Add system user/admin who will manage the application. Assign each admin with a role.
CREATE TABLE IF NOT EXISTS `system_users` (
  `u_userid` int(11) AUTO_INCREMENT  NOT NULL,
  `u_username` varchar(100) NOT NULL,
  `u_password` varchar(255) NOT NULL,
  `u_rolecode` varchar(50) NOT NULL,
  PRIMARY KEY (`u_userid`),
  FOREIGN KEY (`u_rolecode`) REFERENCES `role` (`role_rolecode`)  ON UPDATE CASCADE ON DELETE RESTRICT
) ENGINE=INNODB DEFAULT CHARSET=utf8;

INSERT INTO `system_users` (`u_username`, `u_password`, `u_rolecode`) VALUES
('shahrukh', '123456', 'SUPERADMIN'),
('ronaldo', 'ronaldo', 'ADMIN');

The final step is to give each role the privilege to access modules. I have used 4 options i.e create, edit, view and delete.
INSERT INTO `role_rights` (`rr_rolecode`, `rr_modulecode`, `rr_create`, `rr_edit`, `rr_delete`, `rr_view`) VALUES
('SUPERADMIN', 'PURCHASES', 'yes', 'yes', 'yes', 'yes'),
('SUPERADMIN', 'STOCKS', 'yes', 'yes', 'yes', 'yes'),
('SUPERADMIN', 'SALES', 'yes', 'yes', 'yes', 'yes'),
('SUPERADMIN', 'SHIPPING', 'yes', 'yes', 'yes', 'yes'),
('SUPERADMIN', 'PAYMENT', 'yes', 'yes', 'yes', 'yes'),
('SUPERADMIN', 'TAX', 'yes', 'yes', 'yes', 'yes'),

('ADMIN', 'PURCHASES', 'yes', 'yes', 'yes', 'yes'),
('ADMIN', 'STOCKS', 'no', 'no', 'no', 'yes'),
('ADMIN', 'SALES', 'no', 'no', 'no', 'no'),
('ADMIN', 'SHIPPING', 'yes', 'yes', 'yes', 'yes'),
('ADMIN', 'PAYMENT', 'no', 'no', 'no', 'yes'),
('ADMIN', 'TAX', 'no', 'no', 'no', 'no');

Step 2. Create files for every single modules.

This step is very easy. You have to create files for each modules based on names you have given in the database (module table). Apart from the 6 pages that are given the database, you have to create 3 more pages viz. login.php (user will login), dashboard.php (user will see the menu/modules), and logout.php (to clear the session).

Step 3. Creating login form.

If you have followed my earlier tutorials, you should know that I use PDO classes to access the database. If you are new to PDO classes try learning it from a sample mini-project Simple address book with php and mysql using pdo.

 <form class="form-horizontal" name="contact_form" id="contact_form" method="post" action="">
            <input type="hidden" name="mode" value="login" >

            <fieldset>
                <div class="form-group">
                    <label class="col-lg-2 control-label" for="username"><span class="required">*</span>Username:</label>
                    <div class="col-lg-6">
                        <input type="text" value="" placeholder="User Name" id="username" class="form-control" name="username" required="" >
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg-2 control-label" for="user_password"><span class="required">*</span>Password:</label>
                    <div class="col-lg-6">
                        <input type="password" value="" placeholder="Password" id="user_password" class="form-control" name="user_password" required="" >
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-lg-6 col-lg-offset-2">
                        <button class="btn btn-primary" type="submit">Submit</button> 
                    </div>
                </div>
            </fieldset>
</form>

Create a file name config.php to set up basic configuration.
error_reporting( E_ALL & ~E_DEPRECATED & ~E_NOTICE );
ob_start();
session_start();

define('DB_DRIVER', 'mysql');
define('DB_SERVER', 'localhost');
define('DB_SERVER_USERNAME', 'root');
define('DB_SERVER_PASSWORD', '');
define('DB_DATABASE', 'multi-admin');

define('PROJECT_NAME', 'Create Multi admin using php mysql and bootstrap library');
$dboptions = array(
              PDO::ATTR_PERSISTENT => FALSE, 
              PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, 
              PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
              PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
            );

try {
  $DB = new PDO(DB_DRIVER.':host='.DB_SERVER.';dbname='.DB_DATABASE, DB_SERVER_USERNAME, DB_SERVER_PASSWORD , $dboptions);  
} catch (Exception $ex) {
  echo $ex->getMessage();
  die;
}

require_once 'functions.php';

//get error/success messages
if ($_SESSION["errorType"] != "" && $_SESSION["errorMsg"] != "" ) {
    $ERROR_TYPE = $_SESSION["errorType"];
    $ERROR_MSG = $_SESSION["errorMsg"];
    $_SESSION["errorType"] = "";
    $_SESSION["errorMsg"] = "";
}

Validating user login using PHP

$mode = $_REQUEST["mode"];
if ($mode == "login") {
    $username = trim($_POST['username']);
    $pass = trim($_POST['user_password']);

    if ($username == "" || $pass == "") {

        $_SESSION["errorType"] = "danger";
        $_SESSION["errorMsg"] = "Enter manadatory fields";
    } else {
        $sql = "SELECT * FROM system_users WHERE u_username = :uname AND u_password = :upass ";

        try {
            $stmt = $DB->prepare($sql);

            // bind the values
            $stmt->bindValue(":uname", $username);
            $stmt->bindValue(":upass", $pass);

            // execute Query
            $stmt->execute();
            $results = $stmt->fetchAll();

            if (count($results) > 0) {
                $_SESSION["errorType"] = "success";
                $_SESSION["errorMsg"] = "You have successfully logged in.";

                $_SESSION["user_id"] = $results[0]["u_userid"];
                $_SESSION["rolecode"] = $results[0]["u_rolecode"];
                $_SESSION["username"] = $results[0]["u_username"];

                redirect("dashboard.php");
                exit;
            } else {
                $_SESSION["errorType"] = "info";
                $_SESSION["errorMsg"] = "username or password does not exist.";
            }
        } catch (Exception $ex) {

            $_SESSION["errorType"] = "danger";
            $_SESSION["errorMsg"] = $ex->getMessage();
        }
    }
   // redirect function is found in functions.php page
    redirect("index.php");
}

Once you are logged in you are redirected to dashboard.php where you will see the menu/modules that are assigned as per your role. Your role is saved in session when you are logged in.
// if the rights are not set then add them in the current session
if (!isset($_SESSION["access"])) {

    try {

        $sql = "SELECT mod_modulegroupcode, mod_modulegroupname FROM module "
                . " WHERE 1 GROUP BY `mod_modulegroupcode` "
                . " ORDER BY `mod_modulegrouporder` ASC, `mod_moduleorder` ASC  ";

        $stmt = $DB->prepare($sql);
        $stmt->execute();
        // modules group
        $commonModules = $stmt->fetchAll();

        $sql = "SELECT mod_modulegroupcode, mod_modulegroupname, mod_modulepagename,  mod_modulecode, mod_modulename FROM module "
                . " WHERE 1 "
                . " ORDER BY `mod_modulegrouporder` ASC, `mod_moduleorder` ASC  ";

        $stmt = $DB->prepare($sql);
        $stmt->execute();
        // all modules
        $allModules = $stmt->fetchAll();

        $sql = "SELECT rr_modulecode, rr_create,  rr_edit, rr_delete, rr_view FROM role_rights "
                . " WHERE  rr_rolecode = :rc "
                . " ORDER BY `rr_modulecode` ASC  ";

        $stmt = $DB->prepare($sql);
        $stmt->bindValue(":rc", $_SESSION["rolecode"]);

        $stmt->execute();
        // modules based on user role
        $userRights = $stmt->fetchAll();

        $_SESSION["access"] = set_rights($allModules, $userRights, $commonModules);

    } catch (Exception $ex) {

        echo $ex->getMessage();
    }
}

In the above script all the data are passed into a function named set_rights() which return an array based on user roles.
function set_rights($menus, $menuRights, $topmenu) {
    $data = array();

    for ($i = 0, $c = count($menus); $i < $c; $i++) {

        $row = array();
        for ($j = 0, $c2 = count($menuRights); $j < $c2; $j++) {
            if ($menuRights[$j]["rr_modulecode"] == $menus[$i]["mod_modulecode"]) {
                if (authorize($menuRights[$j]["rr_create"]) || authorize($menuRights[$j]["rr_edit"]) ||
                        authorize($menuRights[$j]["rr_delete"]) || authorize($menuRights[$j]["rr_view"])
                ) {

                    $row["menu"] = $menus[$i]["mod_modulegroupcode"];
                    $row["menu_name"] = $menus[$i]["mod_modulename"];
                    $row["page_name"] = $menus[$i]["mod_modulepagename"];
                    $row["create"] = $menuRights[$j]["rr_create"];
                    $row["edit"] = $menuRights[$j]["rr_edit"];
                    $row["delete"] = $menuRights[$j]["rr_delete"];
                    $row["view"] = $menuRights[$j]["rr_view"];

                    $data[$menus[$i]["mod_modulegroupcode"]][$menuRights[$j]["rr_modulecode"]] = $row;
                    $data[$menus[$i]["mod_modulegroupcode"]]["top_menu_name"] = $menus[$i]["mod_modulegroupname"];
                }
            }
        }
    }

    return $data;
}

// this function is used by set_rights() function
function authorize($module) {
    return $module == "yes" ? TRUE : FALSE;
}

Once you have all the modules based on your role in a session variable. Display it as list menu.
 <ul>
                <?php foreach ($_SESSION["access"] as $key => $access) { ?>
                    <li>
                        <?php echo $access["top_menu_name"]; ?>
                        <?php
                        echo '<ul>';
                        foreach ($access as $k => $val) {
                            if ($k != "top_menu_name") {
                                echo '<li><a href="' . ($val["page_name"]) . '">' . $val["menu_name"] . '</a></li>';
                                ?>
                                <?php
                            }
                        }
                        echo '</ul>';
                        ?>
                    </li>
                    <?php
                }
                ?>
</ul>

Step 4. Conditional checking for each modules functionality.

In this step you have to manually check write a security check for a module functionaliy. Let say user has the right to create, edit and view purchases but not delete it. In this case you have to add a conditional checking before each buttons/links. See a sample below for purchases.php page module.

<!-- for creating purchase function -->
<?php if (authorize($_SESSION["access"]["INVT"]["PURCHASES"]["create"])) { ?>
<button class="btn btn-sm btn-primary" type="button"><i class="fa fa-plus"></i> ADD PURCHASE</button> 
<?php } ?>

<!-- for updating purchase function -->
<?php if (authorize($_SESSION["access"]["INVT"]["PURCHASES"]["edit"])) { ?>
<button class="btn btn-sm btn-info" type="button"><i class="fa fa-edit"></i> EDIT</button> 
<?php } ?>

<!-- for view purchase function -->
<?php if (authorize($_SESSION["access"]["INVT"]["PURCHASES"]["view"])) { ?>
<button class="btn btn-sm btn-warning" type="button"><i class="fa fa-search-plus"></i> VIEW</button>
<?php } ?>

<!-- for delete purchase function -->
<?php if (authorize($_SESSION["access"]["INVT"]["PURCHASES"]["delete"])) { ?>
<button class="btn btn-sm btn-danger" type="button"><i class="fa fa-trash-o"></i> DELETE</button>
<?php } ?>

Step 5. Validation for logged in and non-logged in user.

Another security checking, you can add this checking for individual page. check the two test cases below.

  • If user is logged in and trying to access login page. User will be redirected to dashboard.
  • If user is not logged in and trying to access any page expect login page. User will be redirected to login page.

// paste this in login page
if (isset($_SESSION["user_id"]) && $_SESSION["user_id"] != "") {
    // if logged in send to dashboard page
    redirect("dashboard.php");
}

// paste this in any page which require admin authorization
if (!isset($_SESSION["user_id"]) || $_SESSION["user_id"] == "") {
    // not logged in send to login page
    redirect("index.php");
}

You can also add another layer of security check for each modules pages if you want. In case if user is trying to access a modules using direct page URL but is not assigned for, they must not passed this security check.
$status = FALSE;
if ( authorize($_SESSION["access"]["INVT"]["PURCHASES"]["create"]) || 
authorize($_SESSION["access"]["INVT"]["PURCHASES"]["edit"]) || 
authorize($_SESSION["access"]["INVT"]["PURCHASES"]["view"]) || 
authorize($_SESSION["access"]["INVT"]["PURCHASES"]["delete"]) ) {
 $status = TRUE;
}

if ($status === FALSE) {
die("You dont have the permission to access this page");
}

Step 6. Logout Page.

The step is just for clearing the session and redirecting user back to login page.

session_start();
$_SESSION = array();
unset($_SESSION);
session_destroy();
header("location:index.php");
exit;

View Demo
Download

Get the latest updates directly in your inbox for FREE: Subscribe here

Share your feedback / let me know your doubts regarding this tutorial in the comment box given below.

Share:
Hasan

Shahrukh Khan (Hasan)

A software engineer who's a die-hard coder, blogger, dreamer and mentor with years of expertise in web development. Know more...

Related Posts

kapil verma on

Download link going to localhost. Please update it.

Reply
Shahrukh Khan on

Thanks. I have updated it.

Reply
Johny Carter on

Cannot insert role right table does not exist

Goran on

Good tutorial, thank you…

Reply
Shahrukh Khan on

you are welcome.

Salman Khan on

can you provide the download link or mail the code to me.
allah will bless you

Shahrukh Khan on

the download link is at the end of the article, click on the download button

Nikita Shrivastava on

Thank you so much..!! I actually needed some help to overcome this problem. Thanks again.

Reply
Shahrukh Khan on

Yes what help you need?

Reply
Tanjina on

good job bro.

Reply
Shahrukh Khan on

Thank You Tanjina.

Reply
prabakarab on

this is what i am looking for.
thank you so much for sharing

Reply
Shahrukh Khan on

Thanks a lot

Reply
prabakar on

hi sharuk,

can u please tell me how to build this application in codeigniter.?

thanks

Reply
Shahrukh Khan on

All the concept is same, for the database part make a model, use the application logic in the controller and for output the rights/menu in the view file.

Reply
ashok on

hi sharuk,

good job man….

Reply
Shahrukh Khan on

Thanks a lot.

Reply
prabakar on

Hi sharuk

if we use “OR” opertor in In Page level security check , will it retrieve all data?
so we can access below operations right?
create, edit, delete, view.
Please explain

Reply
Shahrukh Khan on

yes it will

Reply
arsalan on

Dear what is the structure of last table/???

Reply
Suman Chhetri on

I downloaded the contents and configured database as instructed but when I’m logging in as ‘Ronald’ , no option is available. When I login through ‘Shahrukh’, only then menu options are visible. Need your assistance.

Reply
Shahrukh Khan on

you have to give rights for ronald.

Reply
Henry on

Thank you for the tutorial, i have followed every step but i am not able to login, also does ” alidating user login using PHP” code go into the config file..

I am just a step away to getting this Kindly help

Reply
Shahrukh Khan on

make sure you have given the access right for the user.

Reply
ask on

Hi there, always i used to check weblog posts here in the early hours in the morning, for the reason that i enjoy to learn more and more.

Reply
umer on

Not able to download any code 🙁

Reply
Shahrukh Khan on

Please click in the social link to unlock the download link

Reply
harinath on

HI Shahrukh,
i am developing a wordpress website with huge data with lots of images ..
if i want to change the website look ..i will upload that whole data again one by one which takes lots of time.
is there any way to insert bulk data at a time??
please help me
Thanks in advance.

Reply
newbee on

sir, can u make 1 register form for this login scripts,
thx before for this great scripts

Reply
sanjay on

useful and very nice

Reply
Jose Rivera on

What happen if you want to create multilevel menu with modules, now you only allow one sub – level
It will be something like this : Banking -> Accounts -> Others…

Reply
Shahrukh Khan on

In that case you can go for a parent-child relationship way using a column say parent that will hold the ID of the parent menu.

Reply
Tony on

Hi
Trying to set this up but I am struggling.
Can you show the sql code to create the role_rights table.

I can’t see the function redirect that should be in the functions php

Could you assist

Thank you

Reply
Shahrukh Khan on

check step 1 of the article.

Reply
Michael on

I can’t thank you enough! Great tutorial

Reply
Pallab on

Very Nice would u plz explain module order section in database part

Reply
Shahrukh Khan on

everything is already explained, what part are you facing problem.

Reply
sonia on

hello…i am not able to get the moduleorder and modulegrouporder could you please explain how its working?

Reply
jack on

The role_rights table is unavailable. Kindly share it with me

Reply
Shahrukh Khan on

it is there, please check.

Reply
Alex Yeung on

I can’t get the download link even I like it.

Reply
Shahrukh Khan on

double click on that like button.

Reply
alvaro on

Thank you for this amazing tutorial!
I would like to ask if it’s possible to do the same but instead with a website, using android! So far I’ve already created the database and I am capable to insert and modify values, but I’m not sure how I would relate the roles depending of the user… thanks!

Reply
Shahrukh Khan on

well I am not into Android. but I am sure you have to use the logic the same way given here.

Reply
balamurali on

mr khan i have share your website link to my facebook but the downloading option is not avaliabe so pls help me.send the downlaoding link to my email id “3dbalamurali@gmail.com”

Reply
Shahrukh Khan on

try double clicking on the social link. it will work

Reply
simhaa on

hi i am simhaa ,can u send me the code of this tutorial part

Reply
simhaa on

this is good exactlly fits my requirement and iam new to programing

Reply
Shahrukh Khan on

hi. Kindly click on the social links again to unlock the download link.

Reply
Sumit Nair on

Hi bro i am unable to convert your sql code to codeigniter like prepare which is in dashboard.php but i loved your code please help me out buddy how should i write this code in codeigniter

Reply
Shahrukh Khan on

Hi bro . i am not that expert in codeignitor but all you have to do is create a model that will have query part to fetch the permission from database. In the controller you can set the access right in the session variable from models and in the views you can give condition based on that. just the theory on how MVC works. hope this will provide you the guideline.

Reply
Sumit Nair on

Thanks buddy with reference to your code i did it and yes this code helped me alot although it was really tough to convert this code but still just because off your code i was able to complete it thanks alot buddy keep on coding 🙂 🙂

Shahrukh Khan on

Thanks I am glad it helped.

benayad on

hello,
excuse my English is so bad
in your function you are
function set_rights($menus, $menuRights, $topmenu)
but $topmenu is not use anywhere,

Please can you reply

Reply
Shahrukh Khan on

It is used for checking the access rights. If its not used for you can remove that parameter.

Reply
Cahyan on

Sorry, my English is bad
Hello, to be used as mysqli, these functions should be modified as what?
Please reply

function set_rights($menus, $menuRights, $topmenu) {
$data = array();

for ($i = 0, $c = count($menus); $i < $c; $i++) {

$row = array();
for ($j = 0, $c2 = count($menuRights); $j < $c2; $j++) {
if ($menuRights[$j]["rr_modulecode"] == $menus[$i]["mod_modulecode"]) {
if (authorize($menuRights[$j]["rr_create"]) || authorize($menuRights[$j]["rr_edit"]) ||
authorize($menuRights[$j]["rr_delete"]) || authorize($menuRights[$j]["rr_view"])
) {

$row["menu"] = $menus[$i]["mod_modulegroupcode"];
$row["menu_name"] = $menus[$i]["mod_modulename"];
$row["page_name"] = $menus[$i]["mod_modulepagename"];
$row["create"] = $menuRights[$j]["rr_create"];
$row["edit"] = $menuRights[$j]["rr_edit"];
$row["delete"] = $menuRights[$j]["rr_delete"];
$row["view"] = $menuRights[$j]["rr_view"];

$data[$menus[$i]["mod_modulegroupcode"]][$menuRights[$j]["rr_modulecode"]] = $row;
$data[$menus[$i]["mod_modulegroupcode"]]["top_menu_name"] = $menus[$i]["mod_modulegroupname"];
}
}
}
}

return $data;
}

// this function is used by set_rights() function
function authorize($module) {
return $module == "yes" ? TRUE : FALSE;
}

Read more: https://aarafacademy.com/creating-multi-user-role-based-admin-using-php-mysql-bootstrap/#ixzz3zdIF0RiJ

Reply
RBN on

I created role_rights table as:

CREATE TABLE IF NOT EXISTS `role_rights` (
`rr_rolecode` int(11) NOT NULL,
`rr_modulecode` varchar(100) NOT NULL,
`rr_create` varchar(25) NOT NULL,
`rr_edit` varchar(25) NOT NULL,
`rr_delete` varchar(25) NOT NULL,
`rr_view` varchar(25) NOT NULL,
FOREIGN KEY (`rr_rolecode`) REFERENCES `role` (`role_rolecode`) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (`rr_modulecode`) REFERENCES `module` (`mod_modulecode`) ON UPDATE CASCADE ON DELETE RESTRICT
) ENGINE=INNODB DEFAULT CHARSET=utf8;

BR,
Rbn

Reply
Pampa bakshi on

Thank you very much

Reply
T. khanna vijay on

hi ,

may i know how to retrieve three level menu
1>main
2>sub
3>template level
can u please suggest me

thanks & regards

Reply
tuhin on

How are you brother. I’m your source code will be given to me. It’s nice if you would benefit hayecheya.

Reply
Shahrukh Khan on

I am good bro. please click on the social link at the end of the article you will get the download link of the source code.

Reply
Ola on

Hello my friend, good resource there… i want to ask as a super admin, can i add more field to the database.

Shahrukh Khan on

Hello. Of course you can do that directly to the database or you can code a page where you can add this feature. Best of luck

tuhin on

Thank u Brother

Reply
tuhin on

Bro. ami ki kora database a new data post korta pari ektu bolben plz……

Reply
Shilpitha on

Hi Shahrukh,

I’m unable to view this application as in demo.
I’m getting this SQLSTATE[HY000] [1049] Unknown database ‘multi-admin’ when i run, can you please guide me on this. I’m new for PHP

Reply
Shahrukh Khan on

Hello Shilpitha.
Make sure you have already created a database ‘multi-admin’ in your mysql database. If already created make sure you spelt it correctly. Best of luck.

Reply
Michael on

Would be great if this was done with mysqli. Great Tutorial anyway

Reply
Shahrukh Khan on

mysqli or PDO is just a personal preference 🙂

Reply
sudeep on

Good work Bro, Keep it up!

Reply
akin on

Sorry. What is the download link. What social link do I click on? Please point it out. Thanks

Reply
Shahrukh Khan on

click on the any social button below the article to download.

Reply
bougdim on

thanks

Reply
Queen on

Hi. Thanks very much for this wonderful input. Kindly help me understand how to create the table for the role_rights. Thanks

Reply
Pradeepsingh on

Nice Project Shahrukh..!
it willl help me lot to understand & design a similar system.

Reply
raj on

how to make it responsive?

Reply
Shahrukh Khan on

Its already responsive, made with bootstrap library.

Reply
Nakul Gupta on

Sir yesterday I request tutorial so sir in how many days you give tutorial and publish it in website . Because I need it urgently so please make fast. I sent request tutorial with my I’d fcnakul@gmail.com

Reply
Shahrukh Khan on

Tutorial is posted as per my work schedule and does not guarantee any time span. Hope you understand.

Reply
Mac on

Hallow Shahrukh,

I have understood reason for these fields mod_modulegrouporder and mod_moduleorder in module table

Reply
Shahrukh Khan on

Great.

Reply
Upasana on

I am trying to do this website I have not uploaded it yet. I might do on the intranet then the internet. I have a problem. Which page does the code between step 3 and 4 go. I am confused about that.

Reply
Shahrukh Khan on

Just create a form in your login.php (or whatever page you want) and when you give the action of the page where the code to validate the user is given after that. Just use the code in whatever file you have named.

Reply
Upasana on

Thanks a lot. I will try to do actually I m new to PHP and am trying to learn. Single user I have been doing in general but this is new.

RAJESH SAHOO on

Hi dude ,i just view your blog that’s awesome. I have problem please help me ,i download your source code and use it as demos whenever i’m click on Add button for add new item it’s not show the insert form please help me for this.

Reply
Shahrukh Khan on

thanks..the download file has the exact clone of the demo.. maybe you are missing something.. what is the error.

Reply
Ajay Tiwari on

Hey Good Job bro,
But in admin lte panel there is a big issue of session, Session automatically expired still i have set it for 8 hour and after session expire login again and its not loading all menu,

Please help

Reply
Shahrukh Khan on

Hi.
Please contact admnlte template owner/staff for best solutions as they have made the template.

Reply
Ajay Tiwari on

Yes i can understand but this is not the issue of bootstrap this is issue your php code.
Cam you plz help .
You can laso check it in demo plz login once and clear the cookie it will logout automatically and login again you are not able to see menu thas the problem

Surendra on

I need 5 admins, How can i create them?
As There are only two users(Super admin and Admin) in your code.

Reply
Shahrukh Khan on

create from database directly, using phpmyadmin

Reply
albab on

Thanks for this great tutorial

In your tutorial, the accessed page is only one per module (lets say in “module code of Payment” there is a page of “payment.php” (only one page) – in the “module code of Shipping” there is a page of “shipping.php”).

My question is, How if we want to make the user can access to several pages instead of one (example, in the “module code Payment” there will be “payment.php” and “payment1.php” and “payment2.php”)

Thank You.

Reply
Shahrukh Khan on

you need to use module name and put a condition check on each pages.

Reply
seetha on

user name and password is not working to view demo

Reply
Shahrukh Khan on

it will work

Reply
sumit on

cant download the files even though i have liked it Facebook

Reply
Shahrukh Khan on

try unlike and like again.

Reply
AD on

hey bro when i try to create table like:

CREATE TABLE IF NOT EXISTS role_rights (
rr_rolecode int(11) NOT NULL,
rr_modulecode varchar(100) NOT NULL,
rr_create varchar(25) NOT NULL,
rr_edit varchar(25) NOT NULL,
rr_delete varchar(25) NOT NULL,
rr_view varchar(25) NOT NULL,
FOREIGN KEY (rr_rolecode) REFERENCES role (role_rolecode) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (rr_modulecode) REFERENCES module (mod_modulecode) ON UPDATE CASCADE ON DELETE RESTRICT
) ENGINE=INNODB DEFAULT CHARSET=utf8;

it is showing: MySQL said: Documentation

#1005 – Can’t create table ‘multi-admin.role_rights’ (errno: 150) (Details…)

what is the reason plzz give me working code of creating table named: role_rights

Reply
Shahrukh Khan on

Have you created the table role and module.

Reply
AD on

yes now its done…

Budi on

String must be same !!! you can see in role and module database

Reply
lacroix on

//
CREATE TABLE IF NOT EXISTS role_rights (
rr_rolecode int(11) NOT NULL,
rr_modulecode varchar(100) NOT NULL,
rr_create varchar(25) NOT NULL,
rr_edit varchar(25) NOT NULL,
rr_delete varchar(25) NOT NULL,
rr_view varchar(25) NOT NULL,
FOREIGN KEY (rr_rolecode) REFERENCES role (role_rolecode) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (rr_modulecode) REFERENCES module (mod_modulecode) ON UPDATE CASCADE ON DELETE RESTRICT
) ENGINE=INNODB DEFAULT CHARSET=utf8;
//
When I’ve adding this thru phpmyadmin I get this:
MySQL said: Documentation

#1215 – Cannot add foreign key constraint

Reply
Shahrukh Khan on

have you create module and role table

Reply
Pankaj Joshi on

Thank you very much… i got the code which i want… now, i will configure it as my own need.

Shahrukh Khan on

You are welcome.

Arslanali on

Hi. Thank you for tutorial.
I would like to see the implementation of editing, adding, deleting, viewing in bootstrap 🙂

Reply
Arslanali on

It will be a good addition to your lesson

Reply
hungtrada on

hi, tks for your shared
but I got an mistake, When I click in /purchases.php : back to Dashboard .. the page only show Inventory when I click /purchases.php and click back to Dashboard ..the page no show any page… Pls help
tks

Reply
Martins on

Great work sir. but theptoblem I have is that the add, edit and delete functions does not work. when I click, it doesnt respond. Please help me

Reply
Shahrukh Khan on

you need to add the logic yourself. This is just a sample

Reply
Bonny on

“you need to add the logic yourself. This is just a sample”
please can you assist to show us how to add?

Reply
Shahrukh Khan on

Regarding which part

Reply
Developer on

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘multi-admin.module.mod_modulegroupname’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Reply
Tuhin on

Hi, Bro…Ami Role Table A Data insert Error Problem……Plz Solve Me Brother

require(“config.php”);
if (isset($_REQUEST[“sub”])) {

$role_rolecode = trim(($_REQUEST[“p_name”]));
$role_rolename = trim(($_REQUEST[“p_age”]));
if ($p_name “” && $p_age “”) {
$sql = “INSERT INTO `role` (`role_rolecode`, `role_rolename`) VALUES (:n, :a);”;
$success_message = ‘Data has been inserted successfully.’;
try {
$stmt = $DB->prepare($sql);
$stmt->bindValue(“:n”, $p_name);
$stmt->bindValue(“:a”, $p_age);

$stmt->execute();

if ($stmt->rowCount()) {

} else {
printErrorMessage(“could not insert into database. Please try again”);
}
} catch (Exception $ex) {
printErrorMessage($ex->getMessage());
}

} else {

}
}
?>

Database Sample Script – aarafacademy.com

Sample Database Script :: Add Record

Back to Homepage

Role:

Role Name:

Reply
Tuhin on

solve the problem_Thanks Shahrukh Bhai

Reply
Pravin on

Hi Shahrukh,

NEED HELP !!!

I have a problem while logging in.
It accepts the Username and Password correctly through Database table system_users, but doesn’t logs into the website to dashboard. Instead, it again redirects me to Index page.

Would you help me with this issue ?

Reply
Pravin on

Resolved the problem!

Reply
Shahrukh Khan on

maybe your session is not correct or redirection issue.

Reply
edmond on

how to convert this in to mvc

Reply
Shahrukh Khan on

which mvc framework

Reply
Javi Cases on

correct table definition:

CREATE TABLE IF NOT EXISTS role_rights (
rr_rolecode varchar(50) NOT NULL,
rr_modulecode varchar(25) NOT NULL,
rr_create varchar(25) NOT NULL,
rr_edit varchar(25) NOT NULL,
rr_delete varchar(25) NOT NULL,
rr_view varchar(25) NOT NULL,
FOREIGN KEY (`rr_rolecode`) REFERENCES `role` (`role_rolecode`) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (`rr_modulecode`) REFERENCES `module` (`mod_modulecode`) ON UPDATE CASCADE ON DELETE RESTRICT
) ENGINE=INNODB DEFAULT CHARSET=utf8;

Reply
Aditya on

I am trying to login from firefox by your demo as well http://demos.aarafacademy.com/multi-user-admin/

but still the page is redirecting me back to index page after login … there is some problem with the code i guess could you please check

Thanks

Reply
Shahrukh Khan on

working fine here, maybe you can clear your cache and check.

Reply
pagande on

assalaamu alaikum,
Sorry, if my english is not good.
thank you for your shared.
Can i add any module other than create, edit, view and delete?

Reply
Shahrukh Khan on

Walikum assalam. Yes you can add any modules you want. just add extra columns in role_rights table and also in the code as well.

Reply
pagande on

I’ve tried, but not yet.
In addition to the Create, Edit, View, and delete module, I want to add the module Balas and Terima.

This database role_rights:

CREATE TABLE IF NOT EXISTS `role_rights` (
`rr_rolecode` varchar(50) NOT NULL,
`rr_modulecode` varchar(25) NOT NULL,
`rr_create` enum(‘yes’,’no’) NOT NULL DEFAULT ‘no’,
`rr_edit` enum(‘yes’,’no’) NOT NULL DEFAULT ‘no’,
`rr_delete` enum(‘yes’,’no’) NOT NULL DEFAULT ‘no’,
`rr_view` enum(‘yes’,’no’) NOT NULL DEFAULT ‘no’,
`rr_balas` enum(‘yes’,’no’) NOT NULL DEFAULT ‘no’,
`rr_terima` enum(‘yes’,’no’) NOT NULL DEFAULT ‘no’,
PRIMARY KEY (`rr_rolecode`, `rr_modulecode`),
FOREIGN KEY (`rr_rolecode`) REFERENCES `role` (`role_rolecode`) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (`rr_modulecode`) REFERENCES `module` (`mod_modulecode`) ON UPDATE CASCADE ON DELETE RESTRICT
) ENGINE=INNODB DEFAULT CHARSET=utf8;

INSERT INTO `role_rights` (`rr_rolecode`, `rr_modulecode`, `rr_create`, `rr_edit`, `rr_delete`, `rr_view`, `rr_balas`, `rr_terima`) VALUES
(‘SUPERADMIN’, ‘PURCHASES’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘STOCKS’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘SALES’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘SHIPPING’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘PAYMENT’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘TAX’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘ADMIN’, ‘PURCHASES’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘no’, ‘no’),
(‘ADMIN’, ‘STOCKS’, ‘no’, ‘no’, ‘no’, ‘yes’, ‘no’, ‘no’),
(‘ADMIN’, ‘SALES’, ‘no’, ‘no’, ‘no’, ‘no’, ‘no’, ‘no’),
(‘ADMIN’, ‘SHIPPING’, ‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘no’, ‘no’),
(‘ADMIN’, ‘PAYMENT’, ‘no’, ‘no’, ‘no’, ‘yes’, ‘no’, ‘no’),
(‘ADMIN’, ‘TAX’, ‘no’, ‘no’, ‘no’, ‘no’, ‘no’, ‘no’);

Script on file functions.php :

function set_rights($menus, $menuRights, $topmenu) {
$data = array();

for ($i = 0, $c = count($menus); $i < $c; $i++) {

$row = array();
for ($j = 0, $c2 = count($menuRights); $j < $c2; $j++) {
if ($menuRights[$j]["rr_modulecode"] == $menus[$i]["mod_modulecode"]) {
if (authorize($menuRights[$j]["rr_create"]) || authorize($menuRights[$j]["rr_edit"]) ||
authorize($menuRights[$j]["rr_delete"]) || authorize($menuRights[$j]["rr_view"]) ||
authorize($menuRights[$j]["rr_balas"]) || authorize($menuRights[$j]["rr_terima"])
) {

$row["menu"] = $menus[$i]["mod_modulegroupcode"];
$row["menu_name"] = $menus[$i]["mod_modulename"];
$row["page_name"] = $menus[$i]["mod_modulepagename"];
$row["create"] = $menuRights[$j]["rr_create"];
$row["edit"] = $menuRights[$j]["rr_edit"];
$row["delete"] = $menuRights[$j]["rr_delete"];
$row["view"] = $menuRights[$j]["rr_view"];
$row["balas"] = $menuRights[$j]["rr_balas"];
$row["terima"] = $menuRights[$j]["rr_terima"];

$data[$menus[$i]["mod_modulegroupcode"]][$menuRights[$j]["rr_modulecode"]] = $row;
$data[$menus[$i]["mod_modulegroupcode"]]["top_menu_name"] = $menus[$i]["mod_modulegroupname"];
}
}
}
}

return $data;
}

Script on file purchases.php :

if ( authorize($_SESSION["access"]["INVT"]["PURCHASES"]["create"]) ||
authorize($_SESSION["access"]["INVT"]["PURCHASES"]["edit"]) ||
authorize($_SESSION["access"]["INVT"]["PURCHASES"]["view"]) ||
authorize($_SESSION["access"]["INVT"]["PURCHASES"]["delete"]) ||
authorize($_SESSION["access"]["INVT"]["PURCHASES"]["balas"]) ||
authorize($_SESSION["access"]["INVT"]["PURCHASES"]["terima"]) ) {
$status = TRUE;
}

EDIT

VIEW

DELETE

BALAS

TERIMA

If logged in as superadmin level,
Which appears only edit, view, delete.
Being BALAS and TERIMA not showing.

What’s wrong with where?
Thank you very much

pagande on

Sorry, its code is not showing .

purchases.php
————-

if ( authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“create”]) ||
authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“edit”]) ||
authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“view”]) ||
authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“delete”]) ||
authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“balas”]) ||
authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“terima”]) ) {
$status = TRUE;
}

if (authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“edit”])) {
EDIT
}
if (authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“view”])) {
VIEW
}
if (authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“delete”])) {
DELETE
}
if (authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“balas”])) {
BALAS
}
if (authorize($_SESSION[“access”][“INVT”][“PURCHASES”][“terima”])) {
TERIMA
}

Shahrukh Khan on

becuase your session is empty

pagande on

thank you for your answer.
On which part of the session is defined?
🙂

Shahrukh Khan on

in the config file

Harshit on

Hi Shahrukh,
I am basically a kid and i have my project in which i need to have a login page and i dont even know php so could u please tell me how to open this file.

Reply
arshad on

i’m getting invalid argument on this line: foreach ($_SESSION[“access”] as $key => $access)

Reply
Shahrukh Khan on

maybe your session has expired or session variable is not set properly.

Reply
arshad on

What is the use of moduleorder here?

Reply
Shahrukh Khan on

just to display in order of menus

Reply
Akshay on

Thank You Mr. Shahrukh for sharing a good work. I also need this and I will try with your work. If I face any problems I will contact you.

Reply
Shahrukh Khan on

You are welcome.

Reply
Ade on

You have done a very good job..

pavan on

HI shahrukh,

i am getting error while i trying to module name.can you please help us.

Error Code: 1452
Cannot add or update a child row: a foreign key constraint fails (`multi-admin`.`role_rights`, CONSTRAINT `role_rights_ibfk_2` FOREIGN KEY (`rr_modulecode`) REFERENCES `module` (`mod_modulecode`) ON UPDATE CASCADE)

INSERT INTO module (mod_modulegroupcode, mod_modulegroupname, mod_modulecode, mod_modulename, mod_modulegrouporder, mod_moduleorder, mod_modulepagename) VALUES
(“INVT”,”reports”, “reports1″,”Purchases”, 2, 1,’import.php’),
(“INVT”,”reports”, “reports2″,”Stocks”, 2, 2,’stocks.php’),
(“INVT”,”reports”, “reports3″,”Sales”, 2, 3,’sales.php’),
(“CHECKOUT”,”Checkout”,”SHIPPING”,”Shipping”, 3, 1,’shipping.php’),
(“CHECKOUT”,”Checkout”,”PAYMENT”,”Payment”, 3, 2,’payment.php’),
(“CHECKOUT”,”Checkout”,”TAX”,”Tax”, 3, 3,’tax.php’);

INSERT INTO `role_rights` (`rr_rolecode`, `rr_modulecode`, `rr_create`, `rr_edit`, `rr_delete`, `rr_view`) VALUES
(‘SUPERADMIN’, ‘reports1’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘reports2’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘reports1’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘SHIPPING’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘PAYMENT’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘TAX’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),
(‘SUPERADMIN’, ‘REPORT’, ‘yes’, ‘yes’, ‘yes’, ‘yes’),

Reply
Shahrukh Khan on

maybe there is a spelling mistake with your code for module name. thats the reason its not able to insert

Reply
pavan on

Thanks shahrukh.
i got it .

Can your please provide php script to check the duplicate mail id from csc

Shahrukh Khan on

Great. Either set the column name to unique in the database (recommend). Or when you update a new record check if you have any record that exist with that email address.

neeraj on

Sir,
I am new in php. I downloaded your code. While running, a message shows that ‘Warning: Invalid argument supplied for foreach() in C:\wamp\www\shahrukh\dashboard.php on line 69 and ‘Warning: Invalid argument supplied for foreach() in C:\wamp\www\shahrukh\dashboard.php on line 95’. What is the solution?
Thank you.

Reply
Shahrukh Khan on

I think you dont have data in the result set that why.

Reply
Neeraj Kumar on

Sir,
I am new in programming. I downloaded your code and tried to run. A message shows that
1. SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘multi-admin.module.mod_modulegroupname’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
2. Warning: Invalid argument supplied for foreach() in C:\wamp\www\shahrukh\dashboard.php on line 69
3. Warning: Invalid argument supplied for foreach() in C:\wamp\www\shahrukh\dashboard.php on line 95.
4. I have seen above the same query made by someone on January 6, 2017 1:12 AM but no answer was given.
5. As I am new in programming, it is requested to explain why ‘wherre 1 order by —-‘ is used in the query:-
$sql = “SELECT mod_modulegroupcode, mod_modulegroupname, mod_modulepagename, mod_modulecode, mod_modulename FROM module ”
. ” WHERE 1 ”
. ” ORDER BY mod_modulegrouporder ASC, mod_moduleorder ASC “;used at lines 23-25 in dashboard.php.
Thanking you.

Reply
Shahrukh Khan on

i think its your database issue. make sure the schema is built properly.

Reply
Neeraj Kumar on

Dear sir,
Reference: In continuation of the query made by me on 13/08/2017 that is showing just above, it is to state that
first of all, I have not changed your database as well as your programme
and secondly, my php is 5.7 wherein this type of issue continuously are shown. Please rectify your programme as per php 5.7 and latest versions.
Thanking you.

Shahrukh Khan on

i will try to write a new more smart tutorial in coming week which will be compatible with php7 as well. Although it works fine with php5 as well.

mahesh on

when i logout it does not redirect to index.php but still showing dashhboard.php does not clear or reset session ,demo on your site is working fine is there is any setting i have to create in php.ini file please help me

Reply
Shahrukh Khan on

see your session data.

Reply
Jonathan Ornstein on

THANK YOU FOR THIS!!!!!!

Reply
carlo on

can i have your help sir for my project?

Reply
Shahrukh Khan on

Yes regarding

Reply
lily on

hi .. nice content … i still couldnt find anyboby else posting role based login…but i need some help… can the admin create username and password for the users to login… like admin has password and after he logs in he has to create username and passwords for users and give it to them and then the user can login .. can you help me in this..

Reply
lily on

k main question can superadmin assign role rights for the admins on the frontend.. not on database..?? if so can u helpme?

Reply
Shahrukh Khan on

Dont get your question

Shahrukh Khan on

yes it is surely possible, you need to code it.

Reply
Lily on

yes i did it with the help of your codes thank you so much

Shahrukh Khan on

you are welcome.

Taha Ahmad on

Hello Dear ,
your database design is awesome can you send me the picture of database design with relationships .

regards
Taha Ahmad

Reply
Shahrukh Khan on

you get the total code why you need picture.

Reply
soumya on

hi ,
i need php code for posting new events from admin dashboard to the user page.
and adding revies and ratings

Reply
Naman on

Can we get the same in script converted in mysqli

Reply
Shahrukh Khan on

pdo and mysqli is almost same, check the manual for more references.

Reply
sanjay kumar on

i want to registration.php page of this demo for learning because i am a beginner….

Reply
sanjay kumar on

You send it by gmail

Reply
Geetanshu on

Hi Shahrukh..
can u help me out for having almost same kind of functionality implement with asp.net and sql server.
i am working with login for admin…admin register user with different roles…one user can have multiple roles…and based on it….individual or clubbed menus will be displayed…
i have three tables in db….Users, Roles and RolesAllocated

Reply
Shahrukh Khan on

Hi. Sorry i dont work on asp.net but the solution of the problem is the same.

Reply
Abhishek Pandey on

plz can you help regard , if i have logout and re login then sometime work and sometime not working menu/modules foreach

Reply
Abhishek Pandey on

plz help me jab se https lgaya hai domain me tabse ye problem hui h

Reply
Shahrukh Khan on

kya problem hai?

Shahrukh Khan on

what is your error message?

Reply
adnan khan on

Hi Shahrukh,

Your tutorial is great but i have one issue i am beginner and i don’t know about PDO can you convert it into mysqli plzzzzzzzzzzzz my one project stuck due to this issue plzzzzzzzzz can you do this or anybody.

Reply
Shahrukh Khan on

pdo and mysql are almost same, just the syntax are different. rest both of them are use for database connectivity

Reply
Rashid Ahmed Barbhuyan on

Assalamualaikum! I m working on xampp server. How can I add “edit, view, delete & add” link on the module pages?

Reply
Shahrukh Khan on

hi. download my zip file. its a great way to get started.

Reply
Sanjay Namdeo on

you dont share how to create role_rights table
you only insert into values.

Reply
Sanjay Namdeo on

i get file on code zip.
thanks bro this is great work…

Reply
Shahrukh Khan on

you are welcome.

frisör gävle on

I must thank you for the efforts you have put in penning this site.
I really hope to check out the same high-grade content from you later on as
well. In truth, your creative writing abilities has inspired me to get my
own site now 😉

Reply
ss on

why didont add payment ?

Reply
Shahrukh Khan on

means?

Reply
Thokchom on

Thanks buddy

Reply
rizal on

can you give me sample with “mysqli” ?

Reply
Shahrukh Khan on

mysqli and pdo are almost same.

Reply
Shreya on

Hi
I am looking for the same code but not in PDO .
I want to make same functionality as u provide,can u help me for build same in mysqli.

Thankss

Reply
Rakesh Patel on

Dear Shahrukh Khan,

First of all would like to say Thank you so much for this script.

Need small help here, how to hide some pages from menu but on that page I have assign rights also.

In Advance thank you for your kind support,

With Best regards,

Reply
Shahrukh Khan on

Hi Rakesh!

You are welcome, I am not sure what exactly you want to do. first you need to hide pages and then in those pages you want what kinds of rights?

Reply
Mathavan on

Thanks man. perfect code. helps me a lot.

Reply
Shahrukh Khan on

You are welcome!

Reply
saeed on

hi
How can I change access and name change?
Thankful

Reply
Shahrukh Khan on

Through database

Reply
rakhsha on

Sorry how can i display the user name entered?

Reply
Shahrukh Khan on

where?

Reply
azad on

How to create a user role and permission form?

Reply
Shahrukh Khan on

okay, so that part is not done in this tutorial. I will try to do that tutorial soon. You can try that from your end now.

Reply
Blessing on

Hi,such a great tutorial! Just wanted to find out, in the modules table, whats the modulegrouporder & moduleorder numbers? thanks a lot in advance

Reply
Shahrukh Khan on

modulegrouporder the sorting order for the module group, and moduleorder is used to sort the menus of modules.

Reply
Tanzeel Ali on

sir mjhy mera aik chota sa database entry ka project bnya ha …
jis ma 3 forms ha user jis ma admin aur editor create ho skty ha ,
2 bill 3 claim
ab admin ko all pages ka rights deny ha aur editor ko single page ka rights deny ha kch help kr skty ha meri is ma

Reply
Shahrukh Khan on

I have emailed you, in case you haven’t received, please email me your queries.

Reply
Lilesh jadav on

Are You Available For Paid Work?
Please Email Me If Yes

Reply
Shahrukh Khan on

OK

Reply
Daniel on

Buenas Tardes Amigo
gracias por tu code, pero queiro consultar si no pudieras pasar tu codigo donde das acceso a cada pagina de acuerdo al permiso que se le asigna a cada usuario, luego yo pueda aditar o quitar privilegios.

Saludos Daniel

Reply
Shahrukh Khan on

what is the error message you are getting.

Reply
christian on

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘multi-admin.module.mod_modulegroupname’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
it is my problem how to solve it

Reply
Kassandra on

Hello i already have a login page but the only problem is i want multiple admin so how do i link the login page to the database

Reply
Shahrukh Khan on

You can use the database and code provided and try to integrate in your projects. make sure you set the session well.

Reply
Gerald Nduaguba on

Could you do this using mysqli proceedural rather than pdo

Reply
Shahrukh Khan on

I prefer using PDO over PDO.

Reply
Shahrukh Khan on

I prefer using PDO over mysqli.

Reply
Noor on

Thank youuuu soo much

Reply
Jonas on

Hello,

Great script! Easy to use. Just have a quesstion.
So i dont want all the useres to have access to the Admin panel. so i am wondering, how can i restrict access to a role named “Users” or “Supporter”.

I have created a Role Named: User, and a role_rights for user, where rr_modulecode is set to ADMINPANEL and all permissions = no. Also made a Module called ADMINPANEL wich has mod_modulepagename to index.php

So basicly how do i go forward with redericting non-permission users back to the frontpage ?

Reply
Jonas on

$status = false;
if ( authorize($_SESSION["access"]["ADMINPANEL"]["APANEL"]["create"]) ||
authorize($_SESSION["access"]["ADMINPANEL"]["APANEL"]["edit"]) ||
authorize($_SESSION["access"]["ADMINPANEL"]["APANEL"]["view"]) ||
authorize($_SESSION["access"]["ADMINPANEL"]["APANEL"]["delete"]) ) {
$status = true;
}
if ($status === FALSE) {
die("You dont have the permission to access this page");
}

that code dosnt work eather. I have added ADMINPANEL and APANEL to the database table Module. Also given Superadmin all the permissions. it gives me “You dont have the permissions to access this page”.

(All i have changed on the script is that i am using steam login, this works because i can see the menu bar generated via the foreach script with the correct permissions. But when i try to use the authorize part, to restrict pages + functions it wont work. None of the info / permissions is showing when i am using that. ). My Database isnt the exact same as yours, but all the things that was linked, in the database.sql file, is also linked in my database.

This happends on all the pages, Shipping, tax, payment.php etc

Reply
Jonas on

Got it working. For now. I had the authorize positioned in the wrong area. All i did was moving it. and now everything works.

Shahrukh Khan on

Great. most of the time we are to blame for our silly errors.

Chris Papa on

Hello Mr. Shahrukh Khan and thank you or the great tutorial. I have used your codes but seems the pagination code doesn’t work. It displays only the first page. Kindly assist

Reply
Innovation Triggers on

Thanks for the code, Mr. Khan that is very helpful.

Reply
Kid Max on

Hi, how can I use password_verify() function during login?
Thank you

Reply
Shahrukh Khan on

when you get the raw password, use that function convert the password and then match the converted variable with the saved value in the database.

Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.