HttpServer.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/6/11
  6. * Time: 上午9:28
  7. */
  8. namespace common\api;
  9. use Yii;
  10. use yii\base\Component;
  11. class HttpServer extends Component{
  12. public function GetCurUrl()
  13. {
  14. $url='http://';
  15. if(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on'){
  16. $url='https://';
  17. }
  18. if($_SERVER['SERVER_PORT']!='80'){
  19. $url.=$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
  20. }else{
  21. $url.=$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  22. }
  23. return $url;
  24. }
  25. public function GetReferer()
  26. {
  27. if (!empty($_SERVER['HTTP_REFERER'])) {
  28. return $_SERVER['HTTP_REFERER'];
  29. }
  30. }
  31. function getAgentInfo()
  32. {
  33. if (!empty($_SERVER['HTTP_USER_AGENT'])) {
  34. $OS = $_SERVER['HTTP_USER_AGENT'];
  35. if (preg_match('/win/i', $OS)) {
  36. $OS = 'Windows';
  37. } elseif (preg_match('/mac/i', $OS)) {
  38. $OS = 'MAC';
  39. } elseif (preg_match('/linux/i', $OS)) {
  40. $OS = 'Linux';
  41. } elseif (preg_match('/unix/i', $OS)) {
  42. $OS = 'Unix';
  43. } elseif (preg_match('/bsd/i', $OS)) {
  44. $OS = 'BSD';
  45. } else {
  46. $OS = 'Other';
  47. }
  48. return $OS;
  49. } else {
  50. return "unknown";
  51. }
  52. }
  53. }