<?php
//php的header函数 /* * header()函数: * 定义和用法: * * header()向客户端发送原始的HTTP报头 * 即必须在任何实际的输出被发送之前调用header()函数, * <html> * <?php * //结果出错 * //在调用header()之前已经存在输出 * header('Location:http://www.example.com/'); * </html> * * 语法: * header(string,replace,http_response_code) * 参数: * string:必须的,需要发送的报头字符串 * replace:可选,指示该报头是否替换之前的报头,或添加第二个报头. * 默认是true(替换),false(允许相同类型的多个报头) * * http_response_code:可选,把HTTP响应代码强制为指定的值.(php4以上版本) * * * 提示和注释: * 注释:从Php4.2以后,该函数防止一次发送多个报头,这是对头部注入攻击的保护措施. * * for example: * <?php * //Date in the past * header("Expires:Mon,26 Jul 1997 05:00:00 GMT"); * header("Cache-Control:no-cache"); * header("Pragma:no-cache"); * ?> * <html> * <body> * * 注释:用户可能设置一些选项来更改浏览器的默认缓存设置.通过发送上面的报头,您可以覆盖任何这些设置,强制浏览器不进行缓存. * * 例子2: * 提示用户保存一个生成的PDF文件(Content-Disposition) * <?php * header("Content-type:application/pdf"); * * //文件被称为downloaded.pdf * header("Content-Disposition:attachment";filename='downloaded.pdf'); * * //PDF源在orginal.pdf * readfile("original.pdf"); * ?> * <html> * <body> * * ................. * ................. *