fork download
  1. <?php
  2.  
  3. /**
  4.  * FILE: Detector.php
  5.  *
  6.  * @AUTHOR: LTD shalvasoft
  7.  * @AUTHOR: Shalva Kvaratskhelia
  8.  * PROJECT: Georgia Express
  9.  * VERSION: 1.0.0
  10.  */
  11.  
  12. class Detector{
  13.  
  14. /**
  15.   * @return string
  16.   */
  17. public static function getProtocol(){
  18. if(isset($_SERVER['REQUEST_SCHEME'])) {
  19. return $_SERVER['REQUEST_SCHEME'];
  20. }else{
  21. $isSecure = false;
  22. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
  23. $isSecure = true;
  24. }
  25. elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
  26. $isSecure = true;
  27. }
  28. return $isSecure ? 'https' : 'http';
  29. }
  30. }
  31.  
  32. /**
  33.   * @param bool|false $allowProxy
  34.   * @return string
  35.   */
  36. public static function getLocalHost($allowProxy = false){
  37. if (true === $allowProxy) {
  38. if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])
  39. && !empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
  40. $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
  41. if (strpos($host, ',') !== false) {
  42. $hosts = explode(',', $host);
  43. $host = trim(array_pop($hosts));
  44. }
  45. if (!empty($host)) {
  46. return $host;
  47. }
  48. }
  49. }
  50. if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
  51. if (isset($_SERVER['SERVER_PORT'])) {
  52. $portStr = ':' . $_SERVER['SERVER_PORT'];
  53. if (substr($_SERVER['HTTP_HOST'], 0 - strlen($portStr),
  54. strlen($portStr)) == $portStr) {
  55. return substr($_SERVER['HTTP_HOST'], 0, 0-strlen($portStr));
  56. }
  57. }
  58. return $_SERVER['HTTP_HOST'];
  59. }
  60. if (!isset($_SERVER['SERVER_NAME']) || !isset($_SERVER['SERVER_PORT'])) {
  61. return '';
  62. }
  63. return $_SERVER['SERVER_NAME'];
  64. }
  65.  
  66. /**
  67.   * @return bool
  68.   */
  69. public static function getHttps() {
  70. $https = null;
  71. if (isset($_SERVER['HTTPS'])) {
  72. $https = strtolower($_SERVER['HTTPS']);
  73. if ($https == 'on' || $https == '1') {
  74. return true;
  75. }
  76. }
  77. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
  78. $https = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']);
  79. if ($https == 'https') {
  80. return true;
  81. }
  82. }
  83. if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') {
  84. return true;
  85. }
  86. return false;
  87. }
  88. }
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Standard output is empty