Posted By

xylude on 06/15/11


Tagged

mobile android ios


Versions (?)

thisDevice()


 / Published in: PHP
 

  1. function thisDevice() {
  2. $useragent=$_SERVER['HTTP_USER_AGENT'];
  3. if(substr_count($useragent,'iPad')>0) {
  4. $device['specific'] = 'iPad';
  5. $device['general'] = 'tablet';
  6. $device['vague'] = 'mobile';
  7. } else if(substr_count($useragent,'iPhone')>0||substr_count($useragent,'iPod')>0) {
  8. $device['specific'] = 'iPhone';
  9. $device['general'] = 'phone';
  10. $device['vague'] = 'mobile';
  11. } else if(substr_count($useragent,'Android')>0) {
  12. if(substr_count($useragent,'Mobile')>0) {
  13. $device['specific'] = 'droidPhone';
  14. $device['general'] = 'phone';
  15. $device['vague'] = 'mobile';
  16. } else {
  17. $device['specific'] = 'droidTab';
  18. $device['general'] = 'tablet';
  19. $device['vague'] = 'mobile';
  20. }
  21. } else {
  22. $device['specific'] = 'unknown';
  23. $device['general'] = 'unknown';
  24. $device['vague'] = 'unknown';
  25. }
  26. return $device;
  27. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: xylude on June 15, 2011

Returns an array of information on whether the device requesting the page is an ipod/iphone, android phone, ipad or android tablet.

You need to login to post a comment.