Title: function/method for mobile detect consistent with its .htaccess rules
Last modified: August 30, 2016

---

# function/method for mobile detect consistent with its .htaccess rules

 *  [DrLightman](https://wordpress.org/support/users/drlightman/)
 * (@drlightman)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/functionmethod-for-mobile-detect-consistent-with-its-htaccess-rules/)
 * Basically I want to diplay different ads for mobile/desktop and I want them cached.
 * So rather than using a third party library to make the detection (as per Mobile_Detect
   or wp_is_mobile), I’d rather stick with the very same mobile detection that this
   wpsc plugin uses, with the .htaccess rules, in order to avoid possible miscachings.
 * Is there any wpsc function I can use to do this test? Anything like this would
   be perfect:
 *     ```
       if( function_exists( 'wpsc_is_mobile' ) ) {
       	if( wpsc_is_mobile( ) ) {
       		// mobile
       	} else {
       		// desktop
       	}
       }
       ```
   
 * Thanks.
 * [https://wordpress.org/plugins/wp-super-cache/](https://wordpress.org/plugins/wp-super-cache/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [DrLightman](https://wordpress.org/support/users/drlightman/)
 * (@drlightman)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/functionmethod-for-mobile-detect-consistent-with-its-htaccess-rules/#post-6751893)
 * Hate to do this, but: bump.
 *  Thread Starter [DrLightman](https://wordpress.org/support/users/drlightman/)
 * (@drlightman)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/functionmethod-for-mobile-detect-consistent-with-its-htaccess-rules/#post-6751934)
 * I hope Donncha will read this eventually before I dig into the source :v
 *  Thread Starter [DrLightman](https://wordpress.org/support/users/drlightman/)
 * (@drlightman)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/functionmethod-for-mobile-detect-consistent-with-its-htaccess-rules/#post-6751937)
 * Ok I made a function based on wpsc source code, Donncha can you fast check if
   it may work? I think it does:
 *     ```
       static function __wpsc_is_mobile( )
       	{
       		global $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
       		$browsers = explode( ',', $wp_cache_mobile_browsers );
       		$user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
       		foreach ($browsers as $browser) {
       			if ( strstr( $user_agent, trim( strtolower( $browser ) ) ) ) {
       				return true;
       			}
       		}
       		if (isset($_SERVER['HTTP_X_WAP_PROFILE']) )
       			return true;
       		if (isset($_SERVER['HTTP_PROFILE']) )
       			return true;
   
       		if ( isset( $wp_cache_mobile_prefixes ) ) {
       			$browsers = explode( ',', $wp_cache_mobile_prefixes );
       			foreach ($browsers as $browser_prefix) {
       				if ( substr($user_agent, 0, 4) == $browser_prefix ) {
       					return true;
       				}
       			}
       		}
       		$accept = isset( $_SERVER[ 'HTTP_ACCEPT' ] ) ? strtolower( $_SERVER[ 'HTTP_ACCEPT' ] ) : '';
       		if (strpos($accept, 'wap') !== false) {
       			return true;
       		}
       		if (isset($_SERVER['ALL_HTTP']) && strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false) {
       			return true;
       		}
       		return false;
       	}
       ```
   
 * protip: it doesnt check if the two global wpsc vars are set, im doing it in another
   function.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘function/method for mobile detect consistent with its .htaccess rules’
is closed to new replies.

 * ![](https://ps.w.org/wp-super-cache/assets/icon-256x256.png?rev=3506220)
 * [WP Super Cache](https://wordpress.org/plugins/wp-super-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-super-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-super-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-super-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-super-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-super-cache/reviews/)

## Tags

 * [detect](https://wordpress.org/support/topic-tag/detect/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [mobile](https://wordpress.org/support/topic-tag/mobile/)

 * 3 replies
 * 1 participant
 * Last reply from: [DrLightman](https://wordpress.org/support/users/drlightman/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/functionmethod-for-mobile-detect-consistent-with-its-htaccess-rules/#post-6751937)
 * Status: not resolved