403 被制止(Forbidden)
假如你没有权限会见某个页面,那末就会前往403形态。这类情形凡是会产生在你试图翻开一个没有index页面的文件夹。假如办事器设置不答应检查目次内容,那末你就会看到403毛病。
其它一些一些体例也会发送权限限制,例如你可以经由过程IP地址停止禁止,这需求一些htaccess的协助。
order allow,deny
deny from 192.168.44.201
deny from 224.39.163.12
deny from 172.16.7.92
allow from all 302(或307)一时挪动(Moved Temporarily) 和 301 永世挪动(Moved Permanently)
这两个形态会呈现在阅读重视定向时。例如,你利用了相似 bit.ly 的网址延长办事。这也是它们若何获知谁点击了他们链接的办法。
302和301关于阅读器来讲长短常类似的,但关于搜刮引擎爬虫就有一些不同。打个例如,假如你的网站正在保护,那末你就会将客户端阅读器用302 重定向到别的一个地址。搜刮引擎爬虫就会在未来从头索引你的页面。然而假如你利用了301重定向,这就等于你告知了搜刮引擎爬虫:你的网站已永世的挪动 到了新的地址。 500 办事器毛病(Internal Server Error)
Accept-Encoding: gzip,deflate
大局部的古代阅读器都撑持gzip紧缩,并会把这一信息呈报给办事器。这时候办事器就会紧缩过的HTML发送给阅读器。这可以削减近80%的文件巨细,以节俭下载工夫和带宽。
在PHP中可使用 $_SERVER["HTTP_ACCEPT_ENCODING"] 获得该信息。 然后挪用ob_gzhandler()办法时会主动检测该值,所以你无需手动检测。
// enables output buffering
// and all output is compressed if the browser supports it
ob_start("ob_gzhandler");
If-Modified-Since
假如一个页面已在你的阅读器中被缓存,那末你下次阅读时阅读器将会检测文档是不是被修正过,那末它就会发送如许的头部:
If-Modified-Since: Sat, 28 Nov 2009 06:38:19 GMT
假如自从这个工夫以来未被修正过,那末办事器将会前往“304 Not Modified”,并且不会再前往内容。阅读器将主动去缓存中读取内容
在PHP中,可以用$_SERVER["HTTP_IF_MODIFIED_SINCE"] 来检测。
// assume $last_modify_time was the last the output was updated
// did the browser send If-Modified-Since header?
if(isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
// if the browser cache matches the modify time
if ($last_modify_time == strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
// send a 304 header, and no content
header("HTTP/1.1 304 Not Modified");
exit;
}
}
还有一个叫Etag的HTTP头信息,它被用来肯定缓存的信息是不是准确,稍后咱们将会注释它。
Cookie
望文生义, 头部将会包括referring url信息。
例如,我会见Nettuts+的主页并点击了一个链接,这个头部信息将会发送到阅读器:
Referer: http://net.tutsplus.com/
在PHP中,可以经由过程 $_SERVER["HTTP_REFERER"] 获得该值。
if (isset($_SERVER["HTTP_REFERER"])) {
$url_info = parse_url($_SERVER["HTTP_REFERER"]);
// is the surfer coming from Google?
if ($url_info["host"] == "www.谷歌.com") {
parse_str($url_info["query"], $vars);
echo "You searched on Google for this keyword: ". $vars["q"];
}
}
// if the referring url was:
// http://www.谷歌.com/search?source=ig&hl=en&rlz=&=&q=http+headers&aq=f&oq=&aqi=g-p1g9
// the output will be:
// You searched on Google for this keyword: http headers
You may have noticed the word “referrer” is misspelled as “referer”. Unfortunately it made into the official HTTP specifications like that and got stuck.
Authorization
w3.org 的界说是:“The Cache-Control general-header field is used to specify directives which MUST be obeyed by all caching mechanisms along the request/response chain.” 个中“caching mechanisms” 包括一些你ISP能够会用到的 网关和代办署理信息。
例如:
Cache-Control: max-age=3600, public
“public”意味着这个呼应可以被任何人缓存,“max-age” 则标明了该缓存无效的秒数。答应你的网站被缓存降大大削减下载工夫和带宽,同时也进步的阅读器的载入速度。
也能够经由过程设置 “no-cache” 指令来制止缓存:
Cache-Control: no-cache
更多概况请拜见w3.org。
Content-Type
当内容将要被传输到阅读器时,办事器可以经由过程该头部告诉阅读器将要传送文件的巨细(bytes)。
Content-Length: 89123
关于文件下载来讲这个信息相当的有效。这就是为何阅读器晓得下载进度的缘由。
例如,这里我写了一段虚拟剧本,来摹拟一个慢速下载。
// it"s a zip file
header("Content-Type: application/zip");
// 1 million bytes (about 1megabyte)
header("Content-Length: 1000000");
// load a download dialogue, and save it as download.zip
header("Content-Disposition: attachment; filename="download.zip"");
// 1000 times 1000 bytes of data
for ($i = 0; $i < 1000; $i++) {
echo str_repeat(".",1000);
// sleep to slow down the download
usleep(50000);
}
了局将会是如许的:
如今,我将Content-Length头部正文失落:
// it"s a zip file
header("Content-Type: application/zip");
// the browser won"t know the size
// header("Content-Length: 1000000");
// load a download dialogue, and save it as download.zip
header("Content-Disposition: attachment; filename="download.zip"");
// 1000 times 1000 bytes of data
for ($i = 0; $i < 1000; $i++) {
echo str_repeat(".",1000);
// sleep to slow down the download
usleep(50000);
}
了局就酿成了如许: