我需要从 Joomla 本身之外的程序获取当前登录到 Joomla 的用户的信息。我从1.5升级到2.5,之前的功能不再起作用了。
<?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;
经过一些研究,我想出了这个:
<?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 安装位于同一目录中。可能是什么问题?谢谢!
Sources:
http://www.cmsbloke.com/accessing-joomla-objects-from-an-external-script/ 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 http://docs.joomla.org/How_to_access_session_variables_set_by_an_external_script
解决方案:更换session_start();
在你的外部脚本中
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
以适合您的目录结构。
更换$_SESSION[ 'name' ] = "value";
在你的外部脚本中
$session =& JFactory::getSession();
$session->set('name', "value");
Now you can retrieve this session variable using:
$session =& JFactory::getSession();
echo $session->get('name');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)