PHP 에서 서버변수인 PHP_SELF, SCRIPT_NAME, REQUEST_URI 차이점 > 개발

본문 바로가기
사이트 내 전체검색

개발

PHP 에서 서버변수인 PHP_SELF, SCRIPT_NAME, REQUEST_URI 차이점

페이지 정보

profile_image
작성자 관리자 (61.♡.26.29)
댓글 0건 조회 3,314회 작성일 17-03-11 17:50

본문

PHP 에서 많이 사용하는 서버 변수들 중에서 아래 세가지 변수는 비슷한 값을 가진다.
$_SERVER['PHP_SELF']
$_SERVER['SCRIPT_NAME']
$_SERVER['REQUEST_URI']

하지만, 비슷하긴 해도 조금 복잡하게 들어가면 서로 다르다. 알아 보자.


Example 1. 요청된 URL 이 다음과 같을때:

http://example.com/test.php/foo/bar

[PHP_SELF] => /test.php/foo/bar
[SCRIPT_NAME] => /test.php
(this seems to be the only case when PATH_INFO contains sensible information [PATH_INFO] => /foo/bar) Note: this used to be different in some older PHP versions (<= 5.0 ?).



Example 2. REQUEST_URI 는 파라미터를 포함하고, SCRIPT_NAME 은 파라미터를 포함하지 않는다.:
http://example.com/test.php?foo=bar

[SCRIPT_NAME] => /test.php
[REQUEST_URI] => /test.php?foo=bar


Example 3. 서버측 리다이렉션이 동작했을 때 (for example mod_rewrite on apache):

http://example.com/test.php

[REQUEST_URI] => /test.php
[SCRIPT_NAME] => /test2.php


Example 4. REQUEST_URI is different from SCRIPT_NAME when handling HTTP errors with scripts.
Using apache directive ErrorDocument 404 /404error.php
http://example.com/test.php

[REQUEST_URI] => /test.php
[SCRIPT_NAME] => /404error.php
On IIS server using custom error pages
http://example.com/test.php

[SCRIPT_NAME] => /404error.php
[REQUEST_URI] => /404error.php?404;http://example.com/test.php

** 출처 : http://stackoverflow.com/questions/279966/php-self-vs-path-info-vs-script-name-vs-request-uri

추천0

댓글목록

등록된 댓글이 없습니다.

Total 392건 12 페이지
  • RSS
개발 목록
번호 제목 조회 추천 날짜
열람중3315003-11
1713315001-06
1703280003-28
1693257007-14
1683244005-07
1673234004-02
1663220001-15
1653200011-13
1643186012-01
1633177004-28
1623174006-29
1613102006-09
1603096005-08
1593096005-16
1583095007-26
1573088001-29
1563087005-08
1553065006-22
1543062005-11
1533059003-19

검색


사이트 정보

Copyright © Baragi.Net. All rights reserved.