This article mainly introduces the PHP header () function commonly used methods. Summed up the common usage, the need for friends can refer to the following
Define coding Code as follows: Header (' content-type:text/html;charset=utf-8 '); Atom Code as follows: Header (' Content-type:application/atom+xml '); CSS Code as follows: Header (' content-type:text/css '); Javascript Code is as follows: Header (' Content-type:text/javascript '); JPEG Image Code is as follows: Header (' content-type:image/jpeg '); JSON Code is as follows: Header (' Content-type:application/json '); PDF Code as follows: Header (' content-type:application/pdf '); RSS Code is as follows: Header (' content-type:application/rss+xml; charset=iso-8859-1 '); Text (Plain) code as follows: Header (' Content-type:text/plain '); The XML code is as follows: Header (' Content-type:text/xml '); OK Code is as follows: Header (' http/1.1 OK '); Set a 404-head: code as follows: Header (' http/1.1 404 Not Found '); The set address is permanently redirected to the following code: header (' http/1.1 moved Permanently '); Go to a new address code as follows: Header (' location:http://www.example.org/'); File delay steering: Code as follows: Header (' refresh:10 url=http://www.example.org/'); print ' You'll be redirected in seconds '; Of course, you can also use HTML syntax to implement//<meta HTTP-Equiv= "Refresh" content= "10;http://www.example.org//>//Override x-powered-by:php: Code is as follows: Header (' x-powered-by:php /4.4.0 '); Header (' x-powered-by:brain/0.6b '); The document language code is as follows: Header (' content-language:en '); Tell the browser the last time the code was modified as follows: $time = times ()-60; or Filemtime ($FN), etc header (' last-modified: '. Gmdate (' d, D M Y h:i:s ', $time). ' GMT '); Tell the browser that the contents of the document have not changed code as follows: Header (' http/1.1 304 not Modified '); Set content length code as follows: Header (' content-length:1234 '); Set to a download type code as follows: 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 for the current document code as follows: Header (' Cache-control:no-cache, No-store, max-age=0, Must-revalidate '); Header (' Expires:mon, June 1997 05:00:00 GMT '); Date in the past header (' Pragma:no-cache '); Set the content type: The code is as follows: Header (' content-type:text/html charset=iso-8859-1 '); Header (' content-type:text/html; charseT=utf-8 '); Header (' Content-type:text/plain '); Plain Text Format header (' Content-type:image/jpeg '); jpg*** header (' Content-type:application/zip '); Zip file header (' Content-type:application/pdf '); PDF file Header (' Content-type:audio/mpeg '); Audio file header (' Content-type:application/x-shockw**e-flash '); Flash animation//Display Login dialog box code as follows: Header (' http/1.1 401 Unauthorized '); Header (' Www-authenticate:basic realm= "top Secret"); print ' Text that'll be displayed if the user hits cancel or '; print ' enters wrong login data ';