0

I have a script that checks if user is (super)admin and then grants access to that page.

It worked for couple years but now it stopped working. I'm getting a incorrect response text error message. When I comment out the script the thing works fine.

Here is the code:

    <?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' ) ;

}
?>

I'm at a loss. Hope someone can help me.

// EDIT //

Hmm sorry for the incomplete question. After over an hour trying various code samples online i solved it by editing it to:

    <?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' ) ;
}
?>
  • 1
    What is the version of Joomla where this script worked ? What is the error message exactly ? Did you made researchs ? Please edit and complete your question. – Michel Oct 10 '15 at 18:26
  • This is really incomplete. In providing needed information you should `var_dump` the $user and $userGroups variables. My sense is that you probably are not getting anything. That code looks like something from 1.5, e.g. why would you hardcode the groupids rather than just ask if the user has global admin? – Elin Oct 11 '15 at 18:52

0 Answers0