I don't if this ever happened to you or not before, but one time I was working on a project and I wanted to know whether my user was accessing the site from a mobile device or a desktop.

I know you can do this with a help of PHP class in your code and I have done that in the past. However, for some apparent reason I couldn't find that file.

I came across apimk, which allowed me to get the mobile information rather than me installing anything on my server.

Another neat feature about this is that all the work is being done on your client's side rather than on your server.

For example, if you get 100,000 visitors daily, then your server is doing a lot of the heavy lifting. However, if you make this call from the client's side, you don't have to worry about your server working as hard.

How To Make The API Call

You can just hop ontoapimk - detecting mobile device with jquery 

For the most part this is very self-explanatory and it is easy to use.

You would include your jquery at the top of your page, as you would normally do it, then just the following code to make the call:

<script type="application/javascript" src="jquery.min.js"></script>

<script type="application/javascript">
$(document).ready(function()
{
	$.getJSON("https://apimk.com/ismobile.json", function(data, status)
	{
		var d = '';
		d += 'Status = '+data['Status'];
		d += 'Mobile = '+data['Mobile'];
		d += 'Browser = '+data['Browser'];
		d += 'BrowserVersionNum = '+data['BrowserVersionNum'];
		d += 'Platform = '+data['Platform'];
		d += 'OS = '+data['OS'];
	});
});
</script>

After you make the API call, you will get the data back in json format, which is probably the most preferable format because it is the most reliable and easy to use.

Result Back In Json Format

 {
  "ua": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Mobile Safari/537.36",
  "browser": {
    "name": "Chrome",
    "version": "60.0.3112.113",
    "major": "60"
  },
  "engine": {
    "name": "WebKit",
    "version": "537.36"
  },
  "os": {
    "name": "Android",
    "version": "6.0"
  },
  "device": {
    "vendor": "LG",
    "model": "Nexus 5",
    "type": "mobile"
  },   
}

Then you could parse through the different kind of data set points.

Demo






Name

Email

Website

Comment

Post Comment