Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[share Mobile detector dengan php
#1
Untuk membuat sebuah website yang dinamis kita perlu menambahkan properti-properti yang bisa mempercantik penampilan website kita, misal agar bisa di akses dengan browser mobile, seperti opera mini dll.
Nah, untuk membuat nya kita perlu sebuah program / script php untuk mendeteksi browser si pengunjung web kita,
berikut script mobile detector,

PHP Code:
<?php /** * Mobile Detect * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ class Mobile_Detect { protected $accept; protected $userAgent; protected $isMobile = false; protected $isAndroid = null; protected $isAndroidtablet = null; protected $isIphone = null; protected $isIpad = null; protected $isBlackberry = null; protected $isBlackberrytablet = null; protected $isOpera = null; protected $isPalm = null; protected $isWindows = null; protected $isWindowsphone = null; protected $isGeneric = null; protected $devices = array( "android" => "android.*mobile", "androidtablet" => "android(?!.*mobile)", "blackberry" => "blackberry", "blackberrytablet" => "rim tablet os", "iphone" => "(iphone|ipod)", "ipad" => "(ipad)", "palm" => "(avantgo|blazer|elaine|hiptop|palm|plucker|xiino)", "windows" => "windows ce; (iemobile|ppc|smartphone)", "windowsphone" => "windows phone os", "generic" => "(kindle|mobile|mmp|midp|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap|opera mini)" ); public function __construct() { $this->userAgent = $_SERVER['HTTP_USER_AGENT']; $this->accept = $_SERVER['HTTP_ACCEPT']; if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) { $this->isMobile = true; } elseif (strpos($this->accept, 'text/vnd.wap.wml') > 0 || strpos($this->accept, 'application/vnd.wap.xhtml+xml') > 0) { $this->isMobile = true; } else { foreach ($this->devices as $device => $regexp) { if ($this->isDevice($device)) { $this->isMobile = true; } } } } /** * Overloads isAndroid() | isAndroidtablet() | isIphone() | isIpad() | isBlackberry() | isBlackberrytablet() | isPalm() | isWindowsphone() | isWindows() | isGeneric() through isDevice() * * @param string $name * @param array $arguments * @return bool */ public function __call($name, $arguments) { $device = substr($name, 2); if ($name == "is" . ucfirst($device) && array_key_exists(strtolower($device), $this->devices)) { return $this->isDevice($device); } else { trigger_error("Method $name not defined", E_USER_WARNING); } } /** * Returns true if any type of mobile device detected, including special ones * @return bool */ public function isMobile() { return $this->isMobile; } protected function isDevice($device) { $var = "is" . ucfirst($device); $return = $this->$var === null ? (bool) preg_match("/" . $this->devices[strtolower($device)] . "/i", $this->userAgent) : $this->$var; if ($device != 'generic' && $return == true) { $this->isGeneric = false; } return $return; } } ?>

lalu silahkan include pada web anda,

PHP Code:
<? include("deteksi.php"); $detect = new Mobile_Detect(); if ($detect->isMobile()) { echo "<meta http-equiv='refresh' content='5; url=http://versi.mobile.web.anda'>"; }else{ echo "<meta http-equiv='refresh' content='5; url=http://versi.web.anda'>"; } ?>

special thakz : ho1onk
sumber
Reply
#2
nice tutor !! Mantab
Code:
http://xcrotz.org/
Reply
#3
nice tutornya om
izin nyicip ke blog gue Ngakak
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Death_16 share: source code my site w*74rd 36 914 11-22-2013, 03:09 PM
Last Post: Dika_xb
  menyembunyikan file PHP dengan fungsi _GET cinta.damai 0 70 11-01-2013, 06:37 PM
Last Post: cinta.damai
  Membuat Jejaring Sosial Dengan Sharetronix BL-5C 7 168 08-25-2013, 05:35 PM
Last Post: FK28KOMwarez
  [Tut] Membuat Mobile Twitter Client + Mod mydisha 70 2,182 04-26-2013, 09:29 PM
Last Post: Retrun
Death_16 membuat forum sederhana dengan php w*74rd 9 310 10-18-2012, 03:40 PM
Last Post: Falconx
  [share ]Belajar PHP (Membuat Halaman Komentar) newbie-herbet 8 218 09-19-2012, 06:15 PM
Last Post: aandoni
  [share] Membuat Hit Counter Tanpa Database newbie-herbet 3 95 09-19-2012, 07:31 AM
Last Post: newbie-herbet
  [Share] e-Book Adsense Rifqi Azhar Nugraha 0 60 07-07-2012, 05:30 PM
Last Post: Rifqi Azhar Nugraha
  Forum baru Buatan saya dengan Mybb skyland_hacker 10 299 05-22-2012, 07:46 AM
Last Post: skyland_hacker

Forum Jump:


Users browsing this thread: 1 Guest(s)