加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:41:03 所属栏目:PHP教程 来源:网络整理
导读:我们的网站上有一个独立的脚本,与Joomla 1.5安装相邻.我们使用Joomla身份验证来限制对脚本的访问.此时,我们将任何未经授权的用户重定向到Joomla站点以进行登录.但我们希望在我们的脚本中添加登录功能.有谁知道如何使用用户名/密码从外部脚本登录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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读