Environmental Data in WordPress

For browser detection the WordPress also has global variables created. Below is an example that is showing how you can detect the user’s browser version in WordPress using global variables below the code:

<?php
global $is_lynx, $is_IE, $is_opera ,$is_gecko,$is_NS4,
$is_safari, $is_chrome, $is_iphone;
if ( $is_lynx ) {
echo “You are using Lynx”;
}elseif ( $is_gecko ) {
echo “You are using Firefox”;
}elseif ( $is_IE ) {
echo “You are using Internet Explorer”;
}elseif ( $is_opera ) {
echo “You are using Opera”;
}elseif ( $is_NS4 ) {
echo “You are using Netscape”;
}elseif ( $is_safari ) {
echo “You are using Safari”;
}elseif ( $is_chrome ) {
echo “You are using Chrome”;
}elseif ( $is_iphone ) {
echo “You are using an iPhone”;
}
?>

In wordpress this is very useful when designing a website that needs to include browser-specific tasks or functionality. The best and good to stick with web standards and degrade gracefully for lesser browsers, this can be very beneficial for in some circumstances.
For example, The $is_iphone variable to load a custom style sheet for iPhone web users you can use.
If the user or your site is on a mobile device, which could be a smartphone or tablet then the WordPress features another global variable to detect that is user on a mobile device. $is_mobile  is the global variable. There is a handy function available this is called wp_is_mobile() rather than calling this global variable directly from the code. wp_is_mobile() functions performance is to detect the mobile device which is using at that time.  When you are using a mobile device for browsing, then this function returns true; Otherwise return false as shown below:

if ( wp_is_mobile() ) {
echo “This website on a mobile device”;
}else{
echo “You are not on a mobile device”;
}

In the WordPress server information also stores that what type of web server this website is hosted by using the $is_apache  and $is_IIS global variables these check that which server you are using for your website hosting. Below is an example please see it:

<?php
global $is_apache, $is_IIS;
if ( $is_apache ) {
echo “web server is running Apache”;
}elseif ( $is_IIS ) {
echo “web server is running IIS”;
}
?>

The code can produce different results as you expecting because it depending that what type of web server a website you are using. As a good developer then you need to consider that your plugins and themes may be running on different web servers; so you might also need to check that what the user is running in order to accomplish specific tasks should performed.