search
Homephp教程PHP源码Common examples of commonly used headers in php

The functions of headers in PHP include many jumps and sending header information. In addition to these two functions, are there other functions? Let's take a look at common examples of commonly used headers in PHP.

Record commonly used header information here


header('HTTP/1.1 200 OK'); // ok normal access
header('HTTP/1.1 404 Not Found'); //Notify the browser that the page does not exist
header('HTTP/1.1 301 Moved Permanently'); //Set the address to be permanently redirected 301
header('Location: http://www.ruonu.com/'); //Jump to a new address
header('Refresh: 10; url=http://www.ruonu.com/'); //Delayed redirection, that is, jump every few seconds
header('X-Powered-By: PHP/7.0.0'); //Modify X-Powered-By information
header('Content-language: en'); //Document language
header('Content-Length: 1234'); //Set content length
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); //Tell the browser the last modified time
header('HTTP/1.1 304 Not Modified'); //Tell the browser that the document content has not changed

###Content Type###
header('Content-Type: text/html; charset=utf-8'); //Web page encoding
header('Content-Type: text/plain'); //Plain text format
header('Content-Type: image/jpeg'); //JPG, JPEG
header('Content-Type: application/zip'); // ZIP file
header('Content-Type: application/pdf'); // PDF file
header('Content-Type: audio/mpeg'); // Audio file
header('Content-type: text/css'); //css file
header('Content-type: text/javascript'); //js file
header('Content-type: application/json'); //json
header('Content-type: application/pdf'); //pdf
header('Content-type: text/xml'); //xml
header('Content-Type: application/x-shockw**e-flash'); //Flash animation

######

###Declare a downloaded file###
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="ITblog.zip"');
header('Content-Transfer-Encoding: binary');
readfile('test.zip');
######

###Disable caching for 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');
######

###Display a login dialog box that requires verification###
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
######


###Declare an xls file that needs to be downloaded###
header('Content-Disposition: attachment; filename=ithhc.xlsx');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: '.filesize('./test.xls'));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile('./test.xls');
######

?><script>ec(2);</script>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.