我有一个joomla网站,在根文件夹中有一个PHP文件,它可以完美地获取当前登录的用户。
我有另一个文件夹"文件",其中包含其他HTML &PHP文件。我需要kfetch当前登录的用户与这些其他HTML文件的工作。
Get_user.php // in the ROOT folder of the JOomla website and works fine !
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
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();
$user = JFactory::getUser();
$uname = $user->username;
echo $uname;
//return $uname;
这是我的test。php文件放在http://www.mywebsite.com/files/test.php
<? php
$uname = include 'http://www.mywebsite.com/Get_user.php';
echo $uname;
?>
这总是返回1,因为我想要用户名。我尝试了RETURN,但不工作。
我在论坛上搜索了很多,但似乎没有什么对我有用。
谁能帮帮我?
必须是return
包含路径,而不是url。
test.php
<?php
$uname = include(__DIR__ . '/../Get_user.php');
echo $uname;
?>