Hướng dẫn what is the syntax for including a header in php? - cú pháp để bao gồm một tiêu đề trong php là gì?

❮ Tham chiếu mạng PHP

Thí dụ

Gửi ba tiêu đề HTTP để ngăn bộ đệm trang:

// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>

... ...

...
...


Lưu ý: Có các tùy chọn mà người dùng có thể đặt để thay đổi cài đặt bộ đệm mặc định của trình duyệt. Bằng cách gửi các tiêu đề ở trên, bạn sẽ ghi đè bất kỳ cài đặt nào trong số đó và buộc trình duyệt không bộ đệm! There are options that users may set to change the browser's default caching settings. By sending the headers above, you will override any of those settings and force the browser to not cache!


Định nghĩa và cách sử dụng

Hàm tiêu đề () gửi tiêu đề HTTP RAW đến máy khách.

Điều quan trọng là phải lưu ý rằng hàm tiêu đề () phải được gọi trước khi bất kỳ đầu ra thực tế nào được gửi!

Cú pháp

Tiêu đề (tiêu đề, thay thế, http_response_code)

Giá trị tham số

Tham sốSự mô tả
tiêu đềYêu cầu. Chỉ định chuỗi tiêu đề để gửi
thay thếKhông bắt buộc. Cho biết liệu tiêu đề có nên thay thế một tiêu đề tương tự trước đó hay thêm một tiêu đề mới cùng loại. Mặc định là đúng (sẽ thay thế). Sai cho phép nhiều tiêu đề cùng loại
http_response_codeKhông bắt buộc. Buộc mã phản hồi HTTP vào giá trị được chỉ định


Chi tiết kỹ thuật

Giá trị trở lại:Không
Phiên bản PHP:4.0+
PHP Changelog:Php 5.1.2: Bây giờ ngăn chặn hơn một tiêu đề được gửi cùng một lúc. Đây là một sự bảo vệ chống lại các cuộc tấn công tiêm tiêu đề

Nhiều ví dụ hơn

Thí dụ

Cho phép người dùng được nhắc lưu tệp PDF được tạo (tiêu đề định vị nội dung được sử dụng để cung cấp tên tệp được đề xuất và buộc trình duyệt phải hiển thị hộp thoại Lưu):

header("Content-type:application/pdf");

... ...
header("Content-Disposition:attachment;filename='downloaded.pdf'");

Lưu ý: Có các tùy chọn mà người dùng có thể đặt để thay đổi cài đặt bộ đệm mặc định của trình duyệt. Bằng cách gửi các tiêu đề ở trên, bạn sẽ ghi đè bất kỳ cài đặt nào trong số đó và buộc trình duyệt không bộ đệm!
readfile("original.pdf");
?>

Định nghĩa và cách sử dụng

Hàm tiêu đề () gửi tiêu đề HTTP RAW đến máy khách.
...



❮ Tham chiếu mạng PHP


7 năm trước

4 năm trước

I strongly recommend, that you use

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");

instead of

header("HTTP/1.1 404 Not Found");

I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header.

Most of the pages were displayed correct, but on some of them apache added weird content to it:

A 4-digits HexCode on top of the page (before any output of my php script), seems to be some kind of checksum, because it changes from page to page and browser to browser. (same code for same page and browser)

"0" at the bottom of the page (after the complete output of my php script)

It took me quite a while to find out about the wrong protocol in the HTTP-header.

SK89Q ¶

Dev tại Omikrosys dot com ¶

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 0

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 1

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 2

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 3

12 năm trước

14 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 5

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 6

12 năm trước

JP tại WebGraphe Dot Com ¶

18 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 8

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 9

instead of 0

Chris at Ocproducts Dot Com ¶

4 năm trước

instead of 2

instead of 3

instead of 4

instead of 5

instead of 6

SK89Q ¶

Dev tại Omikrosys dot com ¶

instead of 8

12 năm trước

4 năm trước

instead of 9

JP tại WebGraphe Dot Com ¶

13 năm trước

header("HTTP/1.1 404 Not Found"); 0

header("HTTP/1.1 404 Not Found"); 1

header("HTTP/1.1 404 Not Found"); 2

header("HTTP/1.1 404 Not Found"); 3

header("HTTP/1.1 404 Not Found"); 4

header("HTTP/1.1 404 Not Found"); 5

Vinay Kotekar ¶

13 năm trước

header("HTTP/1.1 404 Not Found"); 7

header("HTTP/1.1 404 Not Found"); 8

header("HTTP/1.1 404 Not Found"); 9

Vinay Kotekar ¶

10 năm trước

I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header. 0

I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header. 1

I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header. 2

I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header. 3

I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header. 4

I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header. 5

I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header. 6

David ¶

5 năm trước

I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header. 8

I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header. 9

razvan_bc tại yahoo dot com ¶

4 năm trước

Most of the pages were displayed correct, but on some of them apache added weird content to it: 1

Most of the pages were displayed correct, but on some of them apache added weird content to it: 2

Most of the pages were displayed correct, but on some of them apache added weird content to it: 3

SK89Q ¶

14 năm trước

Most of the pages were displayed correct, but on some of them apache added weird content to it: 4

Most of the pages were displayed correct, but on some of them apache added weird content to it: 5

Most of the pages were displayed correct, but on some of them apache added weird content to it: 6

Most of the pages were displayed correct, but on some of them apache added weird content to it: 7

Shutout2730 tại Yahoo Dot Com ¶

14 năm trước

Most of the pages were displayed correct, but on some of them apache added weird content to it: 8

Most of the pages were displayed correct, but on some of them apache added weird content to it: 9

A 4-digits HexCode on top of the page (before any output of my php script), seems to be some kind of checksum, because it changes from page to page and browser to browser. (same code for same page and browser) 0

A 4-digits HexCode on top of the page (before any output of my php script), seems to be some kind of checksum, because it changes from page to page and browser to browser. (same code for same page and browser) 1

A 4-digits HexCode on top of the page (before any output of my php script), seems to be some kind of checksum, because it changes from page to page and browser to browser. (same code for same page and browser) 2

Shutout2730 tại Yahoo Dot Com ¶

Dev tại Omikrosys dot com ¶

A 4-digits HexCode on top of the page (before any output of my php script), seems to be some kind of checksum, because it changes from page to page and browser to browser. (same code for same page and browser) 4

A 4-digits HexCode on top of the page (before any output of my php script), seems to be some kind of checksum, because it changes from page to page and browser to browser. (same code for same page and browser) 5

A 4-digits HexCode on top of the page (before any output of my php script), seems to be some kind of checksum, because it changes from page to page and browser to browser. (same code for same page and browser) 6

12 năm trước

JP tại WebGraphe Dot Com ¶

A 4-digits HexCode on top of the page (before any output of my php script), seems to be some kind of checksum, because it changes from page to page and browser to browser. (same code for same page and browser) 8

A 4-digits HexCode on top of the page (before any output of my php script), seems to be some kind of checksum, because it changes from page to page and browser to browser. (same code for same page and browser) 9

"0" at the bottom of the page (after the complete output of my php script) 0

"0" at the bottom of the page (after the complete output of my php script) 1

18 năm trước

5 năm trước

"0" at the bottom of the page (after the complete output of my php script) 3

"0" at the bottom of the page (after the complete output of my php script) 4

"0" at the bottom of the page (after the complete output of my php script) 5

razvan_bc tại yahoo dot com ¶

4 năm trước

"0" at the bottom of the page (after the complete output of my php script) 7

"0" at the bottom of the page (after the complete output of my php script) 8

SK89Q ¶

14 năm trước

It took me quite a while to find out about the wrong protocol in the HTTP-header.0

It took me quite a while to find out about the wrong protocol in the HTTP-header.1

Shutout2730 tại Yahoo Dot Com ¶

Dev tại Omikrosys dot com ¶

It took me quite a while to find out about the wrong protocol in the HTTP-header.3

It took me quite a while to find out about the wrong protocol in the HTTP-header.4

12 năm trước

Dev tại Omikrosys dot com ¶

It took me quite a while to find out about the wrong protocol in the HTTP-header.6

It took me quite a while to find out about the wrong protocol in the HTTP-header.7

It took me quite a while to find out about the wrong protocol in the HTTP-header.8

It took me quite a while to find out about the wrong protocol in the HTTP-header.9

0

1

12 năm trước

JP tại WebGraphe Dot Com ¶

Dev tại Omikrosys dot com ¶

3

4

5

6

7

8

9

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 00

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 01

12 năm trước

4 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 02

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 03

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 04

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 05

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 06

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 07

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 08

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 09

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 10

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 11

Người tị nạn ¶

12 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 13

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 14

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 15

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 16

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 17

Bmindful tại fleetingiamge dot org ¶

19 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 19

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 20

nobileelpirata tại hotmail dot com ¶

15 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 22

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 23

er dot ellison dot nyc tại gmail dot com ¶

6 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 25

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 26

Jamie ¶

13 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 28

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 29

David Spector ¶

1 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 31

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 32

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 33

Hamza Dot Eljaouhari Dot Etudes tại Gmail Dot Com ¶

4 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 35

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 36

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 37

Aschmidt tại Anamera Dot Net

4 năm trước

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 39

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 40

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 41

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 42

Aschmidt tại Anamera Dot Net

Cedric tại gn dot apc dot org ¶

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 44

Cú pháp của tiêu đề là gì?

Giá trị tham số.

Việc sử dụng tiêu đề () trong PHP là gì?

PHP |Hàm tiêu đề ().Hàm tiêu đề () là một hàm sẵn có trong PHP được sử dụng để gửi tiêu đề HTTP thô.Các chức năng HTTP là các chức năng thao tác thông tin được gửi đến máy khách hoặc trình duyệt của máy chủ web, trước khi bất kỳ đầu ra nào khác được gửi.to send a raw HTTP header. The HTTP functions are those functions which manipulate information sent to the client or browser by the Web server, before any other output has been sent.

PHP tiêu đề ở đâu?

Để tìm tệp và tự chỉnh sửa nó, hãy truy cập WP-Content> Chủ đề> Tên của bạn> Tiêu đề.php.wp-content > themes > your-theme-name > header. php.

Tiêu đề loại nội dung trong PHP là gì?

Tiêu đề loại nội dung được sử dụng để chỉ ra loại phương tiện của tài nguyên.Loại phương tiện là một chuỗi được gửi cùng với tệp biểu thị định dạng của tệp.Ví dụ: đối với tệp hình ảnh, loại phương tiện của nó sẽ giống như Image/PNG hoặc Image/JPG, v.v. để đáp ứng, nó kể về loại nội dung được trả về, cho máy khách.used to indicate the media type of the resource. The media type is a string sent along with the file indicating the format of the file. For example, for image file its media type will be like image/png or image/jpg, etc. In response, it tells about the type of returned content, to the client.