You are logged in as (Real Name)

Permalink
I am building a membership site and want to include on every page the following:

You are logged in as John Doe. Logout.

Basically, same as is in the default footer, but instead of using the username, I want to use the person's real name pulled from the combination of two custom user attributes:

fname (handle) for First Name
lname (handle) for Last Name

I have been combing the forums and documentation for guidance, but I am not super adept at PHP and have not found anything to help me figure it out.

Any chance someone could lend me a hand?

Thanks,

uswebdesigner
 
andrew replied on at Permalink Best Answer Reply
andrew
This code should do it:

<?php
$u = new User();
$ui = UserInfo::getByID($u->getUserID());
print $ui->getAttribute('fname') . ' ' . $ui->getAttribute('lname');
?>
uswebdesigner replied on at Permalink Reply
uswebdesigner
Thanks so much. I am a novice at PHP but added this in because it threw an error when not logged in.

$u = new User();
      $ui = UserInfo::getByID($u->getUserID());
      if ($u->isLoggedIn()){ 
      print $ui->getAttribute('fname') . ' ' . $ui->getAttribute('lname');
      }


Seems to work and wanted to add it here for anyone else or your modification if there is a better way to do it.
Mnkras replied on at Permalink Reply
Mnkras
$u = new User();
if ($u->isLoggedIn()){ 
      $ui = UserInfo::getByID($u->getUserID());
      print $ui->getAttribute('fname') . ' ' . $ui->getAttribute('lname');
}