问题描述
我在用户通过Windows身份验证登录,然后存储在一个会话变量,用户的权限。我使用的权利存储分隔的方法在一个数据库即:
I am logging in users via windows authentication and then storing that user's rights in a session variable. I use a delimited method of rights storage in a database i.e:
$rights //retrieved from database
= 'read,edit,delete,admin'
所以我的问题是我应该;
so my question is should I;
//generate variable
$_SESSION['userrights'] = $rights ($rights is retrieved from database)
//use strpos to find if right is allowed
if (strpos($_SESSION['userrights'],"admin") !== false) { // do the function }
或
//make array of rights
$_SESSION['userrights'] = explode(',',$rights)
//use in_array to find if right is allowed
if (in_array("admin",$_SESSION['userrights'])) { // do the function }
我presume的差异将是pretty我在做什么太多可以忽略不计,但是这将是更快(使用更少的资源)方法的OCD问题位?
Bit of a OCD question as I presume the difference will be pretty much negligible for what I am doing but which would be the faster (use less resources) method?
任何答案AP preciated除了那些侮辱我的权利存储方法!
Any answers appreciated except ones that insult my method of rights storage!
推荐答案
strpos是搜索文本针的最快方法,php.net网站:
strpos is the fastest way to search a text needle, php.net site:
If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function strpos()....
这篇关于in_array VS strpos在PHP中的表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!