Summary of common methods for PHPheader () functions-PHP Tutorial-php Tutorial

Source: Internet
Author: User
Summary of common methods for PHPheader () functions. Definition code copy code: header (Content-Type: texthtml; charsetutf-8); Atom copy code: header (Content-type: applicationatom + xml ); CSS copy // define the encoding

The code is as follows:

Header ('content-Type: text/html; charset = utf-8 ');


// Atom

The code is as follows:

Header ('content-type: application/atom + XML ');


// CSS

The code is as follows:

Header ('content-type: text/css ');


// Javascript

The code is as follows:

Header ('content-type: text/javascript ');


// JPEG Image

The code is as follows:

Header ('content-type: image/jpeg ');


// JSON

The code is as follows:

Header ('content-type: application/json ');


// PDF

The code is as follows:

Header ('content-type: application/pdf ');


// RSS

The code is as follows:

Header ('content-Type: application/rss + xml; charset = ISO-8859-1 ');


// Text (Plain)

The code is as follows:

Header ('content-type: text/plain ');


// XML

The code is as follows:

Header ('content-type: text/XML ');


// OK

The code is as follows:

Header ('http/1.1 200 OK ');


// Set a 404 header:

The code is as follows:

Header ('http/1.1 404 Not Found ');


// Set the address to be permanently redirected

The code is as follows:

Header ('http/1.1 301 Moved Permanently ');


// Go to a new address

The code is as follows:

Header ('Location: http://www.example.org /');


// File delay redirection:

The code is as follows:

Header ('refresh: 10; url = http://www.example.org /');
Print 'You will be redirected in 10 seconds ';
// Of course, you can also use html syntax to implement
// The code is as follows:

Header ('x-Powered-By: PHP/4.4.0 ');
Header ('x-Powered-By: Brain/0.6b ');


// Document language

The code is as follows:

Header ('content-language: en ');


// Tell the browser the last modification time

The code is as follows:

$ Time = time ()-60; // or filemtime ($ fn), etc
Header ('last-Modified: '. gmdate ('d, d m y h: I: S', $ time). 'gmt ');


// Tell the browser that the document content has not changed

The code is as follows:

Header ('http/1.1 304 Not modified ');


// Set the content length

The code is as follows:

Header ('content-Length: 1234 ');


// Set it to a download type

The code is 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

The code is as follows:

Header ('cache-Control: no-Cache, no-store, max-age = 0, must-revalidate ');
Header ('expires: Mon, 26 Jul 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 the login dialog box

The code is as follows:

Header ('http/1.1 401 unauthorized ');
Header ('www-Authenticate: Basic realm = "Top Secret "');
Print 'text that will be displayed if the user hits cancel or ';
Print 'enters wrong login data ';

The authorization code is as follows: header ('content-Type: text/html; charset = utf-8 '); // The Atom code is as follows: header ('content-type: application/atom + XML'); // CSS copy...

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.