平成30/ 2018-12-10 16:42
PHP $_SERVER /2017.01.19.00

###############################
# 他に、以下もあるのだが、サーバの設定次第で抽出されないケースがあるみたい。なので、あまり使わないようにする。
#

[SCRIPT_URL] => /demo/01/link/01.htm
[SCRIPT_URL] => /demo/01/link/


###############################
# print_r($_SERVER);
#
Array
(
    [HTTP_HOST] => example.com
    [HTTP_CONNECTION] => keep-alive
    [HTTP_REFERER] => http://example.com/
    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16
    [HTTP_ACCEPT] => application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch
    [HTTP_ACCEPT_LANGUAGE] => ja,en-US;q=0.8,en;q=0.6
    [HTTP_ACCEPT_CHARSET] => Shift_JIS,utf-8;q=0.7,*;q=0.3
    [PATH] => /sbin:/usr/sbin:/bin:/usr/bin
    [SERVER_SIGNATURE] =>
    [SERVER_SOFTWARE] => Apache
    [SERVER_NAME] => example.com
    [SERVER_ADDR] => 112.xx.xxx.xx
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 202.xxx.xx.x
    [DOCUMENT_ROOT] => /home/xxx/www/htdocs
    [SERVER_ADMIN] => admin@example.com
    [SCRIPT_FILENAME] => /home/xxx/www/htdocs/entry/index.html
    [REMOTE_PORT] => 99999
    [REMOTE_USER] => basicUser
    [AUTH_TYPE] => Basic
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => pid=8
    [REQUEST_URI] => /entry/?pid=8
    [SCRIPT_NAME] => /entry/index.html
    [PHP_SELF] => /entry/index.html
    [PHP_AUTH_USER] => basicUser
    [PHP_AUTH_PW] => basicPasswd
    [REQUEST_TIME] => 1301643733
)

直接サイト開いた場合、HTTP_REFERER の要素自体ないので、注意しよう。
つまり、
if(
isset($_SERVER["HTTP_REFERER")
){
が必要。