3 Replies - 353 Views - Last Post: 29 March 2013 - 11:23 PM Rate Topic: -----

#1 James1992  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 130
  • Joined: 30-October 12

How to give users with certain levels other options in PHP?

Posted 28 March 2013 - 07:56 AM

Hopefully I'll be able to explain my situation better than my title!

I currently have a table (member) in phpmyadmin. This table contains all information about users such as their names, mobile numbers and email address. This table also has an attribute 'level'. Normal users will have a level 0 whereas admins will have level 1.

In dreamweaver I have login screen that requires the user to put their username and password in. It goes through the typical checking procedure to make sure the inputs are valid. Once they successfully login, they are presented with an option to update their records. I want admins to not only be able to update their records but also to update other peoples as well as delete records.

Is their a way to filter users and offer additional features?

Any advice, tips, or solutions is very much appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: How to give users with certain levels other options in PHP?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8952
  • View blog
  • Posts: 33,555
  • Joined: 12-June 08

Re: How to give users with certain levels other options in PHP?

Posted 28 March 2013 - 07:59 AM

Sure.. when rendering in php page you can load the current viewer's level or group. If they are of sufficient privilege then add the html to that gives them the ability to delete a member, or load up another profile to edit.

Basic dynamic shenanigans.
Was This Post Helpful? 1
  • +
  • -

#3 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,829
  • Joined: 30-April 10

Re: How to give users with certain levels other options in PHP?

Posted 28 March 2013 - 11:09 AM

My suggestion is to write out some pseudo code so you understand what the flow of the script needs to be.
Was This Post Helpful? 0
  • +
  • -

#4 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 160
  • Joined: 07-October 12

Re: How to give users with certain levels other options in PHP?

Posted 29 March 2013 - 11:23 PM

Of Course you don't have to follow my format to the T, but Here I have a login mixed with that you're trying to do. When the user logs in it's going to assign the permissions from the database to the users session. So say you're an admin it's going to set 1 to your session permissions.
function VerifyLoginIn($username,$password)
    {
   
        if(!$this->DBLogin())
        {
            $this->HandleError("Database login failed!");
            return false;
        }          
        $username = $this->SanitizeForSQL($username);
        $pwdmd5 = md5($password);
        $qry = "Select * from $this->tablename where username='$username' and password='$pwdmd5'";
        
        $result = mysql_query($qry,$this->connection);
        
        if(!$result || mysql_num_rows($result) <= 0)
        {
            $this->HandleError("Error logging in. The username or password does not match");
            return false;
        }
        
        $row = mysql_fetch_assoc($result);

$_SESSION['perms'] = $row['permissions'];
$_SESSION['id'] = $row['id_user'];

  return true;
    }



 function UserPermissions()
    {
    	return isset($_SESSION['perms'])?$_SESSION['perms']:'';
    }


After this has been done you can call it inside your website using your function call, so say we have a page for updating records.
<?php
if($YourFunctionCall->UserPermissions()<1){
print "Sorry, but you don't have the appropriate permissions to access this page.";
} else {
print "Your Admin's site functions and Stuff goes here."
}
?>


Personally when I'm doing a page that has different permissions like that I set it up a little differently. IE.
/var/www/admin_path would be where I held my panels for the admin pages.
and then I'd have.
/var/www/user_path would be your typical user.
Now I would have
<?php
if($YourFunctionCall->UserPermissions()<1){
include_once('admin_path/edit_user.php');
} else {
include_once('user_path/edit_user.php');
}
?>


This way I can edit each one accordingly and then main page in the root isn't cluttered with if else statements and multitudes of divs and functions according to who's logged in. the functions are organized in their old folders instead. Hope that what I'm saying is making sense and if you need a hand feel free to let me know and I'll help the best I can. Good luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1