1

I create a web page but I don't want it to be able to open in the computers browser. I only want it to be available for mobiles. I know that with user_agent is possible to know if it is a mobile or computer (I have it already working using .htaccess), but is it possible to have in the mobile view as computer or in the computer there is an option to veiw as mobile so even if I use user_agent is possible to view in a computer. Is there a better way to check if it is really a computer or a mobile?

If it is possible I want to restrict completely the option to open it in the computer.

Iban Arriola
  • 1,946
  • 6
  • 30
  • 80
  • 1
    Why would you care so much? It's not like this will prevent any *person* from seeing the site, even if you could exclude non-mobile user agents they could just switch to a mobile device. –  Nov 24 '13 at 12:28
  • 4
    Yesterday, I bought a gigantic mobile phone (32 inch screen) with a keyboard and a mouse. Should that be allowed to access your website? – Qantas 94 Heavy Nov 24 '13 at 12:49
  • The thing is that we want to prevent to be able to open it in computers to make more difficult to download some content. From a mobile device is more difficult (I am not sure if it is imposible or not) but from the computer I know that is possible. So That is the main reason. We are already creating also the mobile app but we want to have both options available. BTW I have a problems with phonegap media object and his asynchronous functions: http://stackoverflow.com/questions/20149316/asynchronous-functions-not-working-in-phonegap-media – Iban Arriola Nov 24 '13 at 13:00
  • That reason is bollocks. It's just as possible from any device. Either some browsers already allow it. You cannot prevent downloading by technical means. In fact, the content is already downloaded to be viewed and cached, the only question is how easy it is to copy it where the user wants to store it (most likely: very easy). See about a billion other questions on the same topic (often in slightly different settings). –  Nov 24 '13 at 13:28

3 Answers3

0

If you use jsp to implement the web page you can use this code to find the client device is a mobile device:

boolean isMobile = false;

String ua = request.getHeader("User-Agent").toLowerCase();
if (ua.matches("(?i).*((android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino).*") || ua.substring(0, 4).matches("(?i)1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-")) {
    isMobile = true;
}

this code will executed as a server side code.

You may want to check the client device in client side, you can use javascript as follow: Detecting a mobile browser

Community
  • 1
  • 1
Babak Behzadi
  • 1,206
  • 2
  • 16
  • 31
0

As far as I am aware, there is no method that will be 100% accurate in detecting if the client is a mobile or not. You can check the user-agent, but the user-agent can be spoofed. You can rely on javascript to detect the screen size, but javascript is public and therefore you should always assume everyone knows everything about your javascript. You can be a bit sneakier with javascript and detect a certain thing that hasn't been implemented in mobile browsers yet, but works fine in desktop browsers and base your decision on that. In the end it doesn't matter: It can be spoofed.

The only thing that can't be spoofed is the remote ip-address. If you have a giant database with data about ip's used for mobile internet and 'other ips', you can base your decision on that. Most likely you'll need to use an external service for that, and that will be a significant performance hit.

Even then, what are you trying to achieve? If the user may not download something, why do you put it on the internet? If the security of your site depends on it, you are not approaching the problem in the right way. If the files are confidential, you should put a proper username/password or public/private key in place to protect them. Relying on slow/mobile internet to protect something is a bad idea.

Sumurai8
  • 18,213
  • 9
  • 58
  • 88
0

http://matthewhudson.me/projects/device.js/

include device.js and

for example (js):

  document.write("device.ios() === ", "<span class=\"" + device.ios() + "\">" + device.ios() + "</span>", "<br />");
  document.write("device.iphone() === ", "<span class=\"" + device.iphone() + "\">" + device.iphone() + "</span>", "<br />");
  document.write("device.ipod() === ", "<span class=\"" + device.ipod() + "\">" + device.ipod() + "</span>", "<br />");
  document.write("device.ipad() === ", "<span class=\"" + device.ipad() + "\">" + device.ipad() + "</span>", "<br />");
  document.write("device.android() === ", "<span class=\"" + device.android() + "\">" + device.android() + "</span>", "<br />");
  document.write("device.androidPhone() === ", "<span class=\"" + device.androidPhone() + "\">" + device.androidPhone() + "</span>", "<br />");
  document.write("device.androidTablet() === ", "<span class=\"" + device.androidTablet() + "\">" + device.androidTablet() + "</span>", "<br />");
  document.write("device.blackberry() === ", "<span class=\"" + device.blackberry() + "\">" + device.blackberry() + "</span>", "<br />");
  document.write("device.blackberryPhone() === ", "<span class=\"" + device.blackberryPhone() + "\">" + device.blackberryPhone() + "</span>", "<br />");
  document.write("device.blackberryTablet() === ", "<span class=\"" + device.blackberryTablet() + "\">" + device.blackberryTablet() + "</span>", "<br />");
  document.write("device.windows() === ", "<span class=\"" + device.windows() + "\">" + device.windows() + "</span>", "<br />");
  document.write("device.windowsPhone() === ", "<span class=\"" + device.windowsPhone() + "\">" + device.windowsPhone() + "</span>", "<br />");
  document.write("device.windowsTablet() === ", "<span class=\"" + device.windowsTablet() + "\">" + device.windowsTablet() + "</span>", "<br />");
  document.write("device.fxos() === ", "<span class=\"" + device.fxos() + "\">" + device.fxos() + "</span>", "<br />");
  document.write("device.fxosPhone() === ", "<span class=\"" + device.fxosPhone() + "\">" + device.fxosPhone() + "</span>", "<br />");
  document.write("device.fxosTablet() === ", "<span class=\"" + device.fxosTablet() + "\">" + device.fxosTablet() + "</span>", "<br />");
  document.write("device.mobile() === ", "<span class=\"" + device.mobile() + "\">" + device.mobile() + "</span>", "<br />");
  document.write("device.tablet() === ", "<span class=\"" + device.tablet() + "\">" + device.tablet() + "</span>", "<br />");
  document.write("device.portrait() === ", "<span class=\"" + device.portrait() + "\">" + device.portrait() + "</span>", "<br />");
  document.write("device.landscape() === ", "<span class=\"" + device.landscape() + "\">" + device.landscape() + "</span>", "<br />");

css:

.true {
    color: green;
    font-weight: bold;
}
Denis
  • 55
  • 7