PHP code example of wenhainan / thinkphp6-auth

1. Go to this page and download the library: Download wenhainan/thinkphp6-auth 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/ */

    

wenhainan / thinkphp6-auth example snippets



use think\Controller;
use think\wenhainan\Auth;
class Base extends Controller
{
    public function _initialize()
	{
		$controller = request()->controller();
		$action = request()->action();
		$auth = new Auth();
		if(!$auth->check($controller . '-' . $action, session('uid'))){
			$this->error('你没有权限访问');
		}
    }
 }

$auth->check('rule1,rule2',uid);