PHP $_SERVER

array:84 [
  "PATH" => "C:\Windows\system32;"
  "SYSTEMROOT" => "C:\Windows"
  "COMSPEC" => "C:\Windows\system32\cmd.exe"
  "PATHEXT" => ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
  "WINDIR" => "C:\Windows"
  "PHP_FCGI_MAX_REQUESTS" => "1000"
  "PHPRC" => "D:/phpStudynews/PHPTutorial/php/php-7.2.1-nts/"
  "_FCGI_SHUTDOWN_EVENT_" => "2036"
  "SCRIPT_NAME" => "/index.php"                                                                                                    //当前脚本路径
  "REQUEST_URI" => "/api/v2/pm/update?company_name=dfafasdfds%20&id=35"                    //访问的页面URI,包含查询字符串
  "QUERY_STRING" => "company_name=dfafasdfds&id=35"                                                        //查询字符串,不存在为" "
  "REQUEST_METHOD" => "PATCH"                                                                                               //请求方法,如"POST"、"PUT"等
  "SERVER_PROTOCOL" => "HTTP/1.1"                                                                                         //通信协议的名称和版本
  "GATEWAY_INTERFACE" => "CGI/1.1"                                                                                      //服务器使用的CGI 规范的版本
  "REDIRECT_QUERY_STRING" => "company_name=dfafasdfds&id=35"
  "REDIRECT_URL" => "/api/v2/pm/update"
  "REMOTE_PORT" => "61517"                                                                                                     //用户连接服务器使用的端口
  "SCRIPT_FILENAME" => "D:/phpStudynews/PHPTutorial/WWW/faceke/public/index.php"      //当前脚本的绝对路径
  "SERVER_ADMIN" => "[email protected]"
  "CONTEXT_DOCUMENT_ROOT" => "D:/phpStudynews/PHPTutorial/WWW/faceke/public"    
  "CONTEXT_PREFIX" => ""
  "REQUEST_SCHEME" => "http"
  "DOCUMENT_ROOT" => "D:/phpStudynews/PHPTutorial/WWW/faceke/public"               //当前脚本文档根目录的绝对路径
  "REMOTE_ADDR" => "127.0.0.1"                                                                                         // 用户的IP地址                                
  "SERVER_PORT" => "80"                                                                                                      //服务器使用的端口
  "SERVER_ADDR" => "127.0.0.1"                                                                                           // 服务器的IP地址
  "SERVER_NAME" => "www.sun.com"                                                                                  //服务器的主机名,注:如果脚本运行于虚拟主机中,该名称是由那个虚拟主机所设置的值决定。
在 Apache 2 里,必须设置 UseCanonicalName = On 和 ServerName。
否则该值会由客户端提供,就有可能被伪造。 上下文有安全性要求的环境里,不应该依赖此值。 "SERVER_SOFTWARE" => "Apache/2.4.23 (Win32) OpenSSL/1.0.2j mod_fcgid/2.3.9" //响应头中Server的内容 "SERVER_SIGNATURE" => "" //包含了服务器版本和虚拟主机名的字符串 "SystemRoot" => "C:\Windows" "HTTP_CONNECTION" => "close" //请求头中Connection项的内容 "CONTENT_LENGTH" => "0" "HTTP_ACCEPT_ENCODING" => "gzip, deflate" //请求头中Accept-Encoding项的内容 "HTTP_COOKIE" => "PHPSESSID=ubuovo14i1u4cem7pfmjro714g" "HTTP_HOST" => "www.sun.com" //请求头中Host项的内容 "HTTP_ACCEPT" => "*/*"
//请求头中Accept项的内容 "HTTP_USER_AGENT" => "PostmanRuntime/7.4.0" //请求头中User-Agent项的内容 "HTTP_POSTMAN_TOKEN" => "254d4f2a-edab-4962-9192-831b6d80323b" "HTTP_CACHE_CONTROL" => "no-cache" //请求头中Cache-Control项的内容 "REDIRECT_STATUS" => "200" "FCGI_ROLE" => "RESPONDER" "PHP_SELF" => "/index.php" //当前执行脚本的文件名 "REQUEST_TIME_FLOAT" => 1547197941.8135 //请求开始的时间戳,微秒级别精准度 "REQUEST_TIME" => 1547197941 //请求开始的时间戳 "APP_NAME" => "前链财经" "APP_ENV" => "local" "APP_KEY" => "" "APP_DEBUG" => "true" "APP_URL" => "http://www.sun.com" "DATA_LIMIT" => "15" "CORS_LARAVEL_ROUTE_GROUP_MODE" => "true" "CORS_LARAVEL_ALLOW_ROUTE_PERFIX" => "*" "CORS_ALLOW_CREDENTIALS" => "false" "CORS_ACCESS_CONTROL_MAX_AGE" => "0" "LOG_CHANNEL" => "stack" "DB_CONNECTION" => "mysql" "DB_HOST" => "" "DB_PORT" => "" "DB_DATABASE" => "" "DB_USERNAME" => "" "DB_PASSWORD" => "" "BROADCAST_DRIVER" => "log" "CACHE_DRIVER" => "file" "SESSION_DRIVER" => "file" "SESSION_LIFETIME" => "120" "QUEUE_DRIVER" => "sync" "REDIS_HOST" => "127.0.0.1" "REDIS_PASSWORD" => "null" "REDIS_PORT" => "6379" "MAIL_DRIVER" => "log" "MAIL_HOST" => "smtp.mailtrap.io" "MAIL_PORT" => "2525" "MAIL_USERNAME" => "null" "MAIL_PASSWORD" => "null" "MAIL_ENCRYPTION" => "null" "PUSHER_APP_ID" => "" "PUSHER_APP_KEY" => "" "PUSHER_APP_SECRET" => "" "JWT_TTL" => "20160" "JWT_REFRESH_TTL" => "" "JWT_SECRET" => "" "PUSHER_APP_CLUSTER" => "mt1" "MIX_PUSHER_APP_KEY" => "" "MIX_PUSHER_APP_CLUSTER" => "mt1" ]

使用实例:
php

// $_SERVER['HTTPS']当前是否为HTTPS协议
if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
    $url = 'https://';
} else {
    $url = 'http://';
}

if ($_SERVER['SERVER_PORT'] == 80) {
    $url .= $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
} else {
    $url .= $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['SERVER_PORT'];
}
 
   

实例:

php
// $_SERVER['HTTP_REFERER'],前一页面的url
if (!empty($_SERVER['HTTP_REFERER'])) {
    if (!strpos($_SERVER['HTTP_REFERER'], 'www.example.com')) {
        header('Location: http://www.example.com');
    }
}

转载于:https://www.cnblogs.com/sgm4231/p/10256427.html

你可能感兴趣的:(php,数据库)