PHP header function usage tutorial

Source: Internet
Author: User

In php, the header () function is very useful, especially when ajax is used.

The following is a detailed description of the header.

<? Php P2/** 3 * php header function usage example *: www.jbxue.com * // fix 404 pages: header ('HTTP/1.1 200 404 OK '); // set header: header ('HTTP/1.1 404 Not Found '); // set Moved Permanently header (good for redrictions) // use with location header ('HTTP/1.1 301 Moved Permanently '); // redirect to a new location: header ('location: http://www.jbxue.com /'); // redrict with delay: header ('refresh: 10; url = http :// Www.jbxue.com/'); print 'you will be redirected in 10 seconds'; // You coshould also use the HTML syntax: // <meta http-equiv = "refresh" content = "10; http://www.jbxue.com //> // override X-Powered-By: PHP: header ('x-Powered-: PHP/4.4.0 '); header ('x-Powered-By: Brain/0.6b'); // content language (en = English) header ('content-language: en '); // last modified (good for caching) $ time = time ()-60; // or Filemtime ($ fn), etc header ('Last-Modified :'. gmdate ('d, d m y h: I: s', $ time ). 'gmt'); // header for telling the browser that the content // did not get changed header ('HTTP/1.1 304 Not modified '); // set content length (good for caching): header ('content-Length: 1234 '); // Headers for an download: 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 of the current document: 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 pastheader ('pragma: no-cache'); // set content type: header ('content-Type: text/html; charset = iso-8859-1 '); Header ('content-Type: text/html; charset = UTF-8 '); header ('content-Type: text/plain '); // plain text file header ('content-Type: image/jpeg '); // JPG picture header ('content-Type: application/zip '); // ZIP file header ('content-Type: application/pdf '); // PDF file header ('content-Type: audio/mpeg '); // Audio MPEG (MP3 ,...) File header ('content-Type: application/x-shockwave-flash'); // flash animation // show sign in box 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';?>

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.