View php session variables

View php session variables

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Viewing PHP Session Variables in the Browser

There is no browser extension for Firefox or Chrome that allows you to view raw PHP session variables directly within the DevTools sidebar, just as you can inspect cookies or LocalStorage. This limitation exists because of how sessions operate fundamentally differently from cookies regarding data location and lifecycle management.

Cookies are stored on the client side; they reside in your browser's storage engine alongside localStorage and IndexedDB. Because the data lives in the browser, extensions have direct read/write access to these values without needing to interact with the server. PHP sessions work inversely. The session identifier (the ID you see in the address bar or cookies) is stored on the client, but the actual associative array of variables—$_SESSION['key']—exists entirely on the server within a file system path or database table determined by your php.ini configuration.

To view these variables, you must inspect the server state, not the browser state. The most direct method involves accessing the session storage mechanism directly from the browser's network layer or through specific server-side debugging techniques.

Inspecting Sessions via Network Watermarks

The most effective way to peek at session data without modifying your application code is to intercept the session_start() response or a subsequent request that echoes the session ID and contents. However, since sessions are opaque blobs of data until explicitly accessed in your script, you cannot simply "read" them from the browser's Network tab like a cookie.

If you need to verify what is stored during development, the standard approach is to enable session debugging on the server side. In Apache with PHP 7.4 and later, or generally across modern environments, you can utilize session.use_strict_mode alongside display_errors to ensure that when a script accesses a session variable, it logs or outputs the value.

A common pattern for developers who need to audit session contents is to temporarily modify the application logic to dump the array before exiting:

if (isset($_SESSION['user_id']) && isset($_SESSION['permissions'])) {
    header('Content-Type: application/json');
    echo json_encode([
        'session_id' => session_id(),
        'variables' => $_SESSION
    ]);
    exit;
}

By accessing a specific route that triggers this logic, you can view the raw JSON representation of your session variables. You can then open the browser's Developer Tools -> Network tab, locate that specific request, and inspect the response body. This effectively bypasses the need for a dedicated "session inspector" extension by leveraging standard HTTP responses.

Server-Side Configuration and Storage Locations

Understanding where the data lives is crucial for troubleshooting. By default, PHP stores session files in the directory specified by session.save_path in your php.ini file. To view these files directly:

  1. Locate your active php.ini.
  2. Find the session.save_path directive (often /var/lib/php/sessions on Linux).
  3. Ensure session.save_handler is set to files.
  4. Navigate to that directory via your file manager or SSH.

The files are typically named using a hash of the session ID. You cannot read them as plain text without decoding them, but you can inspect their existence and size. If you see a file with the same name as your current session ID (often prefixed with sess_), you know the session is active in storage.

If your application uses a database handler (session.save_handler = db or custom implementations like Laravel's session driver), the data resides in a table. In that scenario, viewing the variables requires querying the specific column mapped to $_SESSION content, which might be serialized JSON or a binary blob depending on the configuration.

Security Implications of Inspection

Attempting to view session variables from the browser without server cooperation is impossible by design. This architecture prevents cross-site scripting (XSS) attacks from easily stealing sensitive data stored in sessions, as the browser cannot arbitrarily read the server's memory or file system.

However, if you are developing the application, enabling debugging output for sessions can introduce security risks if not handled carefully. Dumping $_SESSION to JSON or HTML without sanitizing the values can expose sensitive tokens, CSRF tokens, or user credentials if an attacker can manipulate the session data or intercept the response. Always ensure that debug endpoints are restricted behind authentication checks in production environments.

For frameworks like Laravel, you should check your .env file for SESSION_DRIVER. If set to database, inspecting the sessions table will reveal the serialized data. If set to file, the inspection happens in the configured path. There is no universal extension that abstracts this away because the abstraction layer depends entirely on how your framework or PHP configuration decides to persist the state.

Our network