Home arrow PHP arrow Page 3 - PHP Browser Detection and Appropriate CSS Generation
PHP

PHP Browser Detection and Appropriate CSS Generation


In this article, Tim explains his browser detection utility and how you can use it to generate the right CSS for each user.

Author Info:
By: Tim Perdue
Rating: 4 stars4 stars4 stars4 stars4 stars / 45
February 16, 2003
TABLE OF CONTENTS:
  1. · PHP Browser Detection and Appropriate CSS Generation
  2. · CSS Tips
  3. · Browser Detection Library
  4. · Font Size
  5. · Conclusion

print this article
SEARCH DEVARTICLES

PHP Browser Detection and Appropriate CSS Generation - Browser Detection Library
(Page 3 of 5 )

At any rate, here's my browser detection library. Just require() it at the top of your page and you'll be able to call the slick functions to generate browser-specific HTML.

<?php
//
// SourceForge: Breaking Down the Barriers to Open Source Development
// Copyright 1999-2000 (c) The SourceForge Crew
// http://sourceforge.net
//
// $Id: tim20000821.php3,v 1.2 2001/05/22 19:22:47 tim Exp $

unset ($BROWSER_AGENT);
unset ($BROWSER_VER);
unset ($BROWSER_PLATFORM);

function browser_get_agent () {
  global $BROWSER_AGENT;
  return $BROWSER_AGENT;
}

function browser_get_version() {
  global $BROWSER_VER;
  return $BROWSER_VER;
}

function browser_get_platform() {
  global $BROWSER_PLATFORM;
  return $BROWSER_PLATFORM;
}

function browser_is_mac() {
  if (browser_get_platform()=='Mac') {
    return true;
  } else {
    return false;
  }
}

function browser_is_windows() {
  if (browser_get_platform()=='Win') {
    return true;
  } else {
    return false;
  }
}

function browser_is_ie() {
  if (browser_get_agent()=='IE') {
    return true;
  } else {
    return false;
  }
}

function browser_is_netscape() {
  if (browser_get_agent()=='MOZILLA') {
    return true;
  } else {
    return false;
  }
}


/*
  Determine browser and version
*/


if (ereg( 'MSIE ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version)) {
  $BROWSER_VER=$log_version[1];
  $BROWSER_AGENT='IE';
} elseif (ereg( 'Opera ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version)) {
  $BROWSER_VER=$log_version[1];
  $BROWSER_AGENT='OPERA';
} elseif (ereg( 'Mozilla/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version)) {
  $BROWSER_VER=$log_version[1];
  $BROWSER_AGENT='MOZILLA';
} else {
  $BROWSER_VER=0;
  $BROWSER_AGENT='OTHER';
}

/*
  Determine platform
*/

if (strstr($HTTP_USER_AGENT,'Win')) {
  $BROWSER_PLATFORM='Win';
} else if (strstr($HTTP_USER_AGENT,'Mac')) {
  $BROWSER_PLATFORM='Mac';
} else if (strstr($HTTP_USER_AGENT,'Linux')) {
  $BROWSER_PLATFORM='Linux';
} else if (strstr($HTTP_USER_AGENT,'Unix')) {
  $BROWSER_PLATFORM='Unix';
} else {
  $BROWSER_PLATFORM='Other';
}

/*
//debug code
echo "\n\nAgent: $HTTP_USER_AGENT";
echo "\nIE: ".browser_is_ie();
echo "\nMac: ".browser_is_mac();
echo "\nWindows: ".browser_is_windows();
echo "\nPlatform: ".browser_get_platform();
echo "\nVersion: ".browser_get_version();
echo "\nAgent: ".browser_get_agent();
*/

?>

blog comments powered by Disqus
PHP ARTICLES

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials