Simple visitor user agent logger without database
I was looking for easy going visitor user agent logger writing a list into a simple txt file. I just wanted to see all internet browsers and bots / crawlers accessing to my website.
You can paste this php code snippet into your function.php file and in the same folder create a standard empty txt file useragents.log
Basically you will just rename extension .txt to .log and set the file permission attributes to 700
// User-agents logger, add useragents.log into theme folder with atributes 700
add_action('wp', function ()
{
$timestamp = date('d/m/Y h:i:s ');
$space = ' '; file_put_contents(__dir__ . '/useragents.log', $timestamp . $_SERVER['HTTP_USER_AGENT'] . $space . $_SERVER['REMOTE_ADDR'] .
"\n", FILE_APPEND); }
);