PHP中Header使用的HTTP协议及常用方法小结
本文实例总结了PHP中Header使用的HTTP协议及常用方法。分享给大家供大家参考。具体方法如下:
<?PHP functionhttps($num){ $http=array( 100=>"HTTP/1.1100Continue", 101=>"HTTP/1.1101SwitchingProtocols", 200=>"HTTP/1.1200OK", 201=>"HTTP/1.1201Created", 202=>"HTTP/1.1202Accepted", 203=>"HTTP/1.1203Non-AuthoritativeInformation", 204=>"HTTP/1.1204NoContent", 205=>"HTTP/1.1205ResetContent", 206=>"HTTP/1.1206PartialContent", 300=>"HTTP/1.1300MultipleChoices", 301=>"HTTP/1.1301MovedPermanently", 302=>"HTTP/1.1302Found", 303=>"HTTP/1.1303SeeOther", 304=>"HTTP/1.1304NotModified", 305=>"HTTP/1.1305UseProxy", 307=>"HTTP/1.1307TemporaryRedirect", 400=>"HTTP/1.1400BadRequest", 401=>"HTTP/1.1401Unauthorized", 402=>"HTTP/1.1402PaymentRequired", 403=>"HTTP/1.1403Forbidden", 404=>"HTTP/1.1404NotFound", 405=>"HTTP/1.1405MethodNotAllowed", 406=>"HTTP/1.1406NotAcceptable", 407=>"HTTP/1.1407ProxyAuthenticationRequired", 408=>"HTTP/1.1408RequestTime-out", 409=>"HTTP/1.1409Conflict", 410=>"HTTP/1.1410Gone", 411=>"HTTP/1.1411LengthRequired", 412=>"HTTP/1.1412PreconditionFailed", 413=>"HTTP/1.1413RequestEntityTooLarge", 414=>"HTTP/1.1414Request-URITooLarge", 415=>"HTTP/1.1415UnsupportedMediaType", 416=>"HTTP/1.1416Requestedrangenotsatisfiable", 417=>"HTTP/1.1417ExpectationFailed", 500=>"HTTP/1.1500InternalServerError", 501=>"HTTP/1.1501NotImplemented", 502=>"HTTP/1.1502BadGateway", 503=>"HTTP/1.1503ServiceUnavailable", 504=>"HTTP/1.1504GatewayTime-out" ); header($http[$num]); };
//200正常状态 header('HTTP/1.1200OK');
//301永久重定向,记得在后面要加重定向地址Location:$url header('HTTP/1.1301MovedPermanently');
//重定向,其实就是302暂时重定向 header('Location:http://www.xxxx.com/');
//设置页面304没有修改 header('HTTP/1.1304NotModified');
//显示登录框, header('HTTP/1.1401Unauthorized'); header('WWW-Authenticate:Basicrealm="登录信息"'); echo'显示的信息!';
//403禁止访问 header('HTTP/1.1403Forbidden');
//404错误 header('HTTP/1.1404NotFound');
//500服务器错误 header('HTTP/1.1500InternalServerError');
//3秒后重定向指定地址(也就是刷新到新页面与<metahttp-equiv="refresh"content="10;http://www.xxxx.com//>相同) header('Refresh:3;url=http://www.xxxx.com/'); echo'10后跳转到http://www.xxxx.com';
//重写X-Powered-By值 header('X-Powered-By:PHP/5.3.0'); header('X-Powered-By:Brain/0.6b');
//设置上下文语言 header('Content-language:en');
//设置页面最后修改时间(多用于防缓存) $time=time()-60;//建议使用filetime函数来设置页面缓存时间 header('Last-Modified:'.gmdate('D,dMYH:i:s',$time).'GMT');
//设置内容长度 header('Content-Length:39344');
//设置头文件类型,可以用于流文件或者文件下载 header('Content-Type:application/octet-stream'); header('Content-Disposition:attachment;filename="example.zip"'); header('Content-Transfer-Encoding:binary'); readfile('example.zip');//读取文件到客户端
//禁用页面缓存 header('Cache-Control:no-cache,no-store,max-age=0,must-revalidate'); header('Expires:Mon,26Jul199705:00:00GMT'); header('Pragma:no-cache');
//设置页面头信息 header('Content-Type:text/html;charset=iso-8859-1'); header('Content-Type:text/html;charset=utf-8'); header('Content-Type:text/plain'); header('Content-Type:image/jpeg'); header('Content-Type:application/zip'); header('Content-Type:application/pdf'); header('Content-Type:audio/mpeg'); header('Content-Type:application/x-shockwave-flash'); //....至于Content-Type的值可以去查查w3c的文档库,那里很丰富 ?>