Mobile Version, Tantangan Sederhana Koran Indonesia

Oleh : Reza Ervani

Sudah beberapa hari ini penulis menikmati membaca New York Times lewat communicator. Alhamdulillah, sebuah kemudahan belajar dan mengakses informasi.

Tidak seperti website surat kabar lokal, website NewYork Times menyediakan langsung versi mobilenya di : http://mobile.nytimes.com, sehingga saat kita mengaksesnya dengan perangkat mobile, yang langsung tampil adalah versi mobile tersebut, yang jauh lebih ringan dibandingkan versi browser biasa.

Sayangnya, versi yang sama tidak penulis dapati di website surat kabar lokal, termasuk yang sekelas Republika, Tempo, Media Indonesia dan Kompas. Sayang sekali

Penulis mencoba mencari-cari kode sumber .php untuk autodetect mobile browser ini. Setelah browsing sana sini, inilah yang penulis temukan.

*/

function detect_mobile_device(){

// check if the user agent value claims to be windows but not windows mobile
if(stristr($_SERVER[‘HTTP_USER_AGENT’],’windows’)&&!stristr($_SERVER[‘HTTP_USER_AGENT’],’windows ce’)){
return false;
}
// check if the user agent gives away any tell tale signs it’s a mobile browser
if(eregi(‘up.browser|up.link|windows ce|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp’,$_SERVER[‘HTTP_USER_AGENT’])){
return true;
}
// check the http accept header to see if wap.wml or wap.xhtml support is claimed
if(stristr($_SERVER[‘HTTP_ACCEPT’],’text/vnd.wap.wml’)||stristr($_SERVER[‘HTTP_ACCEPT’],’application/vnd.wap.xhtml+xml’)){
return true;
}
// check if there are any tell tales signs it’s a mobile device from the _server headers
if(isset($_SERVER[‘HTTP_X_WAP_PROFILE’])||isset($_SERVER[‘HTTP_PROFILE’])||isset($_SERVER[‘X-OperaMini-Features’])||isset($_SERVER[‘UA-pixels’])){
return true;
}
// build an array with the first four characters from the most common mobile user agents
$a = array(
‘acs-‘=>’acs-‘,
‘alav’=>’alav’,
‘alca’=>’alca’,
‘amoi’=>’amoi’,
‘audi’=>’audi’,
‘aste’=>’aste’,
‘avan’=>’avan’,
‘benq’=>’benq’,
‘bird’=>’bird’,
‘blac’=>’blac’,
‘blaz’=>’blaz’,
‘brew’=>’brew’,
‘cell’=>’cell’,
‘cldc’=>’cldc’,
‘cmd-‘=>’cmd-‘,
‘dang’=>’dang’,
‘doco’=>’doco’,
‘eric’=>’eric’,
‘hipt’=>’hipt’,
‘inno’=>’inno’,
‘ipaq’=>’ipaq’,
‘java’=>’java’,
‘jigs’=>’jigs’,
‘kddi’=>’kddi’,
‘keji’=>’keji’,
‘leno’=>’leno’,
‘lg-c’=>’lg-c’,
‘lg-d’=>’lg-d’,
‘lg-g’=>’lg-g’,
‘lge-‘=>’lge-‘,
‘maui’=>’maui’,
‘maxo’=>’maxo’,
‘midp’=>’midp’,
‘mits’=>’mits’,
‘mmef’=>’mmef’,
‘mobi’=>’mobi’,
‘mot-‘=>’mot-‘,
‘moto’=>’moto’,
‘mwbp’=>’mwbp’,
‘nec-‘=>’nec-‘,
‘newt’=>’newt’,
‘noki’=>’noki’,
‘opwv’=>’opwv’,
‘palm’=>’palm’,
‘pana’=>’pana’,
‘pant’=>’pant’,
‘pdxg’=>’pdxg’,
‘phil’=>’phil’,
‘play’=>’play’,
‘pluc’=>’pluc’,
‘port’=>’port’,
‘prox’=>’prox’,
‘qtek’=>’qtek’,
‘qwap’=>’qwap’,
‘sage’=>’sage’,
‘sams’=>’sams’,
‘sany’=>’sany’,
‘sch-‘=>’sch-‘,
‘sec-‘=>’sec-‘,
‘send’=>’send’,
‘seri’=>’seri’,
‘sgh-‘=>’sgh-‘,
‘shar’=>’shar’,
‘sie-‘=>’sie-‘,
‘siem’=>’siem’,
‘smal’=>’smal’,
‘smar’=>’smar’,
‘sony’=>’sony’,
‘sph-‘=>’sph-‘,
‘symb’=>’symb’,
‘t-mo’=>’t-mo’,
‘teli’=>’teli’,
‘tim-‘=>’tim-‘,
‘tosh’=>’tosh’,
‘treo’=>’treo’,
‘tsm-‘=>’tsm-‘,
‘upg1’=>’upg1’,
‘upsi’=>’upsi’,
‘vk-v’=>’vk-v’,
‘voda’=>’voda’,
‘wap-‘=>’wap-‘,
‘wapa’=>’wapa’,
‘wapi’=>’wapi’,
‘wapp’=>’wapp’,
‘wapr’=>’wapr’,
‘webc’=>’webc’,
‘winw’=>’winw’,
‘winw’=>’winw’,
‘xda-‘=>’xda-‘
);
// check if the first four characters of the current user agent are set as a key in the array
if(isset($a[substr($_SERVER[‘HTTP_USER_AGENT’],0,4)])){
return true;
}
}

function detect_iphone(){
if(eregi(‘iphone’,$_SERVER[‘HTTP_USER_AGENT’])||eregi(‘ipod’,$_SERVER[‘HTTP_USER_AGENT’])){
return true;
}
}

// example 1 – detect and redirect mobile browsers
if(detect_mobile_device()){
header(‘Location: http://rezaervani.mobi/’);
exit;
}

// example 2 – detect and redirect desktop browsers
if(!detect_mobile_device()){
header(‘Location: http://rezaervani.info/’);
exit;
}

function detect_iphone(){
if(eregi(‘iphone’,$_SERVER[‘HTTP_USER_AGENT’])){
return true;
}
}

// example 3 – send iphone to specific site
if(detect_iphone()){
header(‘Location: http://iphonesite.mobi/’);
exit;
}

?>

Mau tahu ujicobanya ? Tunggu infonya di blog ini ya …

Semoga bermanfaat,

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: