Php obtains the ajax headers method and content instance, and ajaxheaders
1. Front-end page
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2. php page
<? Php $ arr = get_getallheaders (); // get the http header array // echo $ arr ["Token"]; // output Tokenvar_dump ($ arr ); // output the entire array function get_getallheaders () // defines the method {foreach ($ _ SERVER as $ name => $ value) // loop _ SERVER array {if (substr ($ name, 0, 5) = 'HTTP _') // The first five characters are the HTTP _ entry loop {$ headers [str_replace ('', '-', ucwords (strtolower (str_replace ('_','', substr ($ name, 5)] = $ value; // comment // substr ($ name, 5 ), extract 5th characters from $ name and then slash (/str_replace ('_', '',) into spaces. // replace strtolower () into lowercase. // ucwords () convert the initial character to uppercase // replace str_replace ('', '-',) with-} return $ headers; // The first five characters of the first key are returned: HTTP _ array // return $ _ SERVER; // return _ SERVER array}
3. headers returned by the php page
Array (11) {["Cookie"] => string (94) "bytes = 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 "] => // custom token and value 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.20.3.100 Safari/537.36 "[" Origin "] => string (16)" http: // localhost "[" Connection "] => string (5) "close" ["Host"] => string (9) "localhost "}
4. Raw headers data
["HTTP_COOKIE"] => string (94) "bytes = 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 "] => // custom token and value 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.20.3.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"
The above php method and content example for getting ajax headers is all the content that I have shared with you. I hope to give you a reference and support for the help house.