PHP code example of qifen / casbin

1. Go to this page and download the library: Download qifen/casbin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

qifen / casbin example snippets


use Qifen\Casbin\Permission;

// adds permissions to a user
Permission::addPermissionForUser('eve', 'articles', 'read');
// adds a role for a user.
Permission::addRoleForUser('eve', 'writer');
// adds permissions to a rule
Permission::addPolicy('writer', 'articles','edit');

if (Permission::enforce("eve", "articles", "edit")) {
    echo '恭喜你!通过权限认证';
} else {
    echo '对不起,您没有该资源访问权限';
}

php start.php restart

php start.php restart -d