W
W
weranda2018-03-12 10:26:36
PHP
weranda, 2018-03-12 10:26:36

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);

I notice missing user-agent data in the file, IP is there, but user-agent is not. Please tell me why this is happening - an error in the code or bots / people with a missing user-agent and can such people be safely blocked or is there a possibility that these could be lawsuit systems?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2018-03-12
@sergey-gornostaev

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.

R
rudikov, 2018-03-12
@rudikov

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 question

Ask a Question

731 491 924 answers to any question