dongyi1429 2015-10-21 09:14
浏览 42
已采纳

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

I have a joomla website and have a PHP file in the root folder which fetches the current logged user perfectly.

I have another folder 'Files' which contains other HTML & PHP files. I need to kfetch the current logged user to work with these other HTML files.

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

 <? 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. I tried with RETURN but doesn't work.

I have searched a lot in the forum but nothing seems to be working for me.

Can anyone please help me ?

  • 写回答

1条回答 默认 最新

  • dtiu94034 2015-10-21 09:25
    关注

    It has to be return.

    Include it with path, not url.

    test.php

    <?php
        $uname =  include(__DIR__ . '/../Get_user.php');
        echo $uname;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了