-1

Using twitter bootstrap and jquery mobile, I am building a mobile site and would like to restrict access to mobile/tablet users only.

I thought of checking for screen size then redirecting but I think that on its own would be easy to bypass.

Is there some way I can achieve this securely?

Aaron
  • 3,075
  • 5
  • 29
  • 47
  • A search for `javascript detect mobile users` here or on Google will give you all you need to know. Bear in mind that any JavaScript-based solution is *relatively* easy to circumvent. Server-side detection might be slightly more reliable. – Pekka Jun 29 '13 at 16:50
  • Not sure why this is a duplicate, the question asks specifically for securely restricting access – Aaron Jul 04 '17 at 08:20

2 Answers2

6

There’s no easy way to do this because there’s no meaningful difference between a desktop browser and a mobile browser. User agents and screen sizes can easily be faked, of course, and Chrome’s developer tools even have specific settings to emulate mobile browsers for testing, including emulating touch events and setting the device orientation (just click on the gear icon in the bottom-right).

Don’t enforce this, because you will make a mistake and someone will be frustrated.

If you do, just use the user agent and hope nobody cares enough to bother.

Ry-
  • 199,309
  • 51
  • 404
  • 420
0

There are several similar questions on SO. But, as also mentioned in Detecting a mobile browser, a great resource are the scripts published on detectmobilebrowsers.com.

Basically you check the user agent from the request and do you magic if, in your case, it doesn't identify itself as a mobile device.

Of course, using any client-side script like Javascript or jQuery isn't really failsafe, as you've probably figured out. User agents, as provided through the header in a request, can be spoofed. The server-side scripts can provide you with additional sanity checks, but also they aren't even close to being "impossible to bypass".

Community
  • 1
  • 1
Juliën
  • 7,518
  • 6
  • 43
  • 73