Answer the question
In order to leave comments, you need to log in
Why is the user-agent field empty?
There is a PHP code that writes IP and user-agent to a file.
$ip = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$file = 'user-agents.txt';
$current = file_get_contents($file);
$current .= "\n" . str_pad($ip, 20) . "" . str_pad(date("d.m.Y H:i:s"), 25) . "" . $agent;
file_put_contents($file, $current);
Answer the question
In order to leave comments, you need to log in
Firstly, there are a lot of anonymization plugins for browsers that hide this header, and even Chrome in incognito mode, if my memory serves me right. does not transmit it. Secondly, not only browsers can access the site, but also other programs that may not set this header.
I will supplement the words of Sergey Gornostaev .
Anonymization plugins usually change the user-agent to another one.
In incognito mode, browsers still pass the user-agent (checked on Chrome, Opera).
All major search engines specify a user-agent for their bots.
So it's either programs or browsers blocked from sending user-agent via plugins.
I won't say anything about your code, I don't know PHP.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question