下面为大家分享一篇php获取ajax的headers方法与内容实例,具有很好的参考价值,希望对大家有所帮助。一起过来看看吧
原文链接:http://www.php.cn/php-weizijiaocheng-394350.html
1.前端页面
|
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
|
<!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 class="suning">点击</button>
<script type="text/javascript">
$(".suning").click(function(){
$.ajax({
url: 'headers.php',
data: {'key':'123'},
type: 'POST',
beforeSend: function () {
},
headers: {
"token":'token7758521'
},
success: function (responseData) {
console.log(responseData);
},
error: function (error) {
console.log(error);
}
});
});
</script>
</body>
|
2.php页面
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<?php
$arr = get_getallheaders();
var_dump($arr);
function get_getallheaders()
{
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == 'HTTP_')
{
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
|
3.php页面返回的headers
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
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"]=>
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部分数据
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
["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"]=>
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获取文件后缀名的7种方法
PHP获取当前域名的方法
以上就是php获取ajax的headers方法与内容实例的详细内容,更多请关注php中文网其它相关文章!