note 116760 added to function.chmod
| From: | pinetree822 at nate dot com | Date: | Tue, 24 Feb 2015 04:10:27 +0000 |
| Subject: | note 116760 added to function.chmod | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201797@lists.php.net to get a copy of this message | ||
function checkPermission($userPerm,$servicePerm)
{
if( !$userPerm || !$servicePerm ) return false;
if(!preg_match("/^[0-9]+$/",(string) $userPerm) ||
!preg_match("/^[0-9]+$/",(string) $servicePerm)) return false;
if( $userPerm==$servicePerm ) return true;
$i=0;
$tempPerm=0;
do {
$tempPerm= pow(2, $i++); // permission ê° ìì ì ì¥ 1,2,4,8,16
$sumPerm += $tempPerm; // permission í©ê³ 1,3,7,25
if( $sumPerm <= $userPerm ) $arrayPerm[$tempPerm] = true; // permission ê²ì¦ê°
else break;
} while (true);
return @$arrayPerm[$servicePerm];
}
function makePlusPermission($arrayPerm=array(),$perm=0)
{
if( $arrayPerm ) {
$add=@array_shift($arrayPerm);
if(!preg_match("/^[0-9]+$/",(string)$add)) $add=0;
$perm+=$add;
return makePlusPermission($arrayPerm,$perm);
}
$retVal = ((int)$arrayPerm+(int)$perm);//PHP_INT_MAX
return ($retVal < 0 ? 0 : $retVal);
}
function makeRejectPermission($rejectPerm=array(), $perm=0)
{
if( $rejectPerm ) {
$minus=@array_shift($rejectPerm);
if(!preg_match("/^[0-9]+$/",(string)$minus)) $minus=0;
$perm-=$minus;
echo '$perm = '.$perm. ',$minus = ' .$minus. '<br/>';
return makeRejectPermission($rejectPerm,$perm);
}
$retVal = ((int)$rejectPerm+(int)$perm);//PHP_INT_MAX
return ($retVal < 0 ? 0 : $retVal);
}
// í¼ë¯¸ì
ë³ì
$writePost = 1;
$readPost = 2;
$deletePost = 4;
$addUser = 8;
$deleteUser = 16;
$perm["access"] = 1;
$perm["list"] = 2;
$perm["list_more"] = 4;
$perm["read"] = 8;
$perm["read_more"] = 16;
$perm["delete"] = 32;
$perm["delete_more"] = 64;
$perm["modify"] = 128;
$perm["modify_more"] = 256;
$perm["upload"] = 512;
$perm["upload_more"] = 1024;
$perm["down"] = 2048;
$perm["down_more"] = 4096;
$perm["write"] = 8192;
$perm["write_more"] = 16384;
$perm["find"] = 32768;
$perm["find_more"] = 65536;
// 131072,262144,524288,1048576,2097152,4194304,8388608
//ì¡°ì§ë.ê¶í <1,2,4,8,16,32,64,128,256,512>
//org_chart_user_access,org_chart_group_acces
// 그룹 í¼ë¯¸ì
ê°±ì
$administrator = makePlusPermission( array( $writePost, $readPost, $deletePost, $addUser,
$deleteUser ) );
$administrator_modify = makeRejectPermission( array( $deleteUser ),$administrator );
$moderator = makePlusPermission( array( $readPost, $deletePost, $deleteUser ) );
$writer = makePlusPermission( array( $writePost , $readPost ) );
$guest = makePlusPermission( array( $readPost ) );
if( checkPermission($administrator, $deleteUser) ) {
echo '<br/>';
echo("Login administrator - Access organization Listen Function".
'<br>');
}
if( checkPermission($administrators, $deleteUser) ) {
echo '<br/>';
echo("Login administrator - Access organization Listen Function".
'<br>');
}else {
echo '<br/>';
echo("Login administrator - Error Access organization Listen Function".
'<br>');
}
echo '$administrator = ' . $administrator. '<br>' ;
echo '$administrator_modify = ' . $administrator_modify ;
//printing
$perm = 15,
$minus = 16
Login administrator - Access organization Listen Function
Login administrator - Error Access organization Listen Function
$administrator = 31
$administrator_modify = 15
// Good luck, lock.......
----
Server IP: 72.52.91.14
Probable Submitter: 121.140.61.64
----
Manual Page -- http://php.net/manual/en/function.chmod.php
Edit -- https://master.php.net/note/edit/116760
Del: integrated -- https://master.php.net/note/delete/116760/integrated
Del: useless -- https://master.php.net/note/delete/116760/useless
Del: bad code -- https://master.php.net/note/delete/116760/bad+code
Del: spam -- https://master.php.net/note/delete/116760/spam
Del: non-english -- https://master.php.net/note/delete/116760/non-english
Del: in docs -- https://master.php.net/note/delete/116760/in+docs
Del: other reasons-- https://master.php.net/note/delete/116760
Reject -- https://master.php.net/note/reject/116760
Search -- https://master.php.net/manage/user-notes.php