I posted a similar question on the beginner's forum and got immediate and helpful responses, the short answer is ":
- include mainfile.php and header.php in your php file
- echo $xoopsUser->getVar('uname'); //displays username
This is "directly using $xoopsUser object".
..you can see the full thread here: Xoops Help