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;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀