If you can't detect if a visitor is using a mobile phone, you can't feed them information that's tailored to them.
Here's an article that suggests some code to accomplish the task.
NOTE: There's a specific implementation for using this with the Website Membership Plugin (through v 1.05) later in this recipe.
http://azure.ironie.org/478-php-mobile-phone-detection
And here's the code that they suggest:
The function:
<?php function mobile_detection () { if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) return true; if (isset ($_SERVER['HTTP_ACCEPT'])) { $accept = strtolower($_SERVER['HTTP_ACCEPT']); if (strpos($accept, 'wap') !== false) return true; }
if (isset ($_SERVER['HTTP_USER_AGENT'])) { if (strpos ($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false) return true;
if (strpos ($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false) return true; if (strpos ($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false) return true; if (strpos ($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false) return true; if (strpos ($_SERVER['HTTP_USER_AGENT'], 'Tablet') !== false) return true; } return false; } ?>
And the implementation
<?php if (!isset ($_SESSION['mobile'])) $_SESSION['mobile'] = mobile_detection(); if ($_SESSION['mobile'] == true) echo '<link rel="stylesheet" type="text/css" href="style/version-mobile.css" /> <meta name="HandheldFriendly" content="true" /> <meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0, maximum-scale=3.0, minimum-scale=0.25" />';
?>
You can use this concept to replace any code. Here's an implementation to replace a flash .swf masthead with a .png
*** NOTE: this implementation t works with the Website Membership Plugin through V1.05 *** Currently, if Website Membership Plugin V1.06 is used, redirect to login does not redirect the user to the calling page. If anyone solves this, please pass the information on so I can update this recipe.
<?php if (mobile_detection()) : ?>
<img src="images/masthead.png" width="800" height="183" />
<?PHP else: ?>
<script type='text/javascript'> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0','height','180','width','100%','pluginspage', 'http://www.macromedia.com/go/getflashplayer','src','images/masthead','wmode','transparent','quality','best','play','true','movie','images/masthead' ); </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="180" width="100%"> <param name="movie" value="images/masthead.swf" /> <param name="quality" value="best" /> <param name="play" value="true" /> <param name="wmode" value="transparent" /> <embed height="188" pluginspage="http://www.macromedia.com/go/getflashplayer" src="images/masthead.swf" type="application/x-shockwave-flash" width="100%" wmode="transparent" quality="best" play="true"></embed> </object></noscript> <?PHP endif ?>
The article goes further to describe the reasons for this particular code,
Here's an implementation that chooses between viewers:
<?php $_SESSION['mobile'] = mobile_detection(); ?> <?php if (!isset ($_SESSION['mobile']) OR $_SESSION['mobile'] == true) : ?>your_file_for_tablet.php?<?php echo $record['num'] ?><?php else: ?>tour_file_for computer.php?<?php echo $record['num'] ?><? endif?>"><span class="sub_heading_font"> Your Text</span></a>
There's also an article describing the meta tags used for mobile phones at:
http://learnthemobileweb.com/2009/07/mobile-meta-tags/
|