모듈을 검사하여 사용자가 해당 페이지를 볼 수있는 권한이 있는지 확인하는 사용자 클래스에 CheckModulePermission 함수를 만들었습니다. 함수는 다음과 같습니다.모듈 사용 권한 클래스 오류
public function CheckModulePermissions($moduleId) {
if(isset($_SESSION['userId'])) {
// If the user is admin, allow regardless
if($this->IsAdmin()) {
return true;
}
$sql = "SELECT `userModuleId`
FROM `userModules`
WHERE `userId` = " . $_SESSION['userId'] . "
AND `moduleId` = " . $moduleId . ";";
mysql_select_db(DB_USER_DATABASE_NAME, $this->conn);
$result = mysql_query($sql, $this->conn);
$x = mysql_fetch_row($result);
if($x[0] == 1) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}
이 방법은 실패한 페이지 하나를 제외한 모든 페이지에서 정상적으로 작동합니다. 드롭 다운 상자와 사용자 권한에 따라 업데이트 될 텍스트 상자가 있습니다. 사용 권한이있는 사용자로 로그온했지만 드롭 다운 상자가 나타나지 않습니다.
if(isset($_GET['orderNumber'])) {
// If post is set then update the prima reference and order status
// Only if user has sufficient privileges
if(isset($_POST['orderStatus'])) {
if($user->CheckModulePermissions(11)) {
$cid->UpdateOrderStatus($_GET['orderNumber'], $_POST['orderStatus']);
$cid->UpdateOrderReference($_GET['orderNumber'], $_POST['PReference']);
}
}
if($user->CheckModulePermissions(11)) {
$content .= "<select name='orderStatus'>
<option value='1'";
if($orderDetails['status'] == 1) $content .= " selected='selected'";
$content .= ">Incomplete</option>
<option value='2'";
if($orderDetails['status'] == 2) $content .= " selected='selected'";
$content .= ">Submitted</option>
<option value='3'";
if($orderDetails['status'] == 3) $content .= " selected='selected'";
$content .= ">Processed</option>
</select>";
} else {
if($orderDetails['status'] == 1) $content .= "Incomplete";
if($orderDetails['status'] == 2) $content .= "Submitted";
if($orderDetails['status'] == 3) $content .= "Processed";
}
$content .= "</td>
</tr>
<tr>
<th>Prima Order Number</th>
<td>";
if($user->CheckModulePermissions(11)) {
$content .= "<input type='text' name='pReference' value='" . $orderDetails['PReference'] . "' /></td>
</tr>
<tr>
<td colspan='2'><input type='submit' /></td>
</tr>";
} else {
$content .= $orderDetails['PrimaReference'] . "</td></tr>";
}
$content .= "</table>
</form>
</td>
오류가 발생한 드롭 다운 상자의 논리입니까? 여기
감사합니다. 그렇습니다. 권한이 있다는 사실에도 불구하고 관리자로부터 떨어져있는 모든 사용자에 대해 false를 반환하는 것은 제 기능입니다. –
첫 번째 검사 (즉, $ _SESSION [ 'userId']'가 설정되지 않음) 또는 끝에있는 것인가 ('$ x [0] = = 1 '). if (! isset ($ _ SESSION [ 'userId']))가 -1을 반환하고 이전처럼'var_dump'를 호출하면, if (! isset ($ _ SESSION [ 'userId']) '$ _SESSION'에 문제가 있거나 DB 쿼리에 문제가 있는지 알 수 있습니다. 'session_start()'를 호출하는 것을 잊는 것만 큼 간단 할까? – DaveRandom