简体   繁体   English

PHP文件返回1,而不是另一个PHP文件中的登录用户名

[英]PHP files returns 1 instead of the logged in user name in another PHP file

I have a joomla website and have a PHP file in the root folder which fetches the current logged user perfectly. 我有一个joomla网站,并且在根文件夹中有一个PHP文件,可以完美地获取当前登录的用户。

I have another folder 'Files' which contains other HTML & PHP files. 我还有另一个文件夹“ Files”,其中包含其他HTML和PHP文件。 I need to kfetch the current logged user to work with these other HTML files. 我需要提取当前登录的用户才能使用这些其他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;

And this is my test.php file placed in http://www.mywebsite.com/files/test.php 这是我放置在http://www.mywebsite.com/files/test.php test.php文件

 <? php
    $uname =  include 'http://www.mywebsite.com/Get_user.php';
    echo $uname;
  ?>

This always returns 1 where as i would like to have the user name. 这总是返回1,因为我想拥有用户名。 I tried with RETURN but doesn't work. 我尝试了RETURN,但没有用。

I have searched a lot in the forum but nothing seems to be working for me. 我在论坛上进行了很多搜索,但似乎没有任何帮助。

Can anyone please help me ? 谁能帮帮我吗 ?

It has to be return . 它必须return

Include it with path, not url. 包括路径,而不是URL。

test.php test.php

<?php
    $uname =  include(__DIR__ . '/../Get_user.php');
    echo $uname;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM