我想将登录的用户名插入到一个变量中,以便在我的Joomla灌输的根目录中的页面中使用,并通过wrapper/iFrame显示。
在主页中设置cookie不起作用,在下面的代码后面使用$user =& JFactory::getUser();访问用户对象的推荐方式也不起作用(链接如下)。有什么想法吗?
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE',$_SERVER['DOCUMENT_ROOT'].DS. basename(dirname(__DIR__)) );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
//optional use depend on requirement
jimport( 'joomla.user.user');
jimport( 'joomla.session.session');
jimport( 'joomla.user.authentication');发布于 2015-07-05 20:09:48
使用该代码,您将创建并初始化一个新的Joomla应用程序,因此您没有任何“当前”用户。您必须通过代码执行登录,这是可以做到的,但不幸的是,需要纯文本用户和密码。
$login_result = $mainframe->login(array(
'username' => $username,
'password' => $password
));
if (!$login_result)
{
throw new \Exception("Unable to set current user!", 401);
}在此之后,新的Joomla应用程序将有一个当前用户,您可以执行通常的JFactory::getUser()
如果你没有用户名和密码(我希望如此),你有两个选择:
的情况下进行身份验证
发布于 2015-07-08 17:36:03
谢谢你们的帮助。Elin提出的解决方案是将用户名放在url中。要做到这一点,它涉及到Joomla核心的黑客攻击,因为模板覆盖似乎不适用于此文件。
查找此文件
components\com_wrapper\views\wrapper\tmpl\default.php
//Insert line below line after this
defined('_JEXEC') or die;
$user = JFactory::getUser();在44号线附近
//change
src="<?php echo $this->escape($this->wrapper->url);
//to this
src="<?php echo $this->escape($this->wrapper->url). "?userId=" . $user->id; ?>"
//then in the file in the iframe
$userid2 = $_GET["userId"];
//or if you want to store the user name in a session variable
$userid3 = $_SESSION['userId'];https://stackoverflow.com/questions/31229936
复制相似问题