Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Dylan Lopez
Added: Jan 30, 2018 7:47 AM
Views: 18
$this->load->library('user_agent');
https://www.codeigniter.com/user_guide/libraries/user_agent.html#id3
  1. $this->load->library('user_agent');
  2.  
  3. if ($this->agent->is_browser())
  4. {
  5.         $agent = $this->agent->browser().' '.$this->agent->version();
  6. }
  7. elseif ($this->agent->is_robot())
  8. {
  9.         $agent = $this->agent->robot();
  10. }
  11. elseif ($this->agent->is_mobile())
  12. {
  13.         $agent = $this->agent->mobile();
  14. }
  15. else
  16. {
  17.         $agent = 'Unidentified User Agent';
  18. }
  19.  
  20. echo $agent;
  21.  
  22. echo $this->agent->platform(); // Platform info (Windows, Linux, Mac, etc.)
  23.  
  24. //List of methods
  25. $this->agent->is_browser('Safari');
  26. $this->agent->is_mobile('iphone');
  27. $this->agent->is_robot();
  28. $this->agent->is_referral;
  29. $this->agent->browser;
  30. $this->agent->version;
  31. $this->agent->mobile;
  32. $this->agent->robot;
  33. $this->agent->platform;
  34. $this->agent->referrer;
  35. $this->agent->agent_string;
  36. $this->agent->accept_lang;
  37. $this->agent->languages;
  38. $this->agent->accept_charset;
  39. $this->agent->charsets;
  40.  
  41. //Parses a custom user-agent string, different from the one reported by the current visitor.
  42. $this->agent->parse($string);
  43.