λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
Lect & Tip/PHP & WordPress

✈php $_SERVER (μ„œλ²„ν•¨μˆ˜) 예제

by 낯선곡간2 2019. 7. 14.

λͺ©μ°¨

    php뿐만 μ•„λ‹ˆλΌ μ›Ήν”„λ‘œκ·Έλž˜λ°μ„ ν•˜λ‹€λ³΄λ©΄ μ„œλ²„ν™˜κ²½μ΄λ‚˜ μ‚¬μš©μžμ˜ μ‚¬μš©ν™˜κ²½ 정보λ₯Ό μ„œλ²„μ‚¬μ΄λ“œμ—μ„œ μˆ˜μ§‘ν•  ν•„μš”κ°€ μžˆμ„ λ•Œκ°€ μžˆλ‹€.

    phpμ—μ„œλ„ λ‹Ήμ—°νžˆ μ„œλ²„ν™˜κ²½μ΄λ‚˜ μ‚¬μš©μžν™˜κ²½ 예컨데 μ ‘μ†μžμ˜ μ•„μ΄ν”Όμ£Όμ†ŒλΌλ“ μ§€, 

    μžλ°”μŠ€ν¬λ¦½νŠΈμ˜ USER_Agent와 같은 정보듀을 μˆ˜μ§‘ν•  수 μžˆλŠ” ν•¨μˆ˜λ“€μ΄ λ§ˆλ ¨λ˜μ–΄ μžˆλ‹€.

    이λ₯Ό ν†΅μΉ­ν•΄μ„œ μ„œλ²„ν•¨μˆ˜λΌ μΉ­ν•˜κ³ 

    phpμ—μ„œλŠ” $_SERVER의 λ°°μ—΄ ν˜•νƒœλ‘œ μ“Έ 수 μžˆλ‹€.

    μ‚¬μš© μ˜ˆμ œλ“€μ€ λ‹€μŒκ³Ό κ°™λ‹€.

    μ‹€μ œ λ™μž‘ 데λͺ¨νŽ˜μ΄μ§€λŠ” 이 곳을 ν΄λ¦­.

    $_SERVER['DOCUMENT_ROOT'] = μ‚¬μ΄νŠΈκ°€ ν˜„μž¬ μœ„μΉ˜ν•œ μ„œλ²„μƒμ˜ 폴더 μœ„μΉ˜ = /home/hosting_users/rsl2_stspace/www

    $_SERVER['SCRIPT_FILENAME'] = μ‹€ν–‰λ˜κ³  μžˆλŠ” phpλ¬Έμ„œμ˜ μœ„μΉ˜μ™€ 파일λͺ… = /home/hosting_users/rsl2_stspace/www/port/demo/php/d_php_$_SERVER.php

    $_SERVER['SERVER_NAME'] = ν˜„μž¬ μ΄λ¬Έμ„œκ°€ 싀행쀑인 μ‚¬μ΄νŠΈ 도메인 = cafe75.kr

    $_SERVER['SERVER_PORT'] = μ‚¬μ΄νŠΈμ˜ μ›Ήμ„œλ²„κ°€ μ‚¬μš©ν•˜λŠ” 포트 = 80

    $_SERVER['SERVER_SOFTWARE'] = μ„œλ²„μΈ‘μ˜ μ†Œν”„νŠΈμ›¨μ–΄μ μΈ ν™˜κ²½ = Apache

    $_SERVER['GATEWAY_INTERFACE'] = μ„œλ²„μ˜ CGI 정보 = CGI/1.1

    $_SERVER['SERVER_PROTOCOL'] = μ‚¬μš©λœ μ›Ήμ„œλ²„μ˜ HTTP ν”„λ‘œν† μ½œ = HTTP/1.1

    $_SERVER['REQUEST_URI'] = ν˜„μž¬νŽ˜μ΄μ§€μ˜ μ£Όμ†Œμ—μ„œ 도메인을 μ œμ™Έν•œ 정보 = /port/demo/php/d_php_$_SERVER.php

    $_SERVER['PHP_SELF'] = ν˜„μž¬νŽ˜μ΄μ§€μ˜ μ£Όμ†Œμ—μ„œ 도메인과 λ„˜κ²¨μ§€λŠ” νŒŒλΌλ―Έν„° 값을 μ œμ™Έν•œ 정보 = /port/demo/php/d_php_$_SERVER.php

    $_SERVER['APPL_PHYSICAL_PATH'] = ν˜„μž¬ 싀행쀑인 νŽ˜μ΄μ§€μ˜ μ‹€μ œ 파일 경둜=

    $_SERVER['HTTP_ACCEPT_ENCODING'] = ν˜„μž¬ λ¬Έμ„œμ˜ 인코딩 방식 = gzip, deflate

    $_SERVER['HTTP_ACCEPT_LANGUAGE'] = ν˜„μž¬ λ¬Έμ„œμ˜ μ–Έμ–΄ = ko-KR

    $_SERVER['HTTP_USER_AGENT'] = μ‚¬μ΄νŠΈμ— μ ‘μ†ν•œ μ‚¬μš©μž ν™˜κ²½ = Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

    $_SERVER['REMOTE_ADDR'] = μ‚¬μ΄νŠΈ μ ‘μ†ν•œ μ‚¬μš©μž IP = 121.167.42.135

    μœ„ λ‚΄μš©μ˜ PHPμ†ŒμŠ€

    <p>&nbsp;</p>
    
    <p> $_SERVER['DOCUMENT_ROOT'] = μ‚¬μ΄νŠΈκ°€ ν˜„μž¬ μœ„μΉ˜ν•œ μ„œλ²„μƒμ˜ 폴더 μœ„μΉ˜ =
    
    <?=$_SERVER['DOCUMENT_ROOT']?>
    
    </p>
    
    <p> $_SERVER['SCRIPT_FILENAME'] = μ‹€ν–‰λ˜κ³  μžˆλŠ” phpλ¬Έμ„œμ˜ μœ„μΉ˜μ™€ 파일λͺ… =
    
    <?=$_SERVER['SCRIPT_FILENAME'] ?>
    
    </p>
    
    <p> $_SERVER['SERVER_NAME'] = ν˜„μž¬ μ΄λ¬Έμ„œκ°€ 싀행쀑인 μ‚¬μ΄νŠΈ 도메인 =
    
    <?=$_SERVER['SERVER_NAME']?>
    
    </p>
    
    <p> $_SERVER['SERVER_PORT'] = μ‚¬μ΄νŠΈμ˜ μ›Ήμ„œλ²„κ°€ μ‚¬μš©ν•˜λŠ” 포트 =
    
    <?=
    
    $_SERVER['SERVER_PORT']?>
    
    </p>
    
    <p> $_SERVER['SERVER_SOFTWARE'] = μ„œλ²„μΈ‘μ˜ μ†Œν”„νŠΈμ›¨μ–΄μ μΈ ν™˜κ²½ =
    
    <?=$_SERVER['SERVER_SOFTWARE']?>
    
    </p>
    
    <p> $_SERVER['GATEWAY_INTERFACE'] = μ„œλ²„μ˜ CGI 정보 =
    
    <?=$_SERVER['GATEWAY_INTERFACE']?>
    
    </p>
    
    <p> $_SERVER['SERVER_PROTOCOL'] = μ‚¬μš©λœ μ›Ήμ„œλ²„μ˜ HTTP ν”„λ‘œν† μ½œ =
    
    <?=$_SERVER['SERVER_PROTOCOL']?>
    
    </p>
    
    <p> $_SERVER['REQUEST_URI'] = ν˜„μž¬νŽ˜μ΄μ§€μ˜ μ£Όμ†Œμ—μ„œ 도메인을 μ œμ™Έν•œ 정보 =
    
    <?=$_SERVER['REQUEST_URI']?>
    
    </p>
    
    <p> $_SERVER['PHP_SELF'] = ν˜„μž¬νŽ˜μ΄μ§€μ˜ μ£Όμ†Œμ—μ„œ 도메인과 λ„˜κ²¨μ§€λŠ” νŒŒλΌλ―Έν„° 값을 μ œμ™Έν•œ 정보 =
    
    <?=$_SERVER['PHP_SELF']?>
    
    </p>
    
    <p> $_SERVER['APPL_PHYSICAL_PATH'] = ν˜„μž¬ 싀행쀑인 νŽ˜μ΄μ§€μ˜ μ‹€μ œ 파일 경둜=
    
    <?=$_SERVER['APPL_PHYSICAL_PATH']?>
    
    </p>
    
    <p> $_SERVER['HTTP_ACCEPT_ENCODING'] = ν˜„μž¬ λ¬Έμ„œμ˜ 인코딩 방식 =
    
    <?=$_SERVER['HTTP_ACCEPT_ENCODING']?>
    
    </p>
    
    <p> $_SERVER['HTTP_ACCEPT_LANGUAGE'] = ν˜„μž¬ λ¬Έμ„œμ˜ μ–Έμ–΄ =
    
    <?=$_SERVER['HTTP_ACCEPT_LANGUAGE']?>
    
    </p>
    
    <p> $_SERVER['HTTP_USER_AGENT'] = μ‚¬μ΄νŠΈμ— μ ‘μ†ν•œ μ‚¬μš©μž ν™˜κ²½ =
    
    <?=$_SERVER['HTTP_USER_AGENT']?>
    
    </p>
    
    <p> $_SERVER['REMOTE_ADDR'] = μ‚¬μ΄νŠΈ μ ‘μ†ν•œ μ‚¬μš©μž IP =
    
    <?=$_SERVER['REMOTE_ADDR']?>
    
    </p>
    
    <p>&nbsp;</p>

    지방

    λ°˜μ‘ν˜•

    λŒ“κΈ€