Checking user access to resource from external script - Joomla! Forum - community, help and support
i hope helps trying this. took me while digging around in forums , docs figure out.
the code gets current user (which returns guest user not logged in) , checks whether have access article id 12. couldn't figure out how compute access level without grabbing something. maybe else can that.
if there better way this, please chime in.
cheers!
the code gets current user (which returns guest user not logged in) , checks whether have access article id 12. couldn't figure out how compute access level without grabbing something. maybe else can that.
code: select all
define( '_jexec', 1 );
define('jpath_base', $_server['document_root']);
define( 'ds', directory_separator );
require_once ( jpath_base .ds.'includes'.ds.'defines.php' );
require_once ( jpath_base .ds.'includes'.ds.'framework.php' );
require_once ( jpath_base.ds.'libraries'.ds.'joomla'.ds.'environment'.ds.'request.php');
jimport('joomla.application.component.helper');
//$app = jfactory::getapplication('site');
//$app->initialise();
$user = jfactory::getuser();
$groups = $user->getauthorisedviewlevels();
$article =& jtable::getinstance("content");
$article->load(12);
$cacclevel = $article->get("access");
$allowed = in_array($cacclevel, $groups);
if (!$allowed)
{
header("location: http://" . $_server['http_host']);
exit(0);
}
if there better way this, please chime in.
cheers!
Comments
Post a Comment