You're troubleshooting a problem with a part of your application that deals with the session data (temporary user preferences, shopping cart data, etc.) that Drupal stores in its database for authenticated users on your site. You've logged in, and can reproduce the problem by requesting a page as a logged-in user. However, you'd like to track that logged-in user's session back to the database in order to check the data currently associated with it.
In order to accomplish this, you'll need to retrieve the session ID of your user's current login session. This session ID is stored in a cookie in your site's web browser when you initially log in, and this cookie is sent with every subsequent request to your site from that browser. Drupal uses this identifier to determine that a request is from a specific authenticated user, and retrieve information from the database (stored in a table called "sessions") that may have been set for your user previously during your current login session.
Before we begin:
Please note that if someone has access to your session ID, they'll be able to log into the site as your user until that session is deleted or expires. For this reason, you should be extremely careful when sharing or publishing session identifier information, as it could be used to gain unauthorized access to the Drupal user account on your site.
If you've already logged in to Drupal and can reproduce this problem in your web browser, finding the ID of your current login session is as simple as reading that cookie's value from your web browser:
- Make sure you're logged into your Drupal site.
- Open your web browser's cookie management page
- In Google Chrome, open the "Settings" page, click "Show advanced settings", and under the Privacy section, click "Content Settings". Then, under "Cookies", click "All cookies and site data" to open the cookie management page (or simply click here).
- In Mozilla Firefox, open the "Preferences" page, and click the "Privacy and Security" tab (or simply click here). Under the "History" section, click the "delete individual cookies" link to open the cookie management window.
- In the cookie management window, locate the cookies that correspond to your Drupal site (e.g: "www.example.com"), and look for a cookie whose name starts with "SESS" or "SSESS".
- View the cookie described in Step 3. The session ID will be the "Content" or "Value" of this cookie.
You can can use this ID to look up your session in your site's database, in the "sessions" table, under the "sid" column.
If you can't log in as the affected user, or want to find the session ID for another Drupal user, you can look up that identifier (and the data associated with it) directly in the "sessions" table of your site's database. All you'll need is the numeric user ID of the user you'd like to look up (e.g: the user ID of your site's administrative user is 1). You can query the database for entry with a value in the "uid" column that matches this user ID. However, please note that a single user ID may have multiple active sessions associated with it (e.g: if a user is logged into your Drupal site on multiple web browser). Also, if your site sets user data for anonymous users (i.e: user ID 0), looking up a value in the "uid" column won't be an effective way to narrow in on an individual user's session.