Log Visitor Requests to a File in Joomla

See every page request your Joomla site serves, with the visitor's address, referrer and browser, in a log file you can open any time, using one PHP snippet.

Log Visitor Requests to a File in Joomla
Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Something hammers your site every night and the hosting panel's access log is either missing, a day behind, or a maze of rotated files. Analytics scripts don't help, because bots and scrapers don't run JavaScript. You can log visitor requests to a file in Joomla with one PHP snippet in Code Snippets.

The PHP snippet code

On every frontend request, the snippet appends one line to a file in your administrator/logs folder: the date, the visitor's IP address, the request method, the full address, the referrer and the browser. Form data and passwords are never written, so the file holds nothing a visitor typed.

use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Uri\Uri;

// File name inside administrator/logs. Keep the .php extension: Joomla
// starts the file with a line that stops browsers from reading it.
$file = 'traffic.php';

// true: skip requests from logged-in users, so you only see visitors.
$skipLoggedIn = false;

// Do not edit below.

$app = Factory::getApplication();

if ($skipLoggedIn && !$app->getIdentity()->guest)
{
    return;
}

$input  = $app->getInput();
$server = $input->server;

// One line per request: date, visitor address, method, URL, referrer and
// browser, separated by tabs. Form data and passwords are never logged.
$line = implode("\t", [
    $input->getMethod(),
    Uri::getInstance()->toString(),
    $server->getString('HTTP_REFERER', '-'),
    $server->getString('HTTP_USER_AGENT', '-'),
]);

Log::addLogger([
    'text_file'         => $file,
    'text_entry_format' => "{DATETIME}\t{CLIENTIP}\t{MESSAGE}",
], Log::INFO, ['tcs.traffic']);

Log::add($line, Log::INFO, 'tcs.traffic');

Change the 2 settings at the top:

  • $file: the file name. Keep the .php extension. Joomla starts every log file with a line that stops browsers from reading it, so opening the file's address in a browser shows "Forbidden." instead of your log.
  • $skipLoggedIn: set it to true to leave out requests from logged-in users, so the file only shows visitors.

A line looks like this, with tabs between the columns:

2026-10-15T11:59:36+00:00	8.8.8.8	GET	https://example.com/blog/hello-world	https://google.com/	Mozilla/5.0 (Macintosh) Chrome/130.0

The file keeps growing for as long as the snippet is published. Unpublish the snippet when you're done, or delete the file now and then.

How to add this snippet

  1. Install Code Snippets if it isn't installed already.
  2. Log into your Joomla backend.
  3. Go to Components → Tassos Code Snippets.
  4. Click New.
  5. Enter a title, for example Traffic log.
  6. Set Code Type to PHP.
  7. Set Insertion Method to Auto-Insert Locations.
  8. Set Location to On Page Load.
  9. Paste the code above into the editor.
  10. Click Save & Close.

Check that it works

  1. Open a few pages on your site.
  2. Open administrator/logs/traffic.php through your hosting panel's file manager or FTP.

Each page you opened has its own line, with your IP address and browser. Requests to the administrator aren't logged, and neither are addresses that don't exist, because Joomla answers those with a 404 page before any snippet runs.

To keep known pests out once you've spotted them in the log, see Block Traffic by IP Address in Joomla and Block Bot Traffic in Joomla. To learn more about how PHP snippets work, read the PHP snippet docs.

Last updated on Oct 15th 2026 15:10