TIPS - Auto-login a Joomla! user using a PHP oneliner

Auto-login a Joomla! user using a PHP oneliner

Hello super joomlers!

A simple trick to login a Joomla! user by code rather than using a form.

Interested? Let's move on...

Here is the code:

* @var bool $result_login true on successful login, false otherwise
$result_login = Factory::getApplication()->login(
                        'username' => 'example',
                        'password' => 'mysupersecretpassword'
                        'remember' => true,
                        'silent'   => true

Interesting options:
remember: Enables remember me when auto-logged in
silent: Returns a boolean (in this case false rather than an exception if an authentication error occurs).


See you soon for new tips and tricks...

Alexandre ELISÉ

#Joomla technical problem solver. Focusing on secure coding and defensive cybersecurity #appsec #blueteam.#coderparlerpartager Now working @aproximito.

Get the newsletter

Super Joomlers! Get the most out of Joomla!
We hate spam as much as you do and we will not send you email without your prior consent. You can unsubscribe / resubscribe any time you want.