Summary of commonly used header header definitions in PHP_PHP tutorial

WBOY
Release: 2016-07-13 09:50:00
Original
971 people have browsed it

A summary of commonly used header definitions in PHP

This article mainly gives you a summary of the commonly used header definitions in PHP. It is very comprehensive and detailed. Friends who need it You can refer to it.

The header() function sends raw HTTP headers to the client.

It is important to realize that the header() function must be called before any actual output is sent (in PHP 4 and above, you can use output caching to solve this problem):

 ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

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.ithhc.cn/'); //Jump to a new address

header('Refresh: 10; url=http://www.ithhc.cn/'); //Delayed redirection, that is, jump every few seconds

header('X-Powered-By: PHP/6.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 modification 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 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');

######

?>

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1018928.htmlTechArticle Summary of commonly used header definitions in PHP This article mainly introduces to you a summary of commonly used header definitions in PHP , very comprehensive and detailed, friends in need can refer to it. he...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template