Advertisement
Guest User

Untitled

a guest
Sep 7th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1. <?php
  2.  
  3. $mobile_browser = '0';
  4.  
  5. if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
  6.     $mobile_browser++;
  7. }
  8.  
  9. if ((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > 0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {
  10.     $mobile_browser++;
  11. }    
  12.  
  13. $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));
  14. $mobile_agents = array(
  15.     'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
  16.     'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
  17.     'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
  18.     'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
  19.     'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
  20.     'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
  21.     'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
  22.     'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
  23.     'wapr','webc','winw','winw','xda ','xda-');
  24.  
  25. if (in_array($mobile_ua,$mobile_agents)) {
  26.     $mobile_browser++;
  27. }
  28.  
  29. if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini') > 0) {
  30.     $mobile_browser++;
  31. }
  32.  
  33. if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows') > 0) {
  34.     $mobile_browser = 0;
  35. }
  36.  
  37. if ($mobile_browser > 0) {
  38.    // do nothing, the visitor is using a mobile device
  39. }
  40. else {
  41.    // display ads, the visitor is using a desktop device
  42. ?>
  43.  
  44. <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
  45. <!-- Blog Ads -->
  46. <ins class="adsbygoogle"
  47.      style="display:block"
  48.      data-ad-client="ca-pub-6499641812401649"
  49.      data-ad-slot="6954990402"
  50.      data-ad-format="auto"></ins>
  51. <script>
  52. (adsbygoogle = window.adsbygoogle || []).push({});
  53. </script>
  54.  
  55. <?php
  56. }  
  57.  
  58. ?>
  59. </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement