phpot roles php code example
Example 1: php permission system
public function hasRole($role_name) {
return isset($this->roles[$role_name]);
}
public static function insertPerm($role_id, $perm_id) {
$sql = "INSERT INTO role_perm (role_id, perm_id) VALUES (:role_id, :perm_id)";
$sth = $GLOBALS["DB"]->prepare($sql);
return $sth->execute(array(":role_id" => $role_id, ":perm_id" => $perm_id));
}
public static function deletePerms() {
$sql = "TRUNCATE role_perm";
$sth = $GLOBALS["DB"]->prepare($sql);
return $sth->execute();
}
Example 2: 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")) {
}