Project / Support Center
Welcome, Guest. Please login or register. December 11, 2019, 04:10: PM
Home Help Search Login Register
D-Web Web Site Creator D - Web Web Site Creator On-line HTML Editor No Programming knowledge required. Web Global Net PayPal-Cart Shopping Cart System PayPal - Kart Shopping Cart System for E-Commerce over the internet, that's easy to use. Web Global Net Newsletter Manager Newsletter Manager On-line Newsletter Creator with Email Subscriber Management.
Ring Central Discount
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  Mobile Devices  |  Topic: Easy way to detect user devices php if then else 0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Send this topic Print
Author Topic: Easy way to detect user devices php if then else  (Read 2947 times)
admin
Administrator
******
Offline Offline

Posts: 168


« on: October 04, 2016, 07:22: PM »

This I think is the easiest way to detect what type of device is being used by a visitor to your site - we used it to display the correct Map app icon but it can be modified easily to fit your needs. this is a If then else statement.

<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac OS') !== false) {  
?>


the strpos searches the HTTP_USER_AGENT to determine what device is being used for the Filter you supply 'Mac OS' in this case.

a typical HTTP_USER_AGENT if echoed to your screen would look like this :

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4

by using the strpos it can search the entire HTTP_USER_AGENT string for what ever filter word you want.

Our examples below looked for Apple, Android & Windows to display the correct Map App icon and link


Code:
 
Macintosh Filter

<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac OS') !== false) {  
?>


------- display what ever you want based on the filter match here ------------
 <a href="maps://?q=<?php echo $row_rsclass_events['event_address']; ?> <?php echo $row_rsclass_events['event_city']; ?>, <?php echo $row_rsclass_events['event_zip']; ?><img src="../../assets/2016/ios-maps-icon.jpg" width="72" height="72" hspace="0" vspace="0" align="middle" /></a>
------- end display area  --------------------------------------

<?php
}
?>


Android Filter

<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Andriod') !== false) {
?>


<a href="geo://0,0?q=<?php echo $row_rsclass_events['event_address']; ?> <?php echo $row_rsclass_events['event_city']; ?>, <?php echo $row_rsclass_events['event_st']; ?> <?php echo $row_rsclass_events['event_zip']; ?>  <img src="../assets/2016/Maps-Android-R.png" width="72" height="72" hspace="5" vspace="5" /></a>

<?php
}
?>


Windows Filter

<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) {
?>


<a href="http://maps.google.com/?q=<?php echo $row_rsclass_events['event_address']; ?> <?php echo $row_rsclass_events['event_city']; ?>, <?php echo $row_rsclass_events['event_st']; ?> <?php echo $row_rsclass_events['event_zip']; ?>  " target="_blank"><img src="glovebox/code/images/map0-with-pin.png" width="72" height="72" hspace="5" vspace="5" /></a>

<?php
}
?>
« Last Edit: October 04, 2016, 07:33: PM by admin » Report to moderator   Logged

The Unknown Webmaster
Pages: [1] Go Up Send this topic Print 
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  Mobile Devices  |  Topic: Easy way to detect user devices php if then else « previous next »
Jump to:  


Login with username, password and session length
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!