PHP header and Content-Type Parameters

Source: Internet
Author: User
Tags response code gtar

Void header (string [, bool Replace [, inthttp_response_coDe])
Void header (string [, bool Replace [, inthttp_response_coDe])

Header () is used to send httpheader. Replace is an optional parameter, indicating whether to replace a similar header in advance,
Or add 2nd headers of the same type. The default value is replace, but if you pass the false parameter to the 2nd parameters (replace), you
Multiple headers of the same type can be forcibly used. For example:

<? PHP
Header ('www-Authenticate: negotiate ');
Header ('www-Authenticate: ntlm', false );
?>

The second optional parameter http_response_coDe indicates the value of the HTTP response code. (PhP> 4.3.0)

There are two types of specific header calls. One is that the header starts with the string "HTTP/" (case-insensitive) and uses
To specify the HTTP status code. For example, if you have configured Apache to use javasBytes:; "OnClick = "javasResponse: tagshow (event, 'php'); "target =" _ Self "> PHP scripts process requests
Non-existing files (using the errordocument command), you may want to confirm that your script generates an appropriate status code:

<? PHP
Header ("HTTP/1.0 404 Not Found ");
?>

Note: The HTTP status line is always sent to the client first, no matter when you actually call the header () function.
Unless your HTTP header has been sent out, the status will be used by the header () function with a new
The status line overwrites.
In PHP 3, only the module that PHP compiles into Apache is, and the following staus header can achieve the same effect.

<? PHP
Header ("status: 404 Not Found ");
?>

The second special case is "Location:" header. If no 3xx status code has been sent
Issue the location line and send a redirection status code (302 ).

<? PHP
Header ("Location: http://www.upsdn.net ");
Exit;
?>

Note: HTTP/1.1 requires an absolute URI as the location parameter, including the protocol header, host name, and absolute path,
However, some clients can accept relative Uris. You can use $ _ server ['HTTP _ host'] $ _ server ['php _ Self '] and
Dirname () is used to generate an absolute URI from a relative Uri.

<? PHP
Header ("Location: http: //". $ _ server ['HTTP _ host']
. Dirname ($ _ server ['php _ Self '])
. "/". $ Relative_url );
?>

PHP scripts usually generate some dynamic content and do not need to be slowed down by the browser or proxy server of the client. Many proxies and clients can
Forcibly disable cache:

<? PHP
// Time is always past
Header ("expires: Mon, 26 Jul 1997 05: 00: 00gmt ");
// Files are always modified.
Header ("last-modified:". gmdate ("D, D m y h: I: s"). "GMT ");

// HTTP/1.1
Header ("cache-control: No-store, no-cache, must-revalidate ");
Header ("cache-control: Post-check = 0, pre-check = 0", false );

// HTTP/1.0
Header ("Pragma: No-Cache ");
?>

Note: you may find that your page cannot be cached even if you do not output the above header. Several options may have changed the default value.
Cache behavior. See sessrion_cache_limiter ().

If you want to remind the user to save the data you sent in the past, such as a generated PDF file, you can use content_dispostion
To provide a recommended file name, force the browser to display the Save dialog box.

<? PHP
Header ('content-type: Application/pdf ');
Header ('content-Disposition: attachment; filename = "downloaded.pdf "');
Readfile('original ');
?>

For IE, add the connection Header

Header ("HTTP/1.1 301 moved permanently ");
Header ("Location:". $ URL );
Header ("connection: Close ");

Type of Content-Type in Header

Content-Type description:
'Hqx'-> 'application/mac-binhex40 ',
'Cpt '-> 'application/MAC-compactpro ',
'Doc'-> 'application/msword ',
'Bin'-> 'application/octet-stream ',
'Dms '-> 'application/octet-stream ',
'Lha '-> 'application/octet-stream ',
'Lzh '-> 'application/octet-stream ',
'Exe '-> 'application/octet-stream ',
'Class'-> 'application/octet-stream ',
'So'-> 'application/octet-stream ',
'Dll '-> 'application/octet-stream ',
'Oda '-> 'application/oda ',
'Pdf '-> 'application/pdf ',
'Ai'-> 'application/postscript ',
'Eps '-> 'application/postscript ',
'Ps '-> 'application/postscript ',
'Smi'-> 'application/SMIL ',
'Smil '-> 'application/SMIL ',
'Mmi'-> 'application/vnd. mmi ',
'Xls '-> 'application/vnd. MS-Excel ',
'Ppt '-> 'application/vnd. MS-PowerPoint ',
'Wbxml'-> 'application/vnd. WAP. wbxml ',
'Wmlc'-> 'application/vnd. WAP. wmlc ',
'Wmlsc '-> 'application/vnd. WAP. wmlscriptc ',
'Bcpio '-> 'application/X-bcpio ',
'Vcd'-> 'application/X-cdlink ',
'Pgn'-> 'application/X-chess-pgn ',
'Cpio '-> 'application/X-cpio ',
'Csh'-> 'application/X-csh ',
'Dcr '-> 'application/X-ctor ',
'Dir'-> 'application/X-ctor ',
'Dxr'-> 'application/X-ctor ',
'Dvi '-> 'application/X-DVI ',
'Spl'-> 'application/X-futuresplash ',
'Gtar '-> 'application/X-gtar ',
'Hdf'-> 'application/X-hdf ',
'Js'-> 'application/X-javas Comment ',
'Skp'-> 'application/X-koany ',
'Skd'-> 'application/X-koanc ',
'Skt'-> 'application/X-koan ',
'Skm'-> 'application/X-koan ',
'Latex '-> 'application/X-latex ',
'Nc '-> 'application/X-netcdf ',
'Cdf'-> 'application/X-netcdf ',
'Sh'-> 'application/X-Sh ',
'Shar '-> 'application/X-Shar ',
'Swf '-> 'application/X-Shockwave-flash ',
'Sit '-> 'application/X-stuffit ',
'Sv4cpio '-> 'application/x-sv4cpio ',
'Sv4crc '-> 'application/x-sv4crc ',
'Tar '-> 'application/X-tar ',
'Tcl '-> 'application/X-tcl ',
'Tex '-> 'application/X-Tex ',
'Textinfo'-> 'application/X-textinfo ',
'Text'-> 'application/X-textinfo ',
'T'-> 'application/X-troff ',
'Tr'-> 'application/X-troff ',
'Roff'-> 'application/X-troff ',
'Man '-> 'application/X-troff-man ',
'Me'-> 'application/X-troff-me ',
'Ms'-> 'application/X-troff-Ms ',
'Ustar'-> 'application/X-ustar ',
'Src'-> 'application/X-WAIS-source ',
'Xhtml ''' application/XHTML + xml ',
'Xht '-> 'application/XHTML + xml ',
'Zip '-> 'application/zip ',
'Au '-> 'audio/basic ',
'Snd'-> 'audio/basic ',
'Mid '-> 'audio/midI ',
'Midi '-> 'audio/midI ',
'Kar '-> 'audio/midI ',
'Mpga'-> 'audio/MPEG ',
'Mp2'-> 'audio/MPEG ',
'Mp3'-> 'audio/MPEG ',
'Aif'-> 'audio/X-AIFF ',
'Aiff '-> 'audio/X-AIFF ',
'Aifc '-> 'audio/X-AIFF ',
'M3u'-> 'audio/X-mpegurl ',
'Ram '-> 'audio/X-PN-RealAudio ',
'Rm '-> 'audio/X-PN-RealAudio ',
'Rpm '-> 'audio/X-PN-RealAudio-plugin ',
'A'-> 'audio/X-realaudio ',
'Wav '-> 'audio/X-WAV ',
'Pdb'-> 'chemical/X-pdb ',
'Xyz'-> 'chemical/X-xyz ',
'Bmp '-> 'image/BMP ',
'Gif'-> 'image/gif ',
'Ief'-> 'image/ief ',
'Jpeg '-> 'image/JPEG ',
'Jpg '-> 'image/JPEG ',
'Jpe '-> 'image/JPEG ',
'Png '-> 'image/PNG ',
'Tiff '-> 'image/tiff ',
'Tif '-> 'image/tiff ',
'Djvu '-> 'image/vnd. djvu ',
'Djv'-> 'image/vnd. djvu ',
'Wbmp '-> 'image/vnd. WAP. wbmp ',
'Ras '-> 'image/X-CMU-raster ',
'Pnm '-> 'image/X-portable-anymap ',
'Pbm'-> 'image/X-portable-bitmap ',
'Pgm '-> 'image/X-portable-graymap ',
'Ppm '-> 'image/X-portable-pixmap ',
'Rgb '-> 'image/X-RGB ',
'Xbm '-> 'image/X-xbitmap ',
'Xpm'-> 'image/X-xpixmap ',
'Xwd '-> 'image/X-xwindowdump ',
'Gies'-> 'model/iges ',
'Iges'-> 'model/iges ',
'Msh'-> 'model/mesh ',
'Mesh '-> 'model/mesh ',
'Silo'-> 'model/mesh ',
'Wrl'-> 'model/jpa ',
& Apos;> & apos; Model & apos ',
'Css '-> 'text/CSS ',
'Html '-> 'text/html ',
'Htm '-> 'text/html ',
'Asc '-> 'text/plain ',
'Txt '-> 'text/plain ',
'Rtx'-> 'text/richtext ',
& Apos;-& apos; text & apos;, & apos ',
'Sgml'-> 'text/sgml ',
'Sgm'-> 'text/sgml ',
'Tsv'-> 'text/TAB-separated-values ',
'Wml'-> 'text/vnd. WAP. wml ',
'Wmls'-> 'text/vnd. WAP. wmlscript ',
'Etx'-> 'text/X-setext ',
'Xsl '-> 'text/xml ',
'Xml'-> 'text/xml ',
'Mpeg '-> 'video/MPEG ',
'Mpg'-> 'video/MPEG ',
'Mpe'-> 'video/MPEG ',
'Qt '-> 'video/quicktime ',
'Mov '-> 'video/quicktime ',
'Mxu'-> 'video/vnd. mpegurl ',
'Av'-> 'video/X-msvideo ',
'Movie '-> 'video/X-SGI-movie ',
'Ice '-> 'x-conference/X-cooltalk'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.