修改HTTP消息头(例子)Modify HTTP Headers (Examples)
2011-11-30 11:15
357 查看
Many examples that show how to use the header() function of PHP
php中如何使用header()方法有许多例子。点击查看header()方法
Hint: If you want to check your headers, you can use web based tools like: web-sniffer.net, web-browser extensions (e.g. LiveHTTPHeaders, ieHTTPHeaders) or another third-party software tool.
注:
如果想查看headers,可以用基于web的工具,例如web-sniffer.net、浏览器扩展插件(例如:LiveHTTPHeaders,ieHTTPHeaders)或者其他第三方软件。
<?php // See related links for more status codes // Use this header instruction to fix 404 headers // produced by url rewriting... header('HTTP/1.1 200 OK'); // Page was not found: header('HTTP/1.1 404 Not Found'); // Access forbidden: header('HTTP/1.1 403 Forbidden'); // The page moved permanently should be used for // all redrictions, because search engines know // what's going on and can easily update their urls. header('HTTP/1.1 301 Moved Permanently'); // Server error header('HTTP/1.1 500 Internal Server Error'); // Redirect to a new location: header('Location: http://www.example.org/'); // Redriect with a delay: header('Refresh: 10; url=http://www.example.org/'); print 'You will be redirected in 10 seconds'; // you can also use the HTML syntax: // <meta http-equiv="refresh" content="10;http://www.example.org/ /> // override X-Powered-By value header('X-Powered-By: PHP/4.4.0'); header('X-Powered-By: Brain/0.6b'); // content language (en = English) header('Content-language: en'); // last modified (good for caching) $time = time() - 60; // or filemtime($fn), etc header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); // header for telling the browser that the content // did not get changed header('HTTP/1.1 304 Not Modified'); // set content length (good for caching): header('Content-Length: 1234'); // Headers for an download: header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="example.zip"'); header('Content-Transfer-Encoding: binary'); // load the file to send: readfile('example.zip'); // Disable caching of the current document: header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Pragma: no-cache'); // set content type: header('Content-Type: text/html; charset=iso-8859-1'); header('Content-Type: text/html; charset=utf-8'); header('Content-Type: text/plain'); // plain text file header('Content-Type: image/jpeg'); // JPG picture header('Content-Type: application/zip'); // ZIP file header('Content-Type: application/pdf'); // PDF file header('Content-Type: audio/mpeg'); // Audio MPEG (MP3,...) file header('Content-Type: application/x-shockwave-flash'); // Flash animation // show sign in box header('HTTP/1.1 401 Unauthorized'); header('WWW-Authenticate: Basic realm="Top Secret"'); print 'Text that will be displayed if the user hits cancel or '; print 'enters wrong login data';
原文链接:
http://www.jonasjohn.de/snippets/php/headers.htm
相关文章推荐
- Modify HTTP Headers (Examples)
- Java Code Examples for com.sun.net.httpserver.HttpExchange.getResponseHeaders()
- 无法分析从服务器收到的消息。之所以出现此错误,常见的原因是: 在通过调用 Response.Write() 修改响应时,将启用响应筛选器、HttpModule 或服务器跟踪。
- 理解HTTP消息头【很完整,例子也很丰富】
- 无法分析从服务器收到的消息。之所以出现此错误,常见的原因是: 在通过调用 Response.Write() 修改响应时,将启用响应筛选器、HttpModule 或服务器跟踪
- Modify Http Headers
- idHTTP最简洁的修改和取得Cookie例子
- Modify HTML title tag 可以从这个例子得到启发如何修改DOM的元素
- 阿里云消息队列MQ_HTTP接入 for .NetCore 简单例子
- 理解HTTP消息头【很完整,例子也很丰富】
- 理解HTTP消息头【很完整,例子也很丰富】
- 理解HTTP消息头【很完整,例子也很丰富】
- HTTP消息头(HTTP headers)-常用的HTTP请求头与响应头
- 理解HTTP消息头【很完整,例子也很丰富】
- 无法分析从服务器收到的消息。之所以出现此错误,常见的原因是: 在通过调用 Response.Write() 修改响应时,将启用响应筛选器、HttpModule 或服务器跟踪。
- 无法分析从服务器收到的消息。之所以出现此错误,常见的原因是: 在通过调用 Response.Write() 修改响应时,将启用响应筛选器、HttpModule 或服务器跟踪。
- javascript/jquery读取和修改HTTP headers
- 修改HttpCustomHeaders 兼容IE8
- 理解HTTP消息头【很完整,例子也很丰富】
- HTTP长连接实现服务端实时推送消息的小例子,同个账号重复登录踢出原先登录的账号