Skip to content

Mobile device detection (phone, tablet, bot, mobile grade, os, versions, etc)

License

Notifications You must be signed in to change notification settings

igor-pavlenko/mobile-detect.lua

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

mobile-detect.lua

A loose port of Mobile-Detect to Lua for NGINX HTTP servers.

The script will detect the device by comparing patterns against a given User-Agent string.
The following device information is available:

  • mobile or not
  • if mobile, whether phone or tablet
  • operating system
  • Mobile Grade (A, B, C)
  • specific versions (e.g. WebKit)

Current master branch is using detection logic from Mobile-Detect@2.8.22

Requirements

Usage

init_by_lua_block {
    mobile_detect = require "mobile-detect"
}

content_by_lua_block {
    local user_agent = ngx.var.http_user_agent
    ngx.say(mobile_detect.mobile(user_agent))
    ngx.say(mobile_detect.is('iPhone', user_agent))
    ngx.say(mobile_detect.is('bot', user_agent))
}

Contributing

Your contribution is welcome.
If you want new devices to be supported, please contribute to Mobile-Detect.
Changes there will cascade to this project.

If you have bug-fixes, new features, etc for this project, please follow the below steps:
Note: To generate source from template, it requires Mobile-Detect as a sibling directory to mobile-detect.lua

  • Clone Mobile-Detect
  • Fork mobile-detect.lua
  • Create branch
  • Make changes
  • Generate source: php generate/generate.php (requires PHP >= 5.4 in your PATH)
  • Run tests (see below)
  • Commit, push to your branch
  • Create pull request

Testing

  • Install Perl (add to PATH)
  • Install Test::Nginx: cpan Test::Nginx
  • Run: prove -r t

License

MIT-License (see LICENSE file)

About

Mobile device detection (phone, tablet, bot, mobile grade, os, versions, etc)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 76.9%
  • Perl 21.5%
  • PHP 1.6%