Giter Site home page Giter Site logo

Comments (4)

maverik23 avatar maverik23 commented on June 7, 2024

same here

from mobile-detect.

trendoman avatar trendoman commented on June 7, 2024

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(''); }

from mobile-detect.

serbanghita avatar serbanghita commented on June 7, 2024

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

from mobile-detect.

serbanghita avatar serbanghita commented on June 7, 2024

Added this example to https://github.com/serbanghita/Mobile-Detect/blob/4.8.x/scripts/example.php

from mobile-detect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.