我在myjoomla / myscript /
文件夹中有这个代码<?php
define('_JEXEC', 1 );
define('JPATH_BASE', $_SERVER['DOCUMENT_ROOT']."" );
define( 'DS','/' );
require_once ( JPATH_BASE.DS. 'includes'.DS.'defines.php' );
require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php' );
require(JPATH_BASE.DS.'libraries/joomla/factory.php');
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
jimport( 'joomla.session.session' );
$session =& JFactory::getSession();
$user =& JFactory::getUser();
echo "id:".$user->id;
我打印JPATH_BASE就可以了。但没有打印ID,只打印&#34; 0&#34;。我在joomla登录好了。这在localhost中是正常的,但在服务器中没有问题。
由于
答案 0 :(得分:1)
<?php
if (!defined('_JEXEC'))
{
// Initialize Joomla framework
define('_JEXEC', 1);
}
// Load system defines
if (file_exists(dirname(__FILE__) . '/defines.php'))
{
require_once dirname(__FILE__) . '/defines.php';
}
if (!defined('JPATH_BASE'))
{
define('JPATH_BASE', dirname(__FILE__));
}
if (!defined('_JDEFINES'))
{
require_once JPATH_BASE . '/includes/defines.php';
}
// Get the framework.
require_once JPATH_BASE . '/includes/framework.php';
$app = JFactory::getApplication('site');
$app->initialise();
$user = JFactory::getUser();
echo "id:".$user->id;
注意:在本地和现场测试您的代码它对我有用。但不确定为什么它在您的实时环境中不起作用。但是你的代码确实很旧。