Skip to Content Skip to Menu

PHP code to get username of the logged-in user?

13 years 2 months ago #172845 by nobodyjames
Is there a simple way to query the Community Builder app/system from PHP, to ask it for the username of the current logged-in user? I'm picturing something like this:

<?PHP
require("path/to/cb/cb_user_status.php");
$username = cb_get_username();
?>

Thanks for any help on this.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
13 years 2 months ago #172874 by krileon
Yes, please review the below tutorials. If not being used in a CB plugin you'll need to first include CBs API. Once done you need to establish a $user object and from there you can call $user->username.

www.allmysocials.com/directory/tutorials/item/231-include-api-externally

www.allmysocials.com/directory/tutorials/item/232-establishing-user-object


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

13 years 2 months ago #172913 by nobodyjames
Replied by nobodyjames on topic Re: PHP code to get username of the logged-in user?
Thanks for your reply. I tried the code on the first link you mentioned, but it didn't work. It gives this error:

Fatal error: Call to a member function getCfg() on a non-object in [php page] on line 13

Here is line 13:

if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ) ) {

My test page contains exactly the code shown on your first link, and nothing more (well, except for the opening and closing PHP tags).

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum