-2

I would like to know how to check if a user is connecting from a computer, or from a Phone. I'm using Symfony(Latest) and of course PhpPoo. I tried to use PHP_OS, but there is too much choice, and "home-made function" are not optimized.

The fact is that if the user is conneting to my website from a computer, i won't be able to access to it, but if it's from a mobile phone, i will be able.

Thanks :)

Nuura
  • 21
  • 5
  • PHP is not able to see information such as user agent, you'll want to [do the detection in JavaScript](https://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-version-using-javascript) and pass it through as a variable – sjdaws Jun 09 '17 at 12:20
  • There's [get_browser](http://php.net/manual/en/function.get-browser.php) - apart from that you have to do some client-side magic. Also: [this](https://github.com/ThaDafinser/UserAgentParser) package might be of use. – ccKep Jun 09 '17 at 12:36
  • Thanks dude! I'll check for these solutions :) – Nuura Jun 09 '17 at 13:15
  • At the controller level, in each action, you can retrieve the request object and inside it you will have all the variable you will need to detect user information. printr($this->getRequest()); inside a controller will give you all you need. – jeremy Jun 09 '17 at 18:50

1 Answers1

0

I usually use the MobileDetect library for detecting the device and supported features of the client.

There is a convenient Symfony integration: MobileDetectBundle

Kévin Dunglas
  • 2,373
  • 1
  • 15
  • 36