This article introduces the contents of the PHP header () 7 kinds of usage, has a certain reference value, now share to everyone, the need for friends can refer to
7 Ways to use PHP headers
1. Jump page
Header (' Location: '. $url); There is no space between location and ': '.
2. Declaration Content-type
Header (' Content-type:text/html;charset=utf-8 ');
3. Return Response status Code
Header (' http/1.1 404 Not Found ');
4. Perform a jump after a certain time
Header (' refresh:10; url=http://www.baidu.com/'); Jump after 10s.
5. Control browser Cache
Header ("Expires:mon, Jul 1997 05:00:00 GMT"), Header ("Last-modified:". Gmdate ("D, D M Y h:i:s"). "GMT"); Header ("Cache-control:no-cache, must-revalidate"); Header ("Pragma:no-cache");
6.. Perform HTTP validation
Header (' http/1.1 401 Unauthorized '); header (' Www-authenticate:basic realm= ' Top Secret ');
7. Perform the download operation
Header (' Content-type:application/octet-stream '); Set Content Type header (' content-disposition:attachment; filename= ' Example.zip '); Set the MIME user as the attachment header (' content-transfer-encoding:binary '); Set the Transmit mode header (' Content-length: '. FileSize (' Example.zip ')); Set Content length