Closed trendoman closed 1 year ago
same here
I am reading a few postings on Stack that basically revolve around fact that absent user-agent (not empty string, but completely missing one) is a valid request. https://stackoverflow.com/questions/24274789/is-lack-of-user-agent-in-http-request-valid
A posting reported that visitors with a missing UA successfulle performed purchases on website (possibly this is a disinformation lol) https://stackoverflow.com/questions/71527200/how-am-i-getting-users-with-no-user-agent-string
So, meanwhile I am going to try setting it explicitly to an empty string e.g.
if( false === $MB->hasUserAgent() ){ $MB->setUserAgent(''); }
As of https://github.com/serbanghita/Mobile-Detect/releases/tag/4.8.04 the rule is that if there is no User-Agent provided (even after we tried to auto-initialize from known $_SERVER['...']
variables, this will throw an exception, because it's actually an exceptional situation and you don't want to go on with the processing.
The recommendation is the following:
$detect = new MobileDetect();
$isMobile = false;
try {
$isMobile = $detect->isMobile();
} catch (\Detection\Exception\MobileDetectException $e) {
// do nothing, or log this to your error logs.
}
var_dump($isMobile);
Added this example to https://github.com/serbanghita/Mobile-Detect/blob/4.8.x/scripts/example.php
A server randomly receives requests that have no user-agent, mostly from similar IPs (VPN?) e.g.
What is the proper reaction to such situations - handle exceptions, fill-in a user agent before instantiating MD or else? Please advise. Thanks a lot! (I have masked a few fields, but did not delete any rows) It's as is from
print_r($_SERVER, true)
output.