首页 > 编程 > PHP > 正文

php获取ajax的headers方法与内容实例讲解

2020-03-22 19:27:22
字体:
来源:转载
供稿:网友
下面小编就为大家分享一篇php获取ajax的headers方法与内容实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

1.前端页面

 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd  html xmlns= http://www.w3.org/1999/xhtml xml:lang= ko lang= ko  head  title Cross-Browser QRCode generator for Javascript /title  meta http-equiv= Content-Type content= text/html; charset=UTF-8 /  meta name= viewport content= width=device-width,initial-scale=1,user-scalable=no /  script type= text/javascript src= jquery.min.js /script  script type= text/javascript src= qrcode.js /script  /head  body  button >

2.php页面

 ?php$arr = get_getallheaders();//获取http头数组//echo $arr[ Token //输出Tokenvar_dump($arr);//输出整个数组function get_getallheaders() //定义方法 foreach ($_SERVER as $name = $value) //循环_SERVER数组 if (substr($name, 0, 5) == HTTP_ ) //前5个字符是HTTP_的进入循环 $headers[str_replace( , - , ucwords(strtolower(str_replace( _ , , substr($name, 5)))))] = $value;  //注释 //substr($name, 5),从$name第5个字符向后截取 //str_replace( _ , ,)下划线替换成空格 //strtolower()全部转换为小写 //ucwords()首字母转换为大写 //str_replace( , - ,)所有空格替换为- return $headers; //返回前key前5个字符是HTTP_的数组 //return $_SERVER; //返回_SERVER数组}

3.php页面返回的headers

array(11) { [ Cookie ]=  string(94) Hm_lvt_f62fa14829605f0d29c05da9c30e045a=1503649309,1503884728; _ga=GA1.1.1091059248.1504832863  [ Accept-Language ]=  string(14) zh-CN,zh;q=0.8  [ Accept-Encoding ]=  string(17) gzip, deflate, br  [ Referer ]=  string(62) http://localhost/DianNaoBengKuiFangYunDuan/qrcode/headers.html  [ Token ]= //自定义token及值 string(12) token7758521  [ X-Requested-With ]=  string(14) XMLHttpRequest  [ Accept ]=  string(3) */*  [ User-Agent ]=  string(110) Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36  [ Origin ]=  string(16) http://localhost  [ Connection ]=  string(5) close  [ Host ]=  string(9) localhost }

4.原始的headers部分数据

[ HTTP_COOKIE ]=  string(94) Hm_lvt_f62fa14829605f0d29c05da9c30e045a=1503649309,1503884728; _ga=GA1.1.1091059248.1504832863  [ HTTP_ACCEPT_LANGUAGE ]=  string(14) zh-CN,zh;q=0.8  [ HTTP_ACCEPT_ENCODING ]=  string(17) gzip, deflate, br  [ HTTP_REFERER ]=  string(62) http://localhost/DianNaoBengKuiFangYunDuan/qrcode/headers.html  [ HTTP_TOKEN ]= //自定义token及值 string(12) token7758521  [ HTTP_X_REQUESTED_WITH ]=  string(14) XMLHttpRequest  [ HTTP_ACCEPT ]=  string(3) */*  [ HTTP_USER_AGENT ]=  string(110) Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36  [ HTTP_ORIGIN ]=  string(16) http://localhost  [ CONTENT_LENGTH ]=  string(1) 7  [ HTTP_CONNECTION ]=  string(5) close  [ HTTP_HOST ]=  string(9) localhost 

以上这篇php获取ajax的headers方法与内容实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持php 。

您可能感兴趣的文章:

Laravel中使用Queue的最基本操作教程讲解

详解Yaf框架PHPUnit集成测试方法讲解

快速解决PHP调用Word组件DCOM权限的问题讲解

以上就是php获取ajax的headers方法与内容实例讲解的详细内容,PHP教程

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表