为用户分配权限PHP

时间:2014-03-12 08:55:27

标签: php

我有一个表格,显示包括adminseo在内的所有用户,我想限制用户的权限只能看到其他用户(而且看不到管理员或seo) 。以下是用户列表:

Array
(
    [0] => Array
        (
            [uid] => 1
            [rid] => admin
            [first_name] => Admin
            [last_name] => Admin
            [email] => admin@admin.com
            [password] => b2be38504e4c8dedffab96534ff3df93
            [date_register] => 2014-02-18 08:27:28
            [last_connexion] => 2014-03-11 18:18:54
            [enable] => 1
        )

    [1] => Array
        (
            [uid] => 2
            [rid] => seo
            [first_name] => SEO
            [last_name] => SEO
            [email] => seo@SEO.com
            [password] => 74709b45674cab2d2e9928578237a3c4
            [date_register] => 2014-02-18 08:27:28
            [last_connexion] => 0000-00-00 00:00:00
            [enable] => 1
        )

    [2] => Array
    (
        [uid] => 3
        [rid] => user
        [first_name] => Test    
        [last_name] => Test
        [email] => test@yahoo.com
        [password] => 2b2809a2b67df0e17d44de3b0d33e880
        [date_register] => 2014-02-18 08:27:51
        [last_connexion] => 0000-00-00 00:00:00
        [enable] => 1
    )

这是我的代码:

foreach ($users as $key => $value){
if (user('rid') != 'seo' && user('rid') != 'admin') { 
    unset($users[$key]['seo']);
    unset($users[$key]['admin']);
}
}

希望你理解我的意思。我的代码中有错误吗?

由于

1 个答案:

答案 0 :(得分:1)

试试这个,您需要在==条件中使用=代替if

&& $value['email']== $email

而不是

&& $users[$key]['email']= $email