06c01-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 37 行

PHP
37
字号
<?php// Generate access list:$access = array('aramsey', 'cdennison', 'hcline', 'rcook', 'rwhite');$admin = array('ewhite', 'eisenhamer');// The function to check access.  Pass it a username, and optionally if //  you want administrative access only:function check_access($username, $adminonly = false) {    global $access, $admin;        // First of all, if they are an admin, always return true:    if (in_array($username, $admin)) {        return true;    }        // If we are allowing non-admins and they are in the list return true    if (!($adminonly) && in_array($username, $access)) {        return true;    }        // Otherwise, they should not have access:    return false;}// Try a couple of test cases, regular access - both are trueecho "<p>'rwhite' ",    check_access('rwhite') ? 'is' : 'is NOT' ," allowed.</p>";echo "<p>'eisenhamer' ",     check_access('eisenhamer') ? 'is' : 'is NOT' ," allowed.</p>";// Now for administrative, eisenhamer does, but rwhite does not.echo "<p>'rwhite' ",     check_access('rwhite', true) ? 'is' : 'is NOT' ," an admin.</p>";echo "<p>'eisenhamer' ",     check_access('eisenhamer', true) ? 'is' : 'is NOT' ," an admin.</p>";?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?