20/09/2012, 08:41
|
| | Fecha de Ingreso: enero-2011 Ubicación: /root
Mensajes: 530
Antigüedad: 13 años, 10 meses Puntos: 61 | |
Respuesta: redireccion móvil puedes detectar si es movil usando este script , aunque hay muchos en internet , la logica seria si es distinto de movil redireccione a la web normal.
[HIGHLIGHT="PHP"]
function mobile_device_detect($iphone=true,$ipad=true,$andr oid=true,$opera=true,$blackberry=true,$palm=true,$ windows=true,$mobileredirect=false,$desktopredirec t=false){
$mobile_browser = false; // set mobile browser as false till we can prove otherwise
$user_agent = $_SERVER['HTTP_USER_AGENT']; // get the user agent value - this should be cleaned to ensure no nefarious input gets executed
$accept = $_SERVER['HTTP_ACCEPT']; // get the content accept value - this should be cleaned to ensure no nefarious input gets executed
switch(true){ // using a switch against the following statements which could return true is more efficient than the previous method of using if statements
case (preg_match('/ipad/i',$user_agent)); // we find the word ipad in the user agent
$mobile_browser = $ipad; // mobile browser is either true or false depending on the setting of ipad when calling the function
$status = 'Apple iPad';
if(substr($ipad,0,4)=='http'){ // does the value of ipad resemble a url
$mobileredirect = $ipad; // set the mobile redirect url to the url value stored in the ipad value
} // ends the if for ipad being a url
break; // break out and skip the rest if we've had a match on the ipad // this goes before the iphone to catch it else it would return on the iphone instead
case (preg_match('/ipod/i',$user_agent)||preg_match('/iphone/i',$user_agent)); // we find the words iphone or ipod in the user agent
$mobile_browser = $iphone; // mobile browser is either true or false depending on the setting of iphone when calling the function
$status = 'Apple';
if(substr($iphone,0,4)=='http'){ // does the value of iphone resemble a url
$mobileredirect = $iphone; // set the mobile redirect url to the url value stored in the iphone value
} // ends the if for iphone being a url
break; // break out and skip the rest if we've had a match on the iphone or ipod
case (preg_match('/android/i',$user_agent)); // we find android in the user agent
$mobile_browser = $android; // mobile browser is either true or false depending on the setting of android when calling the function
$status = 'Android';
if(substr($android,0,4)=='http'){ // does the value of android resemble a url
$mobileredirect = $android; // set the mobile redirect url to the url value stored in the android value
} // ends the if for android being a url
break; // break out and skip the rest if we've had a match on android
case (preg_match('/opera mini/i',$user_agent)); // we find opera mini in the user agent
$mobile_browser = $opera; // mobile browser is either true or false depending on the setting of opera when calling the function
$status = 'Opera';
if(substr($opera,0,4)=='http'){ // does the value of opera resemble a rul
$mobileredirect = $opera; // set the mobile redirect url to the url value stored in the opera value
} // ends the if for opera being a url
break; // break out and skip the rest if we've had a match on opera
case (preg_match('/blackberry/i',$user_agent)); // we find blackberry in the user agent
$mobile_browser = $blackberry; // mobile browser is either true or false depending on the setting of blackberry when calling the function
$status = 'Blackberry';
if(substr($blackberry,0,4)=='http'){ // does the value of blackberry resemble a rul
$mobileredirect = $blackberry; // set the mobile redirect url to the url value stored in the blackberry value
} // ends the if for blackberry being a url
break; // break out and skip the rest if we've had a match on blackberry
case (preg_match('/(pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine )/i',$user_agent)); // we find palm os in the user agent - the i at the end makes it case insensitive
$mobile_browser = $palm; // mobile browser is either true or false depending on the setting of palm when calling the function
$status = 'Palm';
if(substr($palm,0,4)=='http'){ // does the value of palm resemble a rul
$mobileredirect = $palm; // set the mobile redirect url to the url value stored in the palm value
} // ends the if for palm being a url
break; // break out and skip the rest if we've had a match on palm os
case (preg_match('/(iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)/i',$user_agent)); // we find windows mobile in the user agent - the i at the end makes it case insensitive
$mobile_browser = $windows; // mobile browser is either true or false depending on the setting of windows when calling the function
$status = 'Windows Smartphone';
if(substr($windows,0,4)=='http'){ // does the value of windows resemble a rul
$mobileredirect = $windows; // set the mobile redirect url to the url value stored in the windows value
} // ends the if for windows being a url
break; // break out and skip the rest if we've had a match on windows
case (preg_match('/(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg84 0|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl90 0|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|sa mu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500f oma:|160x|x160|480x|x640|t503|w839|i250|sprint|w39 8samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|tel eca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|m yx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartp hone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp |treo)/i',$user_agent)); // check if any of the values listed create a match on the user agent - these are some of the most common terms used in agents to identify them as being mobile devices - the i at the end makes it case insensitive
$mobile_browser = true; // set mobile browser to true
$status = 'Mobile matched on piped preg_match';
break; // break out and skip the rest if we've preg_match on the user agent returned true
case ((strpos($accept,'text/vnd.wap.wml')>0)||(strpos($accept,'application/vnd.wap.xhtml+xml')>0)); // is the device showing signs of support for text/vnd.wap.wml or application/vnd.wap.xhtml+xml
$mobile_browser = true; // set mobile browser to true
$status = 'Mobile matched on content accept header';
break; // break out and skip the rest if we've had a match on the content accept headers |