PHP 文件 returns 1 而不是另一个 PHP 文件中的登录用户名
PHP files returns 1 instead of the logged in user name in another PHP file
我有一个 joomla 网站,根文件夹中有一个 PHP 文件,可以完美获取当前登录的用户。
我有另一个文件夹 'Files',其中包含其他 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;
这是我放在 http://www.mywebsite.com/files/test.php
中的 test.php 文件
<? php
$uname = include 'http://www.mywebsite.com/Get_user.php';
echo $uname;
?>
这总是 returns 1 我想要用户名。我试过 RETURN 但没有用。
我在论坛上搜索了很多,但似乎没有什么适合我的。
谁能帮帮我?
必须是return
。
将其包含在路径中,而不是 url。
test.php
<?php
$uname = include(__DIR__ . '/../Get_user.php');
echo $uname;
?>
我有一个 joomla 网站,根文件夹中有一个 PHP 文件,可以完美获取当前登录的用户。
我有另一个文件夹 'Files',其中包含其他 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;
这是我放在 http://www.mywebsite.com/files/test.php
<? php
$uname = include 'http://www.mywebsite.com/Get_user.php';
echo $uname;
?>
这总是 returns 1 我想要用户名。我试过 RETURN 但没有用。
我在论坛上搜索了很多,但似乎没有什么适合我的。
谁能帮帮我?
必须是return
。
将其包含在路径中,而不是 url。
test.php
<?php
$uname = include(__DIR__ . '/../Get_user.php');
echo $uname;
?>