/ ************************** * Author: old Youth * email: wnadmin@sina.com * from: http: // blog. 9cbs.net/hahawen * reproduced please retain this information, thank you ************************* /
In the evening, I asked me about the issue of permission judgment on the website page. So this article has this article.
In fact, this is a lot of ways to achieve. 1. Permissions can be permissions can be performed separately in each page. This is the most general method. 2, you can make a configuration file for each final page file, used to perform permission determination, when the user accesses this page, it is judged by a function, whether this file exists. If there is, it is determined according to the content of the file. If there is no existence, it is not necessary to perform permission judgment. 3. It is a unified judgment to make a single function, and the permissions are permissions through a certain configuration.
An example of the following is the third method, which is suitable for any case and is relatively universal. Step 1 The correspondence between the access path "and" Permissions Verification Functions ", press 1: 1 to a configuration file or an array, such as the $ FILTER array step four in the filter.php below, make a verification function, parsing the current access Path, permission judgment.
Brief description, filter.php is a file used to verify information. Authorization () is a core scheduling function. Please note that the instructions inside the function, Application.php is an ordinary page file. There is no specific implementation in the examples, add yourself.
File 1, Filter.php
PHP
$ FILTER = Array ('/ admin' => 'adminlogin', '/ admin / usradmin' => 'PowerAdminLogin', '/ myshop' => 'userlogin');
Function adminlogin () {// returno is administrator? '?' success': 'false';
Function PowerAdminLogin () {// RETURN 'is a super administrator'? 'Success': 'false';
Function UserLogin () {// RETURN 'is a member?'? 'Success': 'false';}
Function Authorization () {global $ file; // Remove and parse the currently accessed URL path, determine if there is a path that is currently filtered by the $ FILTER
//, for example, the current access path is http://www.hahawen.com/admin/Useradmin/gogo.php // Remove / Admin / UseRadmin / GOGO to determine if this path contains this path. // If you don't have this path in the $ FILTER, if you have this path // If you return $ FILTER, this path (/ admin / useradmin) corresponds to the value, // In fact this $ value Is a function name, // This function is used to determine whether the current user, whether the current access path, access to the function // through the $ value () method, returns "success" or "failed" / / If you fail, you will reallite to the error page, or you can perform the corresponding process // if successful in the $ value () function, return true //, for example, the current access path is http://www.hahawen.com/news/ HAPPY / LIST.PHP / / Remove / News / Happy / List Judgment $ FILTER contains this path. // If you don't take out / news / happy judgment $ FILTER is included // If you don't have this path in Filter, if you haven't, if you haven't, you said that this page is not allowed to permissions verification. / / Return true}
?>
Document 2, Application.php
Require_once "filter.php"; authorization (); // Other operations. ?>