dongluan1743 2015-10-27 22:44
浏览 51

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>
  • 写回答

1条回答 默认 最新

  • douzi2333 2015-10-27 22:47
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法