PHP: Class For Mobile Device Detection

If we are using wordpress we can easily using plugin to make switch button between desktop version or mobile version for our blog. Question is how if we’re not using wordpress or we already using another CMS which not contain mobile device detection or we want to build it from zero. In this short articles I will write some technique to detecting mobile device or desktop device.

Google really inspired my creativity after they allowed my country language showing ads in mobile version. There is 2 version ads which it’s only shown for Android or iPhone and another one is for all mobile device. I want to target the ad to maximize my revenue so I looking a better way to detecting mobile device.

After searching yesterday I found one interesting project it was php-mobile-detect. Actually it PHP class to detecting all mobile device and some high-end device ex: android iphone, etc You can download php mobile detec class from here, open it, you may change something on there is you know about mobile device.

[to_plus]

Next, how to using this class. It’s very simple because they already documented it. First upload php mobile detect class and then created some php files with content like this:

include(“Mobile_Detect.php”);
$detect = new Mobile_Detect();

After that there is 7 device you can detect using this class… isAndroid(), isBlackberry(), isOpera(), isPalm(), isWindows(), isGeneric(), and isMobile.() Next, If I want to shown ad only for android phone then I just created php script with content like this sample:

if ($detect->isAndroid()) {
// code to run for the Google Android platform
}

There is something missing on here, as we can see there is no detector for isDesktop() version. Don’t worry we can tricky it using some declaration. There is detector for isMobile() so we will using this variable. The sample code:

if (($detect->isMobile()) == false) {
// code to run for the desktop version
}

That’s it! now we can sepearated users based on their device 🙂 and we can target ad to shown only for device required. This script was tested on my small project today, you can visited by click this. It’s not done yet but it’s already detecting what device you’re using to access it. Be creative, use your imagination to make a better coding!

That’s it, Have a nice day everyone! 🙂

Similar Posts:

RELATED SEARCH TERMS:

3 thoughts on “PHP: Class For Mobile Device Detection”

  1. I’m not certain where you are getting your information, but great topic. I needs to spend some time learning much more or figuring out more. Thank you for great information I was looking for this info for my mission.

  2. pak saya mohon kepada bapak ,tolong di blokir rekening no.093101003342509,atas nama teddy hermawan,karena beliau telah menipu saya se besar 3 juta rupiah,modus nya ber kedok penjualan laptop sony vaio,klo bapak jumpa dgn belia tolong laporkan ke polisi ter dekat,bukti nya ada sama saya,bank riau no.rekening 128-21-05010

  3. pak saya mohon kepada bapak ,tolong di blokir rekening no.093101003342509,atas nama teddy hermawan,karena beliau telah menipu saya se besar 3 juta rupiah,modus nya ber kedok penjualan laptop sony vaio,klo bapak jumpa dgn belia tolong laporkan ke polisi ter dekat,bukti nya ada sama saya,bank riau no.rekening 128-21-05010,atas per hatian nya saya ucap kan terima kasih

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.