0

I need help where every page I give value 1 so what I want if page without value 1 cannot be access with another user

my logic like this :

<li class="treeview">
  <a href="#">
    <i class="fa fa-gears"></i> <span>User Setting</span> <i class="fa fa-angle-left pull-right"></i>
  </a>
  <ul class="treeview-menu">
    <li><a href="<?= $this->config->base_url() ?>changepassword?f=1"><i class="fa fa-circle-o"></i> Change Password</a></li>
    <li><a href="<?= $this->config->base_url() ?>infouser"><i class="fa fa-circle-o"></i> Info User</a></li>
  </ul>
</li>

if user B who don't have access want to open page changepassword.php disable because in database access they don't have value 1 but 0.

but they can open page infouser.php cause value not 1

there any one can give me logic using codeigniter where my database like this :

no | UID     | PWD               |  access |
1  | user A  | user A            |  11     |
2  | user B  | user B            |  10     |
Raunak Gupta
  • 10,412
  • 3
  • 58
  • 97
Wahyu Artadianto
  • 117
  • 1
  • 2
  • 15
  • Please edit and refine this part of your question, *where every page i give value 1 so what i want if page without value 1 cannot be access * – Seeker Feb 13 '17 at 04:26
  • Are you trying to do 'group' access (like access levels) or specific users can only access specific places and its on a user, by user or a 1:1 basis? – Brian Ramsey Feb 13 '17 at 10:53

1 Answers1

1

Well, you need to create ACL Functionality.

in which you need to create a pivot table.

id (int) 11
user_id (int) 11
controller (text)
action (text)

Database Records can be :

| 1 | 3 | users | dashboard |
| 1 | 3 | users | profile |
| 1 | 3 | users | password |

and you can make an interface to update user with their allowed controllers/actions

In this way, you can allow users to access their respective actions.

To get the permissions, you need to run the query with current user id and get controller/action from URL or getRoutes function.

Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30
  • Hi Naveed, thanks for help but what logic between column access? – Wahyu Artadianto Feb 13 '17 at 07:09
  • its mean if i have 5 pages for administrator every page i gave value 1 where in the database looks like '11111' – Wahyu Artadianto Feb 13 '17 at 07:12
  • Hi Naveed, its mean i have to add 1 column for menu so i can put dashboard, profile and password? cause i think just need explode() code to spare my column access where there '11111' its mean in array Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1 ) where every page i think i give like http://localhost/user?access=1 so for admin can access but for another user without access 1 they cannot access but i need help for logic cooding – Wahyu Artadianto Feb 13 '17 at 08:44
  • It maybe work fine but what if new page has been added and sequence will be changed ? – Naveed Ramzan Feb 13 '17 at 08:47
  • im not sure about that i just need some sample code – Wahyu Artadianto Feb 14 '17 at 02:43
  • Well, http://stackoverflow.com/questions/21206031/how-can-i-use-codeigniter-acl-library here is how ACL implementation. ACL stands for Access Control List. – Naveed Ramzan Feb 14 '17 at 04:02