here is the imobile script
<?php
/*
isMobile.php
A PHP script to detect mobile phones.
v1.1 :: 23 September 2008
Check out my blog
http://www.growlingranger.com
Or subscribe to my RSS feed
http://www.growlingranger.com/?feed=rss2
*/
function isMobile() {
// Check the server headers to see if they're mobile friendly
if(isset($_SERVER["HTTP_X_WAP_PROFILE"])) {
return true;
}
// If the http_accept header supports wap then it's a mobile too
if(preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) {
return true;
}
// Still no luck? Let's have a look at the user agent on the browser. If it contains
// any of the following, it's probably a mobile device. Kappow!
if(isset($_SERVER["HTTP_USER_AGENT"])){
$user_agents = array("midp", "j2me", "avantg", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto");
foreach($user_agents as $user_string){
if(preg_match("/".$user_string."/i",$_SERVER["HTTP_USER_AGENT"])) {
return true;
}
}
}
// None of the above? Then it's probably not a mobile device.
return false;
}
// Here's our code to which calls the above function
if (isMobile()) {
// if the function returned true, it's a mobile.
// echo "mobile"; // delete this line in your code, and uncomment the next line
// include_once(DIR_WS_CLASSES . 'javapopup.php');
header('Location: /mysite/mobile/'); // let's redirect the page to the mobile site
} else {
header('Location: /');
}
// if not, we're in a standard browser and our page
// can proceed as normally formatted for the web!
// echo "web"; // delete this line in your code
// header('Location: ../'); // let's redirect the page to the mobile site
?>
I using the iMoblie script to run it, and it works fine, it will direct correctly, how ever, I also want my customer be able to go back to normal site to surfing( because some function my mobile site doesn`t has it).
I add this file under application_top.php
include_once(DIR_WS_CLASSES . 'isMobile.php');
now it will direct mobile site all the time. I was thinking about let the script expire each session, but it looks like does not really work, because the mobile phone browser does not really close each time you close the page.
Any ideal how to make it happen?
Thank you
ken









