我有一个PHP网站有多个PHP脚本。我需要从另一个站点向我的系统提供有限的访问权限。我想限制这些ppl可以访问的页面。限制访问限制访问用户的PHP脚本
我以下列方式这样做:
// $_SESSION['systemid'] is set with a value of say, '1'
$permissionArray = $objACCESS->getPermissions($_SESSION['systemid']);
// getPermissions returns an array like the following (for that systemid):
// 0 => {'systemid' => '1', 'permission_type' => 'createcontent' }
// 1 => {'systemid' => '1', 'permission_type' => 'invitecontacts' }
// the following contain a list of script names that should be
// restricted if permission is not allowed
$createcontent = array('createcontent.php');
$managecontent = array('managecontent.php');
$invitecontacts = array('invitecontacts.php');
$page_name=basename($_SERVER["SCRIPT_FILENAME"]);
if(is_array($permissionarray))
{
$haspermissions = false;
foreach($permissionarray as $permissions)
{
if(in_array($page_name,${"$permissions[permission_type]"}))
{
$haspermissions = true;
break;
}
}
}
if($haspermissions==false)
{
// - do not have permissions
echo "<meta http-equiv=\"refresh\" content=\"0;url=".$site_url."404.php\">";
die;
}
...
// rest of the code
...
Q1:是否有限制用户的访问更好的办法? Q2:如果不是,有没有办法让这种方法更有效率/最优?
+1很好的清晰问题。请注意,但看起来类似于:http://stackoverflow.com/questions/1392428/restricting-access-to-a-site-using-ip-address – Smandoli 2011-04-02 18:05:39
“我需要提供来自其他网站的用户有限访问”这不是明确? “另一个网站”下的含义是什么?反正+1! – Wh1T3h4Ck5 2011-04-02 18:11:32
感谢您的评论smandoli - 但我正在寻求限制这个“外部系统”用户在我的网站上游荡 - 这种限制是基于他来自哪个系统,而不是他的IP地址/地理位置 – siliconpi 2011-04-02 18:12:14