By leemchildress on
I a writing an application outside of drupal. To display the administration section of that application, I would like to check to see if user is logged into Drupal and that he is 'admin'.
Accordingly, using the cookie set by drupal, how do I determine the username (if any) logged into drupal?
Comments
I'm not an ace coder, but
I'm not an ace coder, but I'd say:
You will use the session id to look up the user id associated with the session in the sessions table then join it to the users table from which you may retrieve more user information like the user name:
SELECT u.name, u.uid FROM users u LEFT JOIN sessions s ON u.uid = s.uid WHERE s.sid = '$sid' or something like that.
I saw in the cron.php file in Drupal's root install directory that you can "bootstrap" to your Drupal installation in the custom script you write. I would assume that will mean you have access to the API and don't have to set up database stuff, then also just remember to use {} around your table names.
Add cookies
Since Drupal doesn't make the username available in a cookie, you may wish to add a cookie (perhaps encoding the username, or obscuring it). That's easy to do with a module, but you could even do it in a page template.