Check if PHP-page is accessed from an iOS device Check if PHP-page is accessed from an iOS device ios ios

Check if PHP-page is accessed from an iOS device


Use the user agent from $_SERVER['HTTP_USER_AGENT'], and for simple detection you can use this script:

<?php//Detect special conditions devices$iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");$iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");$iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");$webOS   = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");//do something with this informationif( $iPod || $iPhone ){    //browser reported as an iPhone/iPod touch -- do something here}else if($iPad){    //browser reported as an iPad -- do something here}else if($Android){    //browser reported as an Android device -- do something here}else if($webOS){    //browser reported as a webOS device -- do something here}?> 

If you want to know more details of the user device I recommended to use one of the following solutions: http://51degrees.mobi or http://deviceatlas.com


preg_match("/iPhone|Android|iPad|iPod|webOS/", $_SERVER['HTTP_USER_AGENT'], $matches);$os = current($matches);switch($os){   case 'iPhone': /*do something...*/ break;   case 'Android': /*do something...*/ break;   case 'iPad': /*do something...*/ break;   case 'iPod': /*do something...*/ break;   case 'webOS': /*do something...*/ break;}


function user_agent(){    $iPod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");    $iPhone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");    $iPad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");    $android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");    file_put_contents('./public/upload/install_log/agent',$_SERVER['HTTP_USER_AGENT']);    if($iPad||$iPhone||$iPod){        return 'ios';    }else if($android){        return 'android';    }else{        return 'pc';    }}