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! 🙂

[/to_plus]

Similar Posts:

Related Search Terms:

    Digg Del.icio.us StumbleUpon Reddit Twitter RSS

If you're new here, you may want to subscribe to my RSS feed. You may copy or publish this article to your blog or other site as long you give credit link back to this site article. Thanks for visiting my blog!