【发布时间】:2008-12-17 16:05:40
【问题描述】:
目标是将当前工作目录拆分为/clients/,看看用户是否在
[某事]/clients/[他们的用户名]/[某事]
例如,目标是输入:
cwd = "/volumes/raid0/www/clients/mikey/test_folder/"
$session->username = "mikey"
返回
$authorized = true
我希望它能够识别 UNIX 和 Windows 路径,因此它应该查找“/”或“\”。假定文件名不包含这些字符。
另外,isAdmin() 位应该允许管理员访问所有目录。
现在,PHP 说:
警告:意外的正则表达式错误 (8) c:\apache\htdocs\clients\mikey\index.php 在第 69 行
这里是代码。 (第 69 行在 cmets 中注明。)
if($session->isAdmin())
{
$authorized = true;
}
else
{
// split cwd at the first instance of /clients/
$dir = spliti('%(\/|\\)clients(\/|\\)%',getcwd(),2); //this is line 69
if(count($dir) == 2) // if /clients/ was in cwd
{
// check if the second piece of cwd starts with the username.
$authorized = (preg_match('/^'.$session->username.'//*.$/', $dir[1]));
}
else
$authorized = false;
}
【问题讨论】: