-
-
- Submit Updated Articles to Bing and Yandex with IndexNow in Joomla
- Add Published and Modified Date Meta Tags to Joomla
- Add Open Graph and Twitter Card Tags to Joomla
- Auto-Generate Meta Descriptions from Article Text in Joomla
- Add Noindex to Specific Pages in Joomla
- Verify Your Joomla Site with Google Search Console
-
- Add a View as Markdown Link to Joomla Articles
- Display the Last Modified Date in Joomla Articles
- Embed Iframes in Joomla
- Automatically Link Twitter (X) @mentions in Joomla Articles
- Open External Links in a New Tab in Joomla
- Display Estimated Reading Time in Joomla Articles
- Replace Old URLs in Joomla
- Search and Replace in Joomla
-
- Add a Footer Line to the Joomla Administrator
- Show a Staging Banner in the Joomla Administrator
- Remove the "All" Option from Admin List Limits in Joomla
- Add a Cookie Consent Banner to Joomla
- Make the Administrator Navigation Sticky in Joomla
- Add Google Fonts to Joomla
- Add a Facebook Messenger Chat Button to Joomla
- Add a Reading Progress Bar to Joomla
- Add a Custom Scrollbar to Joomla
- Show Confetti on a Thank You Page in Joomla
- Add Smooth Scrolling to Joomla
- Add a Back to Top Button in Joomla
- Add a WhatsApp Chat Button in Joomla
-
- Protect the Administrator with a Secret URL Key in Joomla
- Show a Welcome Message on First Login in Joomla
- Log Out Idle Administrators in Joomla
- Assign New Users to a Different User Group Automatically in Joomla
- Redirect Visitors by Country in Joomla
- Redirect Users After Login by User Group in Joomla
- Block User Registration with Certain Usernames in Joomla
- Block User Registration by Country in Joomla
- Block User Registration by Email Address in Joomla
- Block User Registration by IP Address in Joomla
- Remove the Forgot Password and Username Links in Joomla
- Remove the Generator Meta Tag in Joomla
- Let Users Log In with Their Email Address in Joomla
- Block Traffic by Country in Joomla
- Block Bot Traffic in Joomla
- Block Traffic by IP Address in Joomla
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.
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.phpextension. 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 totrueto 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
How to add this snippet
- Install Code Snippets if it isn't installed already.
- Log into your Joomla backend.
- Go to Components → Tassos Code Snippets.
- Click New.
- Enter a title, for example Traffic log.
- Set Code Type to PHP.
- Set Insertion Method to Auto-Insert Locations.
- Set Location to On Page Load.
- Paste the code above into the editor.
- Click Save & Close.
Check that it works
- Open a few pages on your site.
- Open
administrator/logs/traffic.phpthrough 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.