Joomla 2.5 从外部脚本获取用户数据 [英] Joomla 2.5 Get User Data from External Script

查看:16
本文介绍了Joomla 2.5 从外部脚本获取用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 Joomla 本身之外的程序中获取当前登录到 Joomla 的用户的信息.我从 1.5 升级到 2.5,之前的已经不能用了.

I need to get the information of the user that's currently logged in to Joomla from a program outside of Joomla itself. I upgraded from 1.5 to 2.5, and what I had before doesn't work anymore.

<?php

define( '_VALID_MOS', 1 );

include_once( 'globals.php' );
require_once( 'configuration.php' );
require_once( 'includes/joomla.php' );
$option="test";
$mainframe = new mosMainFrame( $database, $option, '.' );
$mainframe->initSession();

$my = $mainframe->getUser();
$joomla_name = $my->name;
$joomla_email = $my->email;
$joomla_password = $my->password;

经过一番研究,我想出了这个:

After some research, I've come up with this:

<?php
define( '_JEXEC', 1 );
define( 'JPATH_BASE', dirname(__FILE__) );
define( 'DS', '/' );

require_once ( JPATH_BASE .DS.'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' );

$my =& JFactory::getUser();
$joomla_name = $my->name;
$joomla_email = $my->email;
$joomla_password = $my->password;
$joomla_username = $my->username;

它不会产生任何错误,但似乎有效.但是,用户对象是空的.此脚本与 Joomla 安装在同一目录中.可能是什么问题?谢谢!

It doesn't produce any errors but seems to work. However, the user object is empty. This script is in the same directory as the Joomla installation. What may be the problem? Thanks!

来源:

http://www.cmsbloke.com/accessing-joomla-objects-from-an-external-script/

推荐答案

摘自http://docs.joomla.org/How_to_access_session_variables_set_by_an_external_script

解决方案:将外部脚本中的 session_start(); 替换为

Solution: Replace session_start(); in your external script with

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../..' ));
define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

请务必更改 JPATH_BASE 以适合您的目录结构.

Be sure to change JPATH_BASE to suit your directory structure.

将外部脚本中的 $_SESSION[ 'name' ] = "value"; 替换为

Replace the $_SESSION[ 'name' ] = "value"; in your external script with

$session =& JFactory::getSession();
$session->set('name', "value");
Now you can retrieve this session variable using:

$session =& JFactory::getSession();
echo $session->get('name');

这篇关于Joomla 2.5 从外部脚本获取用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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