我想创建一个脚本,将用户登录到Joomla,并且在http://api.joomla.org/Joomla-Platform/User/JAuthentication.html
上没有关于如何执行此操作的任何官方文档答案 0 :(得分:0)
我遇到类似的问题,要求我从外部自定义HTML表单登录Joomla 2.5网站。我是这个问题的佼佼者,但是我发现了一个非常有用的脚本,因为它的工作方式与我需要的方式一致(this网站的所有学分)。
我不使用JAuthentication类,而是使用JFactory :: getApplication对象及其登录方法对Joomla进行身份验证:
<?
if(isset($_POST['Submit'])){
define('_JEXEC', 1 );
define('DS', DIRECTORY_SEPARATOR);
define('JPATH_BASE', dirname(__FILE__));
require_once (JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once (JPATH_BASE .DS.'includes'.DS.'framework.php' );
$app =& JFactory::getApplication('site');
$app->initialise();
//echo "<br>";print_r($app);
$credentials = array();
$credentials['username'] = $_POST['username'];
$credentials['password'] = $_POST['password'];
//echo "<br>Login res: ".$app->login($credentials);
if($app->login($credentials) == 1)
header('location: http://www.johnabril.com/seguro_desmp');
}
?>
正如您所看到的,您只需从HTML表单中发送用户名和密码字符串即可。
希望它有所帮助。