Simple User Agent (Mobile and Smartphone) Detection and Redirction with PHP


/ Published in: Java
Save to your folder(s)

This is similar to the one for PHP but modified for JAVA.


Copy this code and paste it in your HTML
  1. String UserAgent = req.getHeader("User-Agent");
  2. if(UserAgent.toLowerCase().replace(' ', '%').matches("\\p{Graph}*"
  3. +"(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|"
  4. +"htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|"
  5. +"blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|"
  6. +"symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|"
  7. +"jigs browser|hiptop|^ucweb|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)"
  8. +"\\p{Graph}*")){
  9. System.out.println("ENTRY_MODE = Mobile");
  10. }
  11. else{
  12. System.out.println("ENTRY_MODE = Web");
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.