This article mainly introduces how PHP obtains the AJAX headers, the interested friend's reference, hoped to be helpful to everybody.
1. Front Page
<! DOCTYPE html>
2.php page
<?php$arr = Get_getallheaders ();//Get HTTP header array//echo $arr ["Token"];//output tokenvar_dump ($arr);//output entire array function get_ Getallheaders ()//define method { foreach ($_server as $name = $value)//loop _server Array { if (substr ($name, 0, 5) = = ' Http_ ')///The first 5 characters are http_ into the loop { $headers [Str_replace (', '-', Ucwords (Strtolower (' _ ', ', ' Str_replace ($name, 5))) )] = $value; Note//substr ($name, 5), from $name 5th character to intercept//str_replace (' _ ', ', '), replace the underscore with a space//strtolower () convert all to lowercase//ucwords () convert the first letter to uppercase// Str_replace (', '-',) all spaces are replaced with-} } return $headers;//Return the first 5 characters before key is http_ array//return $_server;//return _server array}
3.php page returned by headers
Array (one) {["Cookie"]=> string (94) "hm_lvt_f62fa14829605f0d29c05da9c30e045a=1503649309,1503884728; _ga=ga1.1.1091059248.1504832863 "[" Accept-language "]=> string" zh-cn,zh;q=0.8 "[" Accept-encoding "]=> String (+) "gzip, deflate, BR" ["Referer"]=> string "http://localhost/DianNaoBengKuiFangYunDuan/qrcode/ Headers.html "[" token "]=>//custom Token and value string (" token7758521 "[" X-requested-with "]=> string (14)" 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. Original headers part data
["Http_cookie"]=> string (94) "Hm_lvt_f62fa14829605f0d29c05da9c30e045a= 1503649309,1503884728; _ga=ga1.1.1091059248.1504832863 "[" Http_accept_language "]=> string" zh-cn,zh;q=0.8 "[" Http_accept_encoding " ]=> string (+) "gzip, deflate, BR" ["Http_referer"]=> string () "http://localhost/DianNaoBengKuiFangYunDuan/ Qrcode/headers.html "[" Http_token "]=>//custom TOKEN and value string ()" 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"