如何在joomla 3.9中访问用户对象 [英] How to access user object in joomla 3.9

查看:90
本文介绍了如何在joomla 3.9中访问用户对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在joomla站点的iframe中获取用户ID(使用虚拟主机)。我在win 10 pro(64位)下使用Joomla 3.9.3和wamp 3.17。我的网站位于www。

下的文件夹'clib'中如许多论坛所示,我使用iframe的php文件以下面的代码开头:

````

I want to get the user id in an iframe in a joomla site (using virtual hosts). I'm using Joomla 3.9.3 with wamp 3.17 under win 10 pro (64 bit). my site resides in folder 'clib' under www.
As given in many forums, my php file using the iframe begins with the following code:
````

<?php

define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ] );

require_once( JPATH_BASE . '/clib/includes/defines.php' );
require_once( JPATH_BASE . '/clib/includes/framework.php' );
require_once( JPATH_BASE . '/clib/libraries/joomla/factory.php' );
$mf1 = JFactory::getApplication('site');

$user = JFactory::getUser();
$uname=$user->name;
$uid=$user->id;


?>



````



这在从localhost机器访问站点时有效,但在从LAN访问时则无效。我需要的只是用户ID。



我尝试过:



当网站在根文件夹中使用wamp 2.4 on win 8.2和joomla 3.4.0之后,这工作更早。更新计算机以赢得10个专业版,wamp 3.1.7& joomla 3.9.4,相同的代码不再起作用。我已经尝试更改为'define.php','framework.php'和& 'factory.php'无济于事。


````

This works when accessing the site from localhost machine, but not when accessing from lan. All I need is the userid.

What I have tried:

This was working earlier when the site was in root folder using wamp 2.4 on win 8.2 and joomla 3.4.0 After updating the computer to win 10 pro, wamp 3.1.7 & joomla 3.9.4, same code doesn't work any longer. I've tried changing the path specified for 'defines.php', 'framework.php' & 'factory.php' to no avail.

推荐答案

_SERVER ['DOCUMENT_ROOT']);

require_once(JPATH_BASE。'/ clib /includes/defines.php');
require_once(JPATH_BASE。'/ clib /includes / framework.php');
require_once(JPATH_BASE。'/ clib / library / joomla / high.php');
_SERVER[ 'DOCUMENT_ROOT' ] ); require_once( JPATH_BASE . '/clib/includes/defines.php' ); require_once( JPATH_BASE . '/clib/includes/framework.php' ); require_once( JPATH_BASE . '/clib/libraries/joomla/factory.php' );


mf1 = JFactory :: getApplication('site');
mf1 = JFactory::getApplication('site');


user = JFactory :: getUser();
user = JFactory::getUser();


这篇关于如何在joomla 3.9中访问用户对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆