PHP Header Sample code recommended

Source: Internet
Author: User
Copy CodeThe code is as follows:


/*** function:php Header () examples (PHP)
* * Desc:some examples on what to use the header () function of phpyou find a detailed tutorial at expertsrt.com (中文版) o R at Ffm.junetz.de (German). These is also a good help on caching at web-caching.com.
* * Example:see below.

Tip:You can use the these sites to check your headers:web-sniffer.net, delorie.com or www.forret.com.
* * Author:jonas John
*/
Fix 404 Pages:
Header (' http/1.1 OK ');
Set 404 Header:
Header (' http/1.1 404 Not Found ');
Set Moved permanently header (Good for redrictions)
Use with location header
Header (' http/1.1 301 Moved permanently ');
Redirect to a new location:
Header (' location:http://www.example.org/');
Redrict with delay:
Header (' refresh:10; url=http://www.example.org/');
print ' You'll be redirected in ten seconds ';
You could also use the HTML syntax://
Override x-powered-by:php:
Header (' x-powered-by:php/4.4.0 ');
Header (' x-powered-by:brain/0.6b ');
Content language (en = 中文版)
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 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, 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 would be displayed if the user hits cancel or ';
print ' enters wrong login data ';
?>

The above describes the PHP header sample code recommendations, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.