php roles and permissions code example
Example 1: php permission system
<?php
require_once "Role.php";
require_once "PrivilegedUser.php";
session_start();
if (isset($_SESSION["loggedin"])) {
$u = PrivilegedUser::getByUsername($_SESSION["loggedin"]);
}
if ($u->hasPrivilege("thisPermission")) {
}
Example 2: php permission system
object(PrivilegedUser)
["roles":"PrivilegedUser":private]=>
array(1) {
["Admin"]=>
object(Role)
["permissions":protected]=>
array(4) {
["addUser"]=>bool(true)
["editUser"]=>bool(true)
["deleteUser"]=>bool(true)
["editRoles"]=>bool(true)
}
}
}
["fields":"User":private]=>
array(4) {
["user_id"]=>string(1) "2"
["username"]=>string(7) "mpsinas"
["password"]=>bool(false)
["email_addr"]=>string(0) ""
}
}