W3LABKR

고정 헤더 영역

글 제목

메뉴 레이어

W3LABKR

메뉴 리스트

  • 홈
  • 태그
  • 방명록
  • 분류 전체보기 (6)
    • Code Snippets (5)
      • HTML (0)
      • CSS (0)
      • Javascript (2)
      • jQuery (0)
      • ReactJS (0)
      • NodeJS (1)
      • PHP (2)
      • Python (0)
      • ShellScript (0)
      • WordPress (0)
      • Git (0)
    • Tools (1)
      • VisualStudioCode (1)
      • SublimeText3 (0)
    • Cloud Computing Services (0)
      • AmazonWebService (0)
      • GoogleCloudPlatform (0)
      • NaverCloudPlatform (0)
홈태그방명록
  • Code Snippets 5
    • HTML 0
    • CSS 0
    • Javascript 2
    • jQuery 0
    • ReactJS 0
    • NodeJS 1
    • PHP 2
    • Python 0
    • ShellScript 0
    • WordPress 0
    • Git 0
  • Tools 1
    • VisualStudioCode 1
    • SublimeText3 0
  • Cloud Computing Services 0
    • AmazonWebService 0
    • GoogleCloudPlatform 0
    • NaverCloudPlatform 0

검색 레이어

W3LABKR

검색 영역

컨텐츠 검색

Code Snippets/PHP

  • How to get subdomain URL

    2021.12.09 by w3labkr

  • How to get site URL protocol?

    2021.12.09 by w3labkr

How to get subdomain URL

Here's a one-liner to get the subdomain: $subdomain = join('.', explode('.', $_SERVER['HTTP_HOST'], -2)) explode with the limit parameter of -2 will split the string on each dot, ignoring the last two elements. If there are two or fewer elements, it returns an empty array. join will assemble the resulting array back into a dot delimited string. In case you have multiple subdomains set, e.g. foo...

Code Snippets/PHP 2021. 12. 9. 07:52

How to get site URL protocol?

Notes: you should look also for HTTP_X_FORWARDED_PROTO (e.g. if proxy server) relying on 443 port is not safe (https could be served on different port) REQUEST_SCHEME not reliable if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { $protocol = 'https'; } else { $prot..

Code Snippets/PHP 2021. 12. 9. 07:51

추가 정보

인기글

최신글

페이징

이전
1
다음
TISTORY
W3LABKR © Magazine Lab
페이스북 트위터 인스타그램 유투브 메일

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.