Find the user-agent

 
Post new topic   Reply to topic    PHP User Group Malta Forum Index // Links to PHP Good Tutorials
View previous topic :: View next topic  
Author Message
yancho
Site Admin


Joined: 13 Nov 2007
Posts: 56
Location: Iklin

PostPosted: Wed Jan 16, 2008 12:55 pm    Post subject: Find the user-agent Reply with quote

 If you want to find if your user is using a mobile browser or not you can use this function :

php:

function checkmobile ($opp$uap$acp) {
  
$isMobile false;

  
$op strtolower($opp);
  
$ua strtolower($uap);
  
$ac strtolower($acp);
  
$ip $ipp;

$isMobile strpos($ac'application/vnd.wap.xhtml+xml') !== false
        
|| $op != ''
        
|| strpos($ua'sony') !== false 
        
|| strpos($ua'symbian') !== false 
        
|| strpos($ua'nokia') !== false 
        
|| strpos($ua'samsung') !== false 
        
|| strpos($ua'mobile') !== false
        
|| strpos($ua'windows ce') !== false
        
|| strpos($ua'epoc') !== false
        
|| strpos($ua'opera mini') !== false
        
|| strpos($ua'nitro') !== false
        
|| strpos($ua'j2me') !== false
        
|| strpos($ua'midp-') !== false
        
|| strpos($ua'cldc-') !== false
        
|| strpos($ua'netfront') !== false
        
|| strpos($ua'mot') !== false
        
|| strpos($ua'up.browser') !== false
        
|| strpos($ua'up.link') !== false
        
|| strpos($ua'audiovox') !== false
        
|| strpos($ua'blackberry') !== false
        
|| strpos($ua'ericsson,') !== false
        
|| strpos($ua'panasonic') !== false
        
|| strpos($ua'philips') !== false
        
|| strpos($ua'sanyo') !== false
        
|| strpos($ua'sharp') !== false
        
|| strpos($ua'sie-') !== false
        
|| strpos($ua'portalmmm') !== false
        
|| strpos($ua'blazer') !== false
        
|| strpos($ua'avantgo') !== false
        
|| strpos($ua'danger') !== false
        
|| strpos($ua'palm') !== false
        
|| strpos($ua'series60') !== false
        
|| strpos($ua'palmsource') !== false
        
|| strpos($ua'pocketpc') !== false
        
|| strpos($ua'smartphone') !== false
        
|| strpos($ua'rover') !== false
        
|| strpos($ua'ipaq') !== false
        
|| strpos($ua'au-mic,') !== false
        
|| strpos($ua'alcatel') !== false
        
|| strpos($ua'ericy') !== false
        
|| strpos($ua'up.link') !== false
        
|| strpos($ua'vodafone/') !== false
        
|| strpos($ua'wap1.') !== false
        
|| strpos($ua'wap2.') !== false;


    return 
$isMobile;
}
?>


and this is an example how I am using it .. you can use it to redirect to another page :

php:
<?
$op 
$_SERVER['HTTP_X_OPERAMINI_PHONE'];
      
$ua $_SERVER['HTTP_USER_AGENT'];
      
$ac $_SERVER['HTTP_ACCEPT'];
      if(
checkmobile($op$ua$ac)){
          
setcookie("environment""mobile",  time()+60*60*24*7);
          
setcookie("user_agent"$uatime()+60*60*24*7);
      }
      
      else {
          
setcookie("environment""desktop",  time()+60*60*24*7);
          
setcookie("user_agent"$uatime()+60*60*24*7);
      }   


This script was adapted from : http://www.russellbeattie.com/blog/mobile-browser-detection-in-php <- in his script you also can find how to detect for a Search Bot

Here is a script to detect the Operating system from the user agent : http://www.geekpedia.com/code47_Detect-operating-system-from-user-agent-string.html

Here is a list of all the recorded user agents : http://www.user-agents.org/ or the list in xml format : http://www.user-agents.org/allagents.xml

Here is a list (in case you need exect agent) of all the mobile devices agents : http://www.zytrax.com/tech/web/mobile_ids.html


Hope you find this info useful Smile


_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Post new topic   Reply to topic    PHP User Group Malta Forum Index // Links to PHP Good Tutorials All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

alexisRed v1.2 // Theme Created By: Andrew Charron and Web Hosting Bluebook // Icons in Part By: Travis Carden
Boards optimised using the phpBB-SEO mod found at phpbb-seo.com
Boards hosted courtesy of solutions-lab.net
Link Backs : PHPClasses.org - MT Page :: PHPUsergroups.org - MT Page



Powered by phpBB © 2001, 2002 phpBB Group