I would need to gather a list of all the user agents of the visitors of my website. Is that possible?
I essentially need a log like this:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36
Mozilla/5.0 (X11; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0
Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36
I tried with this:
<?php
$file = 'user_agents.txt';
$browser = $_SERVER['HTTP_USER_AGENT'] . "<br>";
file_put_contents($file, $browser, FILE_APPEND | LOCK_EX);
?>
To test it I made a .php file with this code inside and I uploaded it on my server. Then I opened it via browser but it didn't create a .txt file in the same folder. What should I do to make it work?
Thanks in advance