日期:2014-05-16  浏览次数:20353 次

php常用的header:301,302, Redirects, 404, Javascript, Download, Authentication dialo

来自:http://phpweby.com/tutorials/php/35

?

PHP is not limited to outputting html. PHP can output images, pdf, javascript files, etc. Browsers determine what type of content is by analyzing the headers sent. In this tutorial I will present you with some examples of how to send headers. To send PHP header use the function header(). You must call this function before any output. Use the function headers_sent() to check whether the headers have been sent and output started.?

301 moved permanently (redirect):?
<?php?
header
('HTTP/1.1?301?Moved?Permanently');
header('Location:?http://www.example.com');
die();
?>?


302 moved temporarily(redirect):?
<?php?
header
('Location:?http://www.example.com');
die();
?>?


404 Page Not Found:?
<?php?
header
('HTTP/1.1?404?Not?Found');
?>?


Service not avaliable:?
<?php?
header
('HTTP/1.1?503?Service?Temporarily?Unavailable');
header('Status:?503?Service?Temporarily?Unavailable');
header('Retry-After:?60');
?>?