As far as I've been able to assess, wordpress does not already do this, am I correct? Authentication state is not logged in mysql, by default?
If you check the wp_usermeta
table, you should see an entry called session_tokens
, which contains a user's active session information.
What is the most efficient way to echo authentication information into an sql table?
The best place would probably be the wp_login
hook, which runs every time a user logs in.
Within this hook you have access to the WP_User
object, which contains information about the user.
Using the user's ID, you can look up the current session token via:
get_user_meta($user->ID, 'session_tokens');
Which you can then log somewhere for historical purpose.