Joomla:如何检查管理员是否登录
Joomla: How to check if admin is logged in
我添加了一个不使用任何 Joomla 组件的自定义 PHP 页面。
我在 .htaccess 中进行了更改,因此该页面现在可以访问了。
link 会像 http://www.example.com/administrator/mypage.php
但是每个人都可以在不登录管理面板的情况下访问该页面。
我怎样才能让它只能由管理员查看?
我的 Joomla 版本是 3.
非常感谢。
首先,您的 php 页面必须包含 joomla 框架,否则您将无法使用任何 joomla 功能。
我通常在 php 文件的开头使用这段代码(php 文件在根目录中):
define( '_JEXEC', 1 );
define('JPATH_BASE', './' ); //config this as you need
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : null;
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
JPluginHelper::importPlugin('system');
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;
$mainframe->triggerEvent('onAfterInitialise');
// Get user
$user = JFactory::getUser();
if ($user->authorise('core.admin')) {
//your code here
}
请记住,这不是正确的解决方案,您应该为 joomla 创建一个组件来扩展它。自定义 php 页面可能会产生安全问题。
希望对您有所帮助,
马可
我添加了一个不使用任何 Joomla 组件的自定义 PHP 页面。 我在 .htaccess 中进行了更改,因此该页面现在可以访问了。
link 会像 http://www.example.com/administrator/mypage.php
但是每个人都可以在不登录管理面板的情况下访问该页面。 我怎样才能让它只能由管理员查看?
我的 Joomla 版本是 3.
非常感谢。
首先,您的 php 页面必须包含 joomla 框架,否则您将无法使用任何 joomla 功能。
我通常在 php 文件的开头使用这段代码(php 文件在根目录中):
define( '_JEXEC', 1 );
define('JPATH_BASE', './' ); //config this as you need
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : null;
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
JPluginHelper::importPlugin('system');
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;
$mainframe->triggerEvent('onAfterInitialise');
// Get user
$user = JFactory::getUser();
if ($user->authorise('core.admin')) {
//your code here
}
请记住,这不是正确的解决方案,您应该为 joomla 创建一个组件来扩展它。自定义 php 页面可能会产生安全问题。
希望对您有所帮助, 马可