php – 如何通过外部脚本登录joomla?

前端之家收集整理的这篇文章主要介绍了php – 如何通过外部脚本登录joomla?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们的网站上有一个独立的脚本,与Joomla 1.5安装相邻.我们使用Joomla身份验证来限制对脚本的访问.此时,我们将任何未经授权的用户重定向到Joomla站点以进行登录.但我们希望在我们的脚本中添加登录功能.有谁知道如何使用用户名/密码从外部脚本登录joomla?谢谢!
<?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','passwd');

//perform the login action
$error = $mainframe->login($credentials);
$user = JFactory::getUser();
//now you are logged in

$mainframe->logout();
//now you are logged out
原文链接:https://www.f2er.com/php/138295.html

猜你在找的PHP相关文章