PHP用户帐户系统


Am new to php and trying my hands on a php login system from this page But am bit confuse about a piece of code.

Code snippet presented below.

<?php

class UserPermissions {

    const READ_POSTS = 1;
    const POST_NEW_THREADS = 2;
    const POST_NEW_REPLIES = 4;
    const EDIT_OWN_POSTS = 8;
    const EDIT_OTHERS_POSTS = 16;
    const DELETE_OWN_POSTS = 32;
    const DELETE_OTHERS_POSTS = 64;
    const MOVE_THREADS = 128;
    const SPLIT_THREADS = 256;
    const MERGE_THREADS = 512;
    const BAN_USERS = 1024;
    const WARN_USERS = 2048;
    const ACCESS_ADMIN_PANEL = 4096;
    // And so on and so on
    
    protected $perms;
    
    function __construct($permissions) {
        $this->perms = $permissions;
    }
    
    function hasPermission($perm) {
        return ($this->perms & $perm) === $perm;
    }
}

?>

The main focus is the hasPermision function and how the return value is calculated.

</div>

PHP.net will be your best friend. Here's their explanation to your question about comparators: http://php.net/manual/en/language.operators.comparison.php

Basically, $perm must be equal but also of the same type.

Here's the link to the bitwise doc: http://php.net/manual/en/language.operators.bitwise.php