How do I get a Joomla user id (which is a number) from user name?

Kiran Madipally

I would like to get the Joomla user Id from the user name, I will be using this in an external script.

GDP

if you don't want to get it via Joomla, just use a SQL statement like this:

SELECT id FROM #__users WHERE username = 'someusername';

Or load Joomla and use something like this code:

if (!defined('_JEXEC')) {
    define( '_JEXEC', 1 );
    define ('JPATH_BASE', "c:\\wamp\\www\\oursite");
    define( 'DS', DIRECTORY_SEPARATOR );
    require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
    require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
    require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
    require_once ( JPATH_LIBRARIES.DS.'joomla'.DS.'import.php'); // Joomla library imports.
    $app=& JFactory::getApplication('site');
}

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id');
$query->from($db->quoteName('#__users'));
$query->where($db->quoteName('username')." = ".$db->quote('someusername'));
$db->setQuery($query);
$user_id = $db->loadResult();

// Get a JUser object, if you want/need it
$user = JFactory::getUser($user_id);

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How do I get a variable with the name of the user running ansible?

分類Dev

How do I get the sum of the user input and a randomly generated number?

分類Dev

How do I use row_number in Hive query to get the latest user login?

分類Dev

How do I pass the `number_entered_by_user` in a Javascript through `onfocusout(number_entered_by_user)` event

分類Dev

How do i retrieve columns from multiple tables specific to user session id?

分類Dev

In Oracle, How do I alter a user that have a special character in the name?

分類Dev

How do I configure @PreAuthorize to recognize the ID of my logged in user?

分類Dev

Discord.js how to get user id just from the username

分類Dev

How to redirect the user according to their user groups in Joomla

分類Dev

How can I find my User ID (UID) from terminal?

分類Dev

How do I set ${user} in Eclipse to get the correct @author tag?

分類Dev

How do I get all the messages of a specific user on a specific channel

分類Dev

how do i get facebook photo of public user in php

分類Dev

How do I get sudo -u $user to use the users env?

分類Dev

How to return a Future<User> from function which returns User?

分類Dev

How can I get current location from user in iOS

分類Dev

How can I get current location from user in iOS

分類Dev

How can I create a single dynamic user page to process any user from their unique id

分類Dev

How do I get which radio button is checked from a groupbox?

分類Dev

How do I ask a user for a input file name, and then use that file name?

分類Dev

How to get user-defined methods name?

分類Dev

I have 2 boxes and a picture. The user can drag the picture between the 2 boxes. How do I tell which box the picture is dragged from?

分類Dev

How do I fix this section of code to allow the user to get their favorites from Firebase Realtime db? even with uid working, user can't view favorites

分類Dev

How do I restrict the user input to particular strings, which are already stored as a variable(s)?

分類Dev

How to get "id" without user and pass

分類Dev

How do I get the font name from an otf or ttf file?

分類Dev

How do I get the font name from a font file?

分類Dev

Discord.py: How can I make a command that i can only do with my user ID?

分類Dev

How can I tell which user limit I am running into?

Related 関連記事

  1. 1

    How do I get a variable with the name of the user running ansible?

  2. 2

    How do I get the sum of the user input and a randomly generated number?

  3. 3

    How do I use row_number in Hive query to get the latest user login?

  4. 4

    How do I pass the `number_entered_by_user` in a Javascript through `onfocusout(number_entered_by_user)` event

  5. 5

    How do i retrieve columns from multiple tables specific to user session id?

  6. 6

    In Oracle, How do I alter a user that have a special character in the name?

  7. 7

    How do I configure @PreAuthorize to recognize the ID of my logged in user?

  8. 8

    Discord.js how to get user id just from the username

  9. 9

    How to redirect the user according to their user groups in Joomla

  10. 10

    How can I find my User ID (UID) from terminal?

  11. 11

    How do I set ${user} in Eclipse to get the correct @author tag?

  12. 12

    How do I get all the messages of a specific user on a specific channel

  13. 13

    how do i get facebook photo of public user in php

  14. 14

    How do I get sudo -u $user to use the users env?

  15. 15

    How to return a Future<User> from function which returns User?

  16. 16

    How can I get current location from user in iOS

  17. 17

    How can I get current location from user in iOS

  18. 18

    How can I create a single dynamic user page to process any user from their unique id

  19. 19

    How do I get which radio button is checked from a groupbox?

  20. 20

    How do I ask a user for a input file name, and then use that file name?

  21. 21

    How to get user-defined methods name?

  22. 22

    I have 2 boxes and a picture. The user can drag the picture between the 2 boxes. How do I tell which box the picture is dragged from?

  23. 23

    How do I fix this section of code to allow the user to get their favorites from Firebase Realtime db? even with uid working, user can't view favorites

  24. 24

    How do I restrict the user input to particular strings, which are already stored as a variable(s)?

  25. 25

    How to get "id" without user and pass

  26. 26

    How do I get the font name from an otf or ttf file?

  27. 27

    How do I get the font name from a font file?

  28. 28

    Discord.py: How can I make a command that i can only do with my user ID?

  29. 29

    How can I tell which user limit I am running into?

ホットタグ

アーカイブ