我使用了以下代码中的代码:https://stackoverflow.com/a/2288181/4819200
<?php
//http://domain.com/script/script.php?username=username&passwd=password
define( '_JEXEC', 1 );
define('JPATH_BASE', '../' );
define( 'DS', DIRECTORY_SEPARATOR );
require_once('../configuration.php');
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' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');
$credentials = array();
$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
$credentials['password'] = JRequest::getVar('passwd', '', 'method', 'passwd');
//perform the login action
$error = $mainframe->login($credentials);
$user = JFactory::getUser();
//now you are logged in
$mainframe->logout();
//now you are logged out
现在,问题
它在Joomla 2.3版本中工作,它在3.4版本中停止工作。 现在,它不会从 $ mainframe =&amp;行返回JFactory :: getApplication( '位点');
您可以为我推荐最新版本的代码。
注意: 我不是joomla家伙。但是,我已经开发了一些PHP框架。
答案 0 :(得分:1)
在Joomla 3中,您可以使用此代码从Joomla外部获取用户对象
<?php
//http://domain.com/script/script.php?username=username&passwd=password
$dir = '/var/www/joomla'; // path to your joomla installation directory
define( '_JEXEC', 1 );
define( 'JPATH_BASE', $dir);
define( 'DS', '/' );
require_once ( JPATH_BASE .DS . 'configuration.php' );
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' );
//Then you can call the classes this way
$mainframe = JFactory::getApplication('site');
/* Create the Application */
//$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');
$credentials = array();
$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
$credentials['password'] = JRequest::getVar('passwd', '', 'method', 'passwd');
//perform the login action
$error = $mainframe->login($credentials);
$user = JFactory::getUser();
//now you are logged in
$mainframe->logout();
答案 1 :(得分:0)
$code = NULL;
$plugin_param->params = new JRegistry($plugin_param->params);
$is_valid = $plugin->checkAnswer($code);