简体   繁体   English

Joomla 2.5.9,PHP 5.3.22,JFactory,获取用户

[英]Joomla 2.5.9, PHP 5.3.22, JFactory, Get User

I am using the Joomla Easy Flash Uploader and there is an auto email that is sent out to the administrator (or person of my choosing) once an upload is made. 我正在使用Joomla Easy Flash Uploader,上传完成后,会自动发送一封电子邮件给管理员(或我选择的人)。 It is designed to show the logged in user's name in the email, however it simply keep showing "Guest" even though the form is only being accessed by logged in users. 它旨在在电子邮件中显示已登录用户的名称,但是即使仅由已登录用户访问该表单,它也始终显示“来宾”。 I desperately need this to properly pull the username. 我迫切需要这个来正确提取用户名。 Here is how the message reads: (file name and location have simply been removed to protect my website. 消息显示如下:(为了保护我的网站,仅删除了文件名和位置。

A guest (Guest) has successfully uploaded FILE NAME to LOCATION at Tue, 12 Mar 2013 14:56:07 -0500. 一位访客(来宾)已成功在2013年3月12日星期二14:56:07 -0500将文件名上传到LOCATION。

  • Check out the code: 查看代码:

//email notification if ($_POST['notify'] != false && JMailHelper::isEmailAddress($_POST['recipient'])) { //fetch the mail object $mailer =& JFactory::getMailer(); //电子邮件通知if($ _POST ['notify']!= false && JMailHelper :: isEmailAddress($ _ POST ['recipient'])){//获取邮件对象$ mailer =&JFactory :: getMailer();

    //set up the sender
    $config =& JFactory::getConfig();
    $sender = array( 
        $config->getValue( 'config.mailfrom' ),
        $config->getValue( 'config.fromname' )
    );
    $mailer->setSender($sender);

    //set up recipient
    $mailer->addRecipient($_POST['recipient']);

    //get user info
    $user_info = array();
    $user =& JFactory::getUser();
    if ($user->guest == true)
    {
        $user_info['name'] = 'A guest';
        $user_info['username'] = 'Guest';
    }
            else
    {
        $user_info['name'] = $user->name;
        $user_info['username'] = $user->username;
    }

    //set up message
    $body = $user_info['name']." (".$user_info['username'].") has successfully uploaded ".$fileName;
    $body.= "(".sizeToText($fileSize).") to ".JPATH_SITE.DS.$cleanedSubPath;
    $body.= " at ".date("r", time()).".\n";
    $mailer->setSubject('New File Uploaded - PC Scribe');
    $mailer->setBody($body);

    //send email
    $send =& $mailer->Send();
    if ($send !== true)
    {
        //error: DO NOTHING!!!
        /****DEBUGGING****/
        //$replaceText.= ' * Email error *';
        /****  CODE   ****/
    }
    else
    {
        //success: DO NOTHING!!!
        /****DEBUGGING****/
        //$replaceText.= ' (Email sent)';
        /****  CODE   ****/
    }
}

I really don't think there is anything wrong with the code (well, apart from the security concerns of using $_POST). 我真的认为代码没有任何问题(嗯,除了使用$ _POST的安全性问题之外)。

At least the code itself does it job. 至少代码本身可以完成工作。

$user_info = array();
$user = JFactory::getUser();
if ($user->guest == true)
{
    $user_info['name'] = 'A guest';
    $user_info['username'] = 'Guest';
}
        else
{
    $user_info['name'] = $user->name;
    $user_info['username'] = $user->username;
}

var_dump($user_info);

The only explication maybe that the extension works somehow outside the Joomla! 唯一的说明可能是该扩展在Joomla之外可以正常工作! and the user session is somehow lost. 并且用户会话以某种方式丢失。

Do some tests yourself, checking the contents with var_dump($user) of $user. 自己做一些测试,使用$ user的var_dump($ user)检查内容。

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

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