Thursday, 28 April 2016 16:39

How I can get user id or other information from any user in joomla

Written by
Rate this item
(1 Vote)
public static function getUserId($username)
    $db = JFactory::getDbo();
    $query = $db->getQuery(true)
        ->where($db->quoteName('username') . ' = ' . $db->quote($username));
    $db->setQuery($query, 0, 1);

    return $db->loadResult();

And you can use JUserHelper:

$username = 'admin';
$userId    = JUserHelper::getUserId($username);

echo $userId;
Read 725 times Last modified on Sunday, 22 October 2017 23:17

Experienced Web Developer with a demonstrated history of working in the information technology and services industry.

Skilled in User Experience, Magento, Joomla, WordPress and IT Services.

Related items

  • [solved] How to delete text symbol from php line?
    in PHP
    $string = 'Some Text .... 1. 2 .3.  Buy';
    $string = preg_replace('~[^0-9]+~','',$string);
    echo $string;
    // 123 
  • How to show all errors in php?
    in PHP

    If you need show some errors in your php code - use this php notation:

    // enable showing errors in PHP
    ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT);
  • [solved] Deprecated: Methods with the same name as their class will not be constructors ... www/plugins/content/jw_sigpro/jw_sigpro.php on line 19

    If you update your hosting to v7.1 & more - you can look same notification 'Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; plgContentJw_sigpro has a deprecated constructor in .../www/plugins/content/jw_sigpro/jw_sigpro.php on line 19'

    This code fix this problem you need Open plugins/content/jw_sigpro/jw_sigpro.php find this code in line 28:

    function plgContentJw_sigpro(&$subject, $params)
    		parent::__construct($subject, $params);
    		// Define the DS constant under Joomla! 3.0
    		if (!defined('DS'))
    			define('DS', DIRECTORY_SEPARATOR);

     And replase it to this code:

    public function __construct(&$subject, $params) {
    	parent::__construct($subject, $params);
    	// Define the DS constant under Joomla! 3.8.2+
    	if (!defined('DS')){
    		define('DS', DIRECTORY_SEPARATOR);

    Awesome - it work done! :-)

    If you see same problem with jw_sig.php  - just download free new plugin from GitHub and install it:

  • [php] How to make function for compress css using regular expression
    in PHP
    function compresscss ( $data, $url ) {
            global $current_css_url;
            $current_css_url = $url;
            /* remove comments */
            $data = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $data);
            /* remove tabs, spaces, new lines, etc. */
            $data = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), ' ', $data);
            /* remove unnecessary spaces */
            $data = preg_replace('/[ ]+([{};,:])/', '\1', $data);
            $data = preg_replace('/([{};,:])[ ]+/', '\1', $data);
            /* remove empty class */
            $data = preg_replace('/(\}([^\}]*\{\})+)/', '}', $data);
            /* remove PHP code */
            $data = preg_replace('/<\?(.*?)\?>/mix', '', $data);
            /* replace url*/
            $data = preg_replace_callback('/url\(([^\)]*)\)/', 'replaceurl', $data);
            return $data;


  • 7 tips to improve Joomla website performance [part 2]

    To continue with the tips to improve Joomla website performance, in the previous part, I had introduced how to use caching and .htaccess Optimization Rules, in this part, I will show you some other tips and hope you find it useful.

    Joomla Compression

    This is also an effective feature to optimize your website performance. When you enable this feature, the web page will be compressed and of course, the compressed page will take less time to load. Here is the way to enable Joomla Compression: