0

我有一个脚本检查用户是否是(超级)管理员,然后授予对该页面的访问权限。

它工作了几年,但现在它停止工作了。我收到不正确的响应文本错误消息。当我注释掉脚本时,一切正常。

这是代码:

    <?php

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );


/* Create the Application */
$mainframe =& JFactory::getApplication('site');
$user = JFactory::getUser();
$userGroups = $user->getAuthorisedGroups();

if(in_array(7,$userGroups) or in_array(8,$userGroups)){

}else{

   header( 'Location: /beheer-niet-toegestaan.html' ) ;

}
?>

我不知所措。希望可以有人帮帮我。

// 编辑 //

嗯,对不起,不完整的问题。经过一个多小时在线尝试各种代码示例后,我通过将其编辑为:

    <?php

define( '_JEXEC', 1 ); 
define( '_VALID_MOS', 1 ); 
define( 'JPATH_BASE', realpath(dirname(__FILE__))); 
define( 'DS', DIRECTORY_SEPARATOR ); 
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); 
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); 
$mainframe =& JFactory::getApplication('site'); 
$mainframe->initialise(); 

$user = JFactory::getUser();

$isAdmin = $user->get('isRoot');

if ($isAdmin == false) {    
   header( 'Location: /beheer-niet-toegestaan.html' ) ;
}
?>
4

0 回答 0