[英]Check user logged in Joomla 2.5 from external script (reiterated)
I'm well familiar with coding in PHP and other languages, but I'm totally unfamiliar with Joomla. 我对用PHP和其他语言进行编码非常熟悉,但是我完全不熟悉Joomla。
What I want to accomplish is to know when a user has logged in on the Joomla site (under /web) and differentiate this script's behaviour accordingly. 我要完成的工作是知道用户何时登录Joomla站点(在/ web下),并相应地区分此脚本的行为。
I have a Joomla 2.5 site under /web/ and I have a script under /web/test/index.php, where the following code lies ( collected from other replies in here and elsewhere): 我在/ web /下有一个Joomla 2.5站点,在/web/test/index.php下有一个脚本,其中包含以下代码( 从此处和其他位置的其他答复中收集 ):
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
echo dirname(dirname(__FILE__)) . "\n";
if (file_exists(dirname(dirname(__FILE__)) . '/defines.php'))
include_once dirname(dirname(__FILE__)) . '/defines.php';
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(dirname(__FILE__)));
require_once JPATH_BASE.'/includes/defines.php';
}
require_once JPATH_BASE.'/includes/framework.php';
$app = JFactory::getApplication('site');
$app->initialise();
print_r(JFactory::getUser());
What I get back is 我得到的是
/web
JUser Object
(
[isRoot:protected] =>
[id] => 0
[name] =>
...
Thank you, 谢谢,
Use this code it's working: 使用此代码可以正常工作:
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/' ));
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 . 'factory.php' );
$mainframe = JFactory::getApplication('site');
var_dump(JFactory::getUser());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.