The following small series for you to share a PHP to get Ajax headers method and content examples, has a good reference value, I hope to be helpful to everyone. Let's take a look at it with a little knitting.
1. Front 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 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"
Above this PHP get Ajax headers method and content instance is small to share all the content, hope to give you a reference, also hope that we support PHP Chinese web.
Articles you may be interested in:
The most basic operating tutorial on using queue in Laravel
Detailed explanation of YAF framework PHPUnit Integration test method
Quick troubleshooting PHP calls to Word component DCOM permissions