PHP获取网页头部信息、获取文件当前位置、获取文件最后修改时间

一直不明白header头到底有哪些数据,今天在手册上无意中看到一个函数:getallheaders(),瞬间就震精了。

更改header头信息,可以控制文件被浏览器访问时浏览器接收到的文件的类型。比如要下载一个csv文件等等。

echo "
";
var_dump(getallheaders())."
"; echo "
";

array(9) {
  ["Host"]=>
  string(9) "127.0.0.1"
  ["Connection"]=>
  string(10) "keep-alive"
  ["Cache-Control"]=>
  string(9) "max-age=0"
  ["User-Agent"]=>
  string(100) "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11"
  ["Accept"]=>
  string(63) "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
  ["Accept-Encoding"]=>
  string(17) "gzip,deflate,sdch"
  ["Accept-Language"]=>
  string(14) "zh-CN,zh;q=0.8"
  ["Accept-Charset"]=>
  string(23) "GBK,utf-8;q=0.7,*;q=0.3"
  ["Cookie"]=>
  string(1191) "ECS[visit_times]=1; 15f90_winduser=U2tXUwcFCwxYVQJVBFFeBlZTVlUAVgcHVgBcAFJXDgFeA2o; 15f90_ck_info=%2F%09; 15f90_ol_offset=98; lzstat_uv=3864835143548786077|931085; 15f90_lastpos=other; 15f90_lastvisit=151%091332294013%09%2Fupload%2Fpw_ajax.php%3Factionbubble%26uid1%26signpw_all_tip_cloudAuthCode%26nowtime1332294013725; 15f90_admin_att=att; 15f90_AdminUser=U1FXBVZaBQEOBDlSU1pRWmoCW1ZXUgcBAgpbBwUFVgUJBFBUVQcGBVVaUA4LA1QDUz4; __utma=96992031.448634020.1332813028.1332813028.1332813028.1; __utmz=96992031.1332813028.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); 9c4ac_ipstate=1332917950; 9c4ac_cloudClientUid=9748974; 9c4ac_threadlog=%2C37%2C91%2C90%2C95%2C10%2C57%2C60%2C13%2C70%2C76%2C; 9c4ac_readlog=%2C24%2C25%2C26%2C27%2C28%2C29%2C30%2C31%2C32%2C33%2C; 9c4ac_clearm_1=2; 9c4ac_ol_offset=98; thisPWTabs=basic; 9c4ac_AdminUser=UwFRUV8GUwwFAzlUUFRZXztUVFQEVgNQUlpXBVYMBgEGBAoEBgUGAgABAltXV1FTBTBRAAUFUAMBAlIE; 9c4ac_cknum=UwFRUV8GUwAGDTk8AwkGCFFQBlYEAABWBVpTUAVUDQwHUwoDUVMHAAQHVVw; 9c4ac_winduser=VjsHAAcAVAlUVgYNUlgFUgUKVQRVVQMHAg5VA1IFDQkJBTs; 9c4ac_ck_info=%2F%09; 9c4ac_lastpos=index; 9c4ac_lastvisit=24%091332926257%09%2Fpw8%2Findex.php%3Fmbbs; 9c4ac_ci=index%091332926257%09%09"
}

获取文件当前位置:

echo getcwd();

获取文件最后修改时间:

echo "Last modified: " . date ("F d Y H:i:s.", getlastmod());


你可能感兴趣的:(PHP)