1. Front Page
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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>
<body>
<button class= "Suning" > Click </button>
<script type= "Text/javascript" >
$ (". Suning"). Click (function () {
$.ajax ({
URL: ' headers.php ',
Data: {' key ': ' 123 '},//if string JSON is required, use Json.stringify (setting.data)
Type: ' POST ',
DataType: ' JSON ',
ContentType: ' Application/json ',
processdata:true,//to True does not serialize data
Beforesend:function () {
Layer.load (2);
},
Headers: {
"token": ' token7758521 '/custom token and value
},
Success:function (responsedata) {
Console.log (ResponseData);
},
Error:function (Error) {
Console.log (Error);
}
});
});
</script>
</body>
2.php page
<?php
$arr = get_getallheaders ()//Gets the HTTP header array
//echo $arr ["Token"];//output Token
Var_dump ($arr); Outputs the entire array
function get_getallheaders () //Definition method
{
foreach ($_server as $name => $value) //loop _server array
&NBSP;{&NBSP;&NBSP
if (substr ($name, 0, 5) = = ' Http_ ') // The first 5 characters are http_ into the loop
{
$headers [Str_replace (', '-', Ucwords strtolower ( Str_replace (' _ ', ', substr ($name, 5))] = $value;
//notes
&NBSP;//SUBSTR ($name, 5), from the $name 5th character backward intercept
//str_replace (' _ ', ', ') underline replaced by Space
//strtolower () all to lowercase
//ucwords () converts the first letter to uppercase
//str_replace (', '-',) all spaces replaced by-
}
&NBSP;}&NBSP;&NBSP
return $headers; //Return the first 5 characters of the previous key are HTTP_ array
//return $_ SERVER; Returns the _server array
}
3.php page returned by headers
Array (11) {
["Cookie"]=>
String (hm_lvt_f62fa14829605f0d29c05da9c30e045a=1503649309,1503884728) "; _ga=ga1.1.1091059248.1504832863 "
["Accept-language"]=>
String "zh-cn,zh;q=0.8"
["Accept-encoding"]=>
String (a) "gzip, deflate, BR"
["Referer"]=>
String ("http://localhost/DianNaoBengKuiFangYunDuan/qrcode/headers.html")
["Token"]=>//custom Token and values
String (a) "token7758521"
["X-requested-with"]=>
String "XMLHttpRequest"
["Accept"]=>
String (3) "*/*"
["User-agent"]=>
String (mozilla/5.0) (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/61.0.3163.100 safari/537.36 "
["Origin"]=>
String (http://localhost)
["Connection"]=>
String (5) "Close"
["Host"]=>
String (9) "localhost"
}
4. The original headers part of the data
["Http_cookie"]=>
String (hm_lvt_f62fa14829605f0d29c05da9c30e045a=1503649309,1503884728) "; _ga=ga1.1.1091059248.1504832863 "
["Http_accept_language"]=>
String "zh-cn,zh;q=0.8"
["Http_accept_encoding"]=>
String (a) "gzip, deflate, BR"
["Http_referer"]=>
String ("http://localhost/DianNaoBengKuiFangYunDuan/qrcode/headers.html")
["Http_token"]=>//custom TOKEN and values
String (a) "token7758521"
["Http_x_requested_with"]=>
String "XMLHttpRequest"
["Http_accept"]=>
String (3) "*/*"
["Http_user_agent"]=>
String (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 (http://localhost)
["Content_length"]=>
String (1) "7"
["Http_connection"]=>
String (5) "Close"
["Http_host"]=>
String (9) "localhost"