我有一個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