Hello, I just want to have a log file with user IP and agents of who is visiting my homepage.
I managed to modify a PHP script that does it, but Grav does not allow direct PHP inside pages :(
Could anybody make this script into a plugin that would run on mainpage.html.twig and write the log?
<?php
$date = new DateTime();
$rdate = $date->format('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$file = "bla.txt";
$fh = fopen($file, 'a');
fwrite($fh, '/---'.$rdate."```
");
fwrite($fh, '| '.$ip.' '.$hostname."
");
fwrite($fh, '| '.$agent."
");
fwrite($fh, '------'."
");
fclose($fh);
?>
Sorry if this is not the right place, but I have no coding experience and don't know anything about PHP plugins.