Return to Snippet

Revision: 44713
at June 12, 2011 05:57 by withinmedianl


Updated Code
$user_agent 	= $_SERVER['HTTP_USER_AGENT'];
$iphone 	= strpos($user_agent,"iPhone");
$ipod	 	= strpos($user_agent,"iPod");
$ipad 		= strpos($user_agent,"iPad");
$blackberry	= stristr($user_agent,"BlackBerry");
$android 	= strpos($user_agent,"Android");

if ($iphone || $ipod || $blackberry || $android)
{
   $browser = 'mobile phone';
   if($iphone) 		{$browser .= ' iphone';}
   if($ipod) 		{$browser .= ' ipod';}
   if($blackberry) 	{$browser .= ' blackberry';}
   if($android) 	{$browser .= ' android';}
}
else if($ipad)
{
   $browser = 'mobile tablet';
   $browser .= ' ipad';
}
else
{
   $browser = 'desktop';	
}


/*
To use in CSS:
<body class="<?php echo $browser ?>">
*/

Revision: 44712
at June 12, 2011 05:41 by withinmedianl


Updated Code
$user_agent 	= $_SERVER['HTTP_USER_AGENT'];
$iphone 	= strpos($user_agent,"iPhone");
$ipod	 	= strpos($user_agent,"iPod");
$ipad 		= strpos($user_agent,"iPad");
$blackberry	= stristr($user_agent,"BlackBerry");
$android 	= strpos($user_agent,"Android");

if ($iphone || $ipod || $blackberry || $android)
{
   $browser = 'mobile phone';
   if($iphone) 		{$browser .= ' iphone';}
   if($ipod) 		{$browser .= ' ipod';}
   if($blackberry) 	{$browser .= ' blackberry';}
   if($android) 	{$browser .= ' android';}
}
else if($ipad)
{
   $browser = 'mobile tablet';
   $browser .= ' ipad';
}
else
{
   $browser = 'desktop';	
}

Revision: 44711
at May 20, 2011 22:51 by withinmedianl


Updated Code
$user_agent 	= $_SERVER['HTTP_USER_AGENT'];
$iphone 	= strpos($user_agent,"iPhone");
$ipod	 	= strpos($user_agent,"iPod");
$ipad 		= strpos($user_agent,"iPad");
$blackberry	= strpos($user_agent,"BlackBerry");
$android 	= strpos($user_agent,"Android");

if ($iphone || $ipod || $blackberry || $android)
{
   $browser = 'mobile phone';
   if($iphone) 		{$browser .= ' iphone';}
   if($ipod) 		{$browser .= ' ipod';}
   if($blackberry) 	{$browser .= ' blackberry';}
   if($android) 	{$browser .= ' android';}
}
else if($ipad)
{
   $browser = 'mobile tablet';
   $browser .= ' ipad';
}
else
{
   $browser = 'desktop';	
}

Revision: 44710
at April 16, 2011 05:12 by withinmedianl


Initial Code
// PHP
$user_agent	= $_SERVER['HTTP_USER_AGENT'];
$iphone 	= strpos($user_agent,"iPhone");
$ipad 		= strpos($user_agent,"iPad");
$blackberry	= strpos($user_agent,"BlackBerry");
$android 	= strpos($user_agent,"Android");

if ($iphone || $ipad || $blackberry || $android)
{
   $browser = 'mobile';
   if($iphone) 		{$browser .= ' iphone';}
   if($ipad) 		{$browser .= ' ipad';}
   if($blackberry) 	{$browser .= ' blackberry';}
   if($android) 	{$browser .= ' android';}
}
else
{
   $browser = 'desktop';	
}


// HTML
<body class="<?php echo $browser ?>">

Initial URL

                                

Initial Description
Based upon http://csswizardry.com/2010/01/iphone-css-tips-for-building-iphone-websites/

Initial Title
Detect (mobile) browser and device

Initial Tags
mobile, iphone, android

Initial Language
PHP