0

Before telling me that the question have been asked earlier only with after reading my title, read further.

I would like to know the best way to detect mobile browser without sniffing the headers for the simple reason that this can be modified addons on a desktop's computer.

The reason for this is that I am building a HTML5 Game and I do not want it to be played on a desktop's computer. It will probably end up being played by automated bots if I let this happens.

The only way I can think of is to compare Javascript offsetWidth of document/window and compare it against a list of possibles sizes. But, I believe that in a not so long future, phones and tablets will have similar screen resolution then desktop's computer and I couldn't take them apart.

What are my other options? Of course, Javascript is very welcomed.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
Cybrix
  • 3,248
  • 5
  • 42
  • 61
  • 1
    This question has been asked earlier before – jeremy Sep 08 '12 at 23:22
  • possible duplicate of [JavaScript libraries to detect browser capabilities/plug-ins](http://stackoverflow.com/questions/1436994/javascript-libraries-to-detect-browser-capabilities-plug-ins) – Icarus Sep 08 '12 at 23:27
  • http://msdn.microsoft.com/en-us/magazine/hh475813.aspx – Icarus Sep 08 '12 at 23:28
  • 1
    The only way to prevent botting in a multiplayer game is to make your game so interesting that players don't want to bot in the first place. When your game is popular and the gameplay easy to automatize, people will just reverse-engineer your communication protocol and write their own client. – Philipp Sep 08 '12 at 23:29
  • Depends what you mean by “mobile browser” really. It sounds like you actually mean “not on a desktop computer”, because you’re worried about bots playing the game. I would have thought that soon enough (if not now), bots can do that from a phone too. – Paul D. Waite Sep 08 '12 at 23:29
  • http://www.html5rocks.com/en/tutorials/detection/index.html – Icarus Sep 08 '12 at 23:30
  • Echoing what Philipp said, you can't prevent this. You have to trust the client to report whether they are a mobile client or not, and the first rule of preventing cheating is "don't trust the client". – Chris Heald Sep 08 '12 at 23:44

3 Answers3

2

If your concern is preventing access from a desktop computer, well, you basically cannot. Headers can be easily forged, beating browser size detection is just a matter of resizing the window... I'd say go with normal user-agent detection and hope for the best.

  • Don't be so worried about this. Normal users will be caught in your check and not be allowed to play. Power users who may try to get to the game by forging headers etc, are not worth your thought. – sciritai Sep 09 '12 at 13:44
0

CSS3 makes it better with media queries. Instead of the if-then-else logic with the device types (User Agents), it allows us to code to the screen size.

Here is good read.

The basic idea being, dynamically adapting to the screen size (and other capabilities!) and also making the design of the website future proof from the ground-up.

Some conceptual examples are HERE

Otpidus
  • 489
  • 5
  • 5
0

Maybe one thing you could try is to make some sort of "unlock" touch gesture when your game starts up. So for example dragging a circle onto an other or something along those lines, which will:

  1. require touch events to be fired by the browser
  2. can be slightly different positions / sizes every time so difficult to script.
dain
  • 6,475
  • 1
  • 38
  • 47