$_SERVER配列にセットされる情報は、Proxyサーバーを経由するかしないかで若干変わってくる。
Proxyサーバーを経由しない場合
- $_SERVER[‘REMOTE_ADDR’] – アクセス元のIPアドレス
- $_SERVER[‘SERVER_ADDR’] – WebサーバーのIPアドレス
しかし、Proxyサーバーを経由する場合
- $_SERVER[‘HTTP_X_FORWARDED_FOR’] – アクセス元のIPアドレス
- $_SERVER[‘REMOTE_ADDR’] – ProxyサーバーのIPアドレス
- $_SERVER[‘SERVER_ADDR’] – WebサーバーのIPアドレス
以下に、現在利用しているサーバー(Nginx)における$_SERVER配列をダンプしておく。
1 |
print_r($_SERVER); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
Array ( [SHLVL] => 2 [_] => /usr/bin/spawn-fcgi [TERM] => xterm [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin [LANG] => en_CA.UTF-8 [PWD] => / [PHP_FCGI_CHILDREN] => 16 [FCGI_ROLE] => RESPONDER [QUERY_STRING] => [REQUEST_METHOD] => GET [CONTENT_TYPE] => [CONTENT_LENGTH] => [SCRIPT_NAME] => /test/index.php [REQUEST_URI] => /test/ [DOCUMENT_URI] => /test/index.php [DOCUMENT_ROOT] => /home/httpd/html/mydomain.com [SERVER_PROTOCOL] => HTTP/1.1 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_SOFTWARE] => nginx/1.4.1 [REMOTE_ADDR] => xxx.xxx.xxx.xxx [REMOTE_PORT] => 33779 [SERVER_ADDR] => xxx.xxx.xxx.xxx [SERVER_PORT] => 80 [SERVER_NAME] => mydomain.com [REDIRECT_STATUS] => 200 [SCRIPT_FILENAME] => /home/httpd/html/mydomain.com/test/index.php [HTTP_HOST] => mydomain.com [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ACCEPT_LANGUAGE] => en-us [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_COOKIE] => PHPSESSID=xxxxxxxxxxxxxxxxxxxxxxxxxxxx [HTTP_X_FORWARDED_FOR] => xxx.xxx.xxx.xxx [HTTP_CONNECTION] => close [PHP_SELF] => /test/index.php [REQUEST_TIME] => 1406846236 ) |