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