PHP/JS 操作C/S过程中head信息

php获取和定义头部信息

var_dump($_SERVER);

输出:

array(32) {
  ["USER"]=>
  string(6) "nobody"
  ["HOME"]=>
  string(1) "/"
  ["FCGI_ROLE"]=>
  string(9) "RESPONDER"
  ["SCRIPT_FILENAME"]=>
  string(22) "/feihu/dwz_ui/head.php"
  ["QUERY_STRING"]=>
  string(0) ""
  ["REQUEST_METHOD"]=>
  string(3) "GET"
  ["CONTENT_TYPE"]=>
  string(0) ""
  ["CONTENT_LENGTH"]=>
  string(0) ""
  ["SCRIPT_NAME"]=>
  string(16) "/dwz_ui/head.php"
  ["REQUEST_URI"]=>
  string(16) "/dwz_ui/head.php"
  ["DOCUMENT_URI"]=>
  string(16) "/dwz_ui/head.php"
  ["DOCUMENT_ROOT"]=>
  string(21) "/usr/local/nginx/html"
  ["SERVER_PROTOCOL"]=>
  string(8) "HTTP/1.1"
  ["GATEWAY_INTERFACE"]=>
  string(7) "CGI/1.1"
  ["SERVER_SOFTWARE"]=>
  string(11) "nginx/1.8.1"
  ["REMOTE_ADDR"]=>
  string(12) "192.168.95.1"
  ["REMOTE_PORT"]=>
  string(5) "50835"
  ["SERVER_ADDR"]=>
  string(14) "192.168.95.128"
  ["SERVER_PORT"]=>
  string(2) "80"
  ["SERVER_NAME"]=>
  string(9) "xnj.aijee"
  ["REDIRECT_STATUS"]=>
  string(3) "200"
  ["HTTP_HOST"]=>
  string(9) "xnj.aijee"
  ["HTTP_CONNECTION"]=>
  string(10) "keep-alive"
  ["HTTP_CACHE_CONTROL"]=>
  string(9) "max-age=0"
  ["HTTP_ACCEPT"]=>
  string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
  ["HTTP_UPGRADE_INSECURE_REQUESTS"]=>
  string(1) "1"
  ["HTTP_USER_AGENT"]=>
  string(109) "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
  ["HTTP_ACCEPT_ENCODING"]=>
  string(19) "gzip, deflate, sdch"
  ["HTTP_ACCEPT_LANGUAGE"]=>
  string(14) "zh-CN,zh;q=0.8"
  ["PHP_SELF"]=>
  string(16) "/dwz_ui/head.php"
  ["REQUEST_TIME_FLOAT"]=>
  float(1472375417.1809)
  ["REQUEST_TIME"]=>
  int(1472375417)
}

其中"HTTP..."开头部分为C端传过来的head信息,其他为默认的服务器短信息

设置S端发往C端的head信息

header('content-Type:application/json');
header('content-Type:application/json; charset=utf-8');
headder('Server:apache');

 

Js只能通过Ajax请求一个url的过程可以设置获取head信息,如果一段jquery使用ajax语段:

//利用jQuery的ajax请求来完成对head的请求,然后逐个取得需要的信息,
$.ajax({
    type: 'HEAD', // 获取头信息,type=HEAD即可
    url : window.location.href,
    complete: function( xhr,data ){
        // 获取相关Http Response header
        var wpoInfo = {
            // 服务器端时间
            "date" : xhr.getResponseHeader('Date'),
            // 如果开启了gzip,会返回这个东西
            "contentEncoding" : xhr.getResponseHeader('Content-Encoding'),
            // keep-alive ? close?
            "connection" : xhr.getResponseHeader('Connection'),
            // 响应长度
            "contentLength" : xhr.getResponseHeader('Content-Length'),
            // 服务器类型,apache?lighttpd?
            "server" : xhr.getResponseHeader('Server'),
            "vary" : xhr.getResponseHeader('Vary'),
            "transferEncoding" : xhr.getResponseHeader('Transfer-Encoding'),
            // text/html ? text/xml?
            "contentType" : xhr.getResponseHeader('Content-Type'),
            "cacheControl" : xhr.getResponseHeader('Cache-Control'),
            // 生命周期?
            "exprires" : xhr.getResponseHeader('Exprires'),
            "lastModified" : xhr.getResponseHeader('Last-Modified')
        };
        // 在这里,做想做的事。。。
    }
});

  

  

posted @ 2016-08-28 10:29  飞虎cnblog  阅读(146)  评论(0编辑  收藏  举报
友情链接:技术迷 | JSM官方博客 | 阿旭博客 | 有声小说在线听