Title: Browser detection broken
Last modified: August 21, 2016

---

# Browser detection broken

 *  ResolvedPlugin Contributor [Greg Ross](https://wordpress.org/support/users/gregross/)
 * (@gregross)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/browser-detection-broken/)
 * I’m using Opera quite a bit on my site and found the plugin never detected Opera
   but instead classified it as “Unknown”.
 * The following code is in statistics.class.php:
 *     ```
       public function get_UserAgent() {
   
       			static $agent = null;
   
       			if ( empty($agent) ) {
       				$agent = $_SERVER['HTTP_USER_AGENT'];
   
       				if ( stripos($agent, 'Firefox') ) {
       					$agent = 'Firefox';
       				} elseif ( stripos($agent, 'MSIE') ) {
       					$agent = 'IE';
       				} elseif ( stripos($agent, 'iPad') ) {
       					$agent = 'Ipad';
       				} elseif ( stripos($agent, 'Android') ) {
       					$agent = 'Android';
       				} elseif ( stripos($agent, 'Chrome') ) {
       					$agent = 'Chrome';
       				} elseif ( stripos($agent, 'Opera') ) {
       					$agent = 'Opera';
       				} elseif ( stripos($agent, 'Safari') ) {
       					$agent = 'Safari';
       				} else {
       					$agent = 'unknown';
       				}
       			}
   
       			return $agent;
       		}
       ```
   
 * which is broken as stripos can return 0 which evals to false but is actually 
   returning the fact the string was found at the first position in the string.
 * Also, the check for $agent being empty is redundent as it was just set to null
   the line before. A working version of the function is as follows:
 *     ```
       public function get_UserAgent() {
       			$agent = $_SERVER['HTTP_USER_AGENT'];
   
       			if ( stripos($agent, 'Firefox') !== FALSE ) {
       				$agent = 'Firefox';
       			} elseif ( stripos($agent, 'MSIE') !== FALSE ) {
       				$agent = 'IE';
       			} elseif ( stripos($agent, 'iPad') !== FALSE ) {
       				$agent = 'Ipad';
       			} elseif ( stripos($agent, 'Android') !== FALSE ) {
       				$agent = 'Android';
       			} elseif ( stripos($agent, 'Chrome') !== FALSE ) {
       				$agent = 'Chrome';
       			} elseif ( stripos($agent, 'Opera') !== FALSE ) {
       				$agent = 'Opera';
       			} elseif ( stripos($agent, 'Safari') !== FALSE ) {
       				$agent = 'Safari';
       			} else {
       				$agent = 'unknown';
       			}
   
       			return $agent;
       		}
       ```
   
 * [http://wordpress.org/plugins/wp-statistics/](http://wordpress.org/plugins/wp-statistics/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Mostafa Soufi](https://wordpress.org/support/users/mostafas1990/)
 * (@mostafas1990)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/browser-detection-broken/#post-4312764)
 * Was transferred to the email.

Viewing 1 replies (of 1 total)

The topic ‘Browser detection broken’ is closed to new replies.

 * ![](https://ps.w.org/wp-statistics/assets/icon.svg?rev=3081064)
 * [WP Statistics – Simple, privacy-friendly Google Analytics alternative](https://wordpress.org/plugins/wp-statistics/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-statistics/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-statistics/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-statistics/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-statistics/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-statistics/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Mostafa Soufi](https://wordpress.org/support/users/mostafas1990/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/browser-detection-broken/#post-4312764)
 * Status: resolved