PHP $_SEVER를 이용한 서버, 웹 주소 정보 가져오기
1. $_SERVER 를 이용하여 웹 주소 정보 가져오기
$hostname=$_SERVER["SERVER_NAME"]; // sever 정보 ex) www.codebalck.net
$hostname2=$_SERVER["HTTP_HOST"]; // host 정보 ex) www.codebalck.net
$uri= $_SERVER["REQUEST_URI"]; // uri 정보 ex) /2015/05/php-sever.html
2. $_SERVER 주요 속성(elements)
What revision of the CGI specification the server is using; i.e. 'CGI/1.1'.
The IP address of the server under which the current script is executing.
The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.
Server identification string, given in the headers when responding to requests.
Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0';
Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.
The timestamp of the start of the request. Available since PHP 5.1.0.
The timestamp of the start of the request, with microsecond precision. Available since PHP 5.4.0.
The query string, if any, via which the page was accessed.
The document root directory under which the current script is executing, as defined in the server's configuration file.
Contents of the Accept: header from the current request, if there is one.
Contents of the Accept-Charset: header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'.
Contents of the Accept-Encoding: header from the current request, if there is one. Example: 'gzip'.
Contents of the Accept-Language: header from the current request, if there is one. Example: 'en'.
Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive'.
Contents of the Host: header from the current request, if there is one.
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
Contents of the User-Agent: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). Among other things, you can use this value with get_browser() to tailor your page's output to the capabilities of the user agent.