Php obtains client and server information
- $ Headers = array ();
- Foreach ($ _ SERVER as $ key => $ value ){
- If ('http _ '= substr ($ key, 0, 5 )){
- $ Headers [str_replace ('_', '-', substr ($ key, 5)] = $ value;
- }
- }
- ?>
-
Note: the names of information headers are case-insensitive in RFC. However, not all HTTP request headers exist in the form of Keys starting with HTTP _ and $ _ SERVER, such as Authorization, Content-Length, and Content-Type, therefore, to obtain all HTTP request headers, add the following code:
- If (isset ($ _ SERVER ['php _ AUTH_DIGEST ']) {
- $ Header ['authorization'] = $ _ SERVER ['php _ AUTH_DIGEST ']);
- } Elseif (isset ($ _ SERVER ['php _ AUTH_USER ']) & isset ($ _ SERVER ['php _ AUTH_PW']) {
- $ Header ['authorization'] = base64_encode ($ _ SERVER ['php _ AUTH_USER '].': '. $ _ SERVER ['php _ AUTH_PW']);
- }
- If (isset ($ _ SERVER ['content _ length']) {
- $ Header ['content-length'] = $ _ SERVER ['content _ length'];
- }
- If (isset ($ _ SERVER ['content _ type']) {
- $ Header ['content-type'] = $ _ SERVER ['content _ type'];
- }
- ?>
|