Cách chuyển nhiều biến trong tiêu đề (Vị trí php)

Hàm header() 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à những chức năng thao tác thông tin được máy chủ Web gửi đến máy khách hoặc trình duyệt trước khi bất kỳ đầu ra nào khác được gửi đi. Hàm PHP header() gửi tiêu đề HTTP tới máy khách hoặc trình duyệt ở dạng thô. Trước khi HTML, XML, JSON hoặc đầu ra khác được gửi tới trình duyệt hoặc ứng dụng khách, dữ liệu thô được gửi cùng với yêu cầu (đặc biệt là Yêu cầu HTTP) do máy chủ tạo dưới dạng thông tin tiêu đề. Tiêu đề HTTP cung cấp thông tin bắt buộc về đối tượng được gửi trong nội dung thư chính xác hơn về yêu cầu và phản hồi

cú pháp

void header( $header, $replace = TRUE, $http_response_code )

Thông số. Hàm này chấp nhận ba tham số như đã đề cập ở trên và được mô tả bên dưới

  • tiêu đề $. Tham số này giữ chuỗi tiêu đề. Có hai loại cuộc gọi tiêu đề. Tiêu đề đầu tiên bắt đầu bằng chuỗi “HTTP/”, được sử dụng để tìm ra mã trạng thái HTTP để gửi. Trường hợp thứ hai của tiêu đề là “Vị trí. ”. Nó là tham số bắt buộc
  • $thay thế. Nó là tham số tùy chọn. Nó biểu thị tiêu đề nên thay thế tiêu đề trước đó hoặc thêm tiêu đề thứ hai. Giá trị mặc định là True (sẽ thay thế). Nếu giá trị $replace là Sai thì nó buộc nhiều tiêu đề cùng loại
  • $http_response_code. Nó là một tham số tùy chọn. Nó buộc mã phản hồi HTTP đến giá trị đã chỉ định (PHP 4. 3 trở lên)

Giá trị trả về. Hàm này không trả về bất kỳ giá trị nào

ví dụ 1




This will change location of header, i.e. redirect to the URL
4

This will change location of header, i.e. redirect to the URL
5

This will change location of header, i.e. redirect to the URL
6

This will change location of header, i.e. redirect to the URL
7

This will change location of header, i.e. redirect to the URL
8
This will change location of header, i.e. redirect to the URL
9
This will change location of header, i.e. redirect to the URL
0

This will change location of header, i.e. redirect to the URL
6

This will change location of header, i.e. redirect to the URL
1

This will change location of header, i.e. redirect to the URL
2

This will change location of header, i.e. redirect to the URL
3____14

This will change location of header, i.e. redirect to the URL
6

This will change location of header, i.e. redirect to the URL
6

đầu ra

This will change location of header, i.e. redirect to the URL

ví dụ 2




This will change location of header, i.e. redirect to the URL
4

This will change location of header, i.e. redirect to the URL
5

This will change location of header, i.e. redirect to the URL
6

Hello World!

Array ( 
    [0] => X-Powered-By: PHP/7.0.33 
    [1] => Expires: Sun, 25 Jul 1997 06:02:34 GMT 
    [2] => Cache-Control: no-cache 
    [3] => Pragma: no-cache 
)
0

This will change location of header, i.e. redirect to the URL
8
Hello World!

Array ( 
    [0] => X-Powered-By: PHP/7.0.33 
    [1] => Expires: Sun, 25 Jul 1997 06:02:34 GMT 
    [2] => Cache-Control: no-cache 
    [3] => Pragma: no-cache 
)
2
This will change location of header, i.e. redirect to the URL
0

This will change location of header, i.e. redirect to the URL
8
Hello World!

Array ( 
    [0] => X-Powered-By: PHP/7.0.33 
    [1] => Expires: Sun, 25 Jul 1997 06:02:34 GMT 
    [2] => Cache-Control: no-cache 
    [3] => Pragma: no-cache 
)
5
This will change location of header, i.e. redirect to the URL
0

This will change location of header, i.e. redirect to the URL
8
Hello World!

Array ( 
    [0] => X-Powered-By: PHP/7.0.33 
    [1] => Expires: Sun, 25 Jul 1997 06:02:34 GMT 
    [2] => Cache-Control: no-cache 
    [3] => Pragma: no-cache 
)
8
This will change location of header, i.e. redirect to the URL
0

This will change location of header, i.e. redirect to the URL
6

This will change location of header, i.e. redirect to the URL
6

This will change location of header, i.e. redirect to the URL
42

This will change location of header, i.e. redirect to the URL
43
This will change location of header, i.e. redirect to the URL
44

This will change location of header, i.e. redirect to the URL
45
This will change location of header, i.e. redirect to the URL
46

This will change location of header, i.e. redirect to the URL
47

This will change location of header, i.e. redirect to the URL
45
This will change location of header, i.e. redirect to the URL
49

This will change location of header, i.e. redirect to the URL
45
This will change location of header, i.e. redirect to the URL
51

This will change location of header, i.e. redirect to the URL
45
This will change location of header, i.e. redirect to the URL
4

This will change location of header, i.e. redirect to the URL
54
This will change location of header, i.e. redirect to the URL
55

This will change location of header, i.e. redirect to the URL
45
This will change location of header, i.e. redirect to the URL
6

This will change location of header, i.e. redirect to the URL
43
This will change location of header, i.e. redirect to the URL
59

This will change location of header, i.e. redirect to the URL
60

đầu ra

Hello World!

Array ( 
    [0] => X-Powered-By: PHP/7.0.33 
    [1] => Expires: Sun, 25 Jul 1997 06:02:34 GMT 
    [2] => Cache-Control: no-cache 
    [3] => Pragma: no-cache 
)

Ví dụ trên giúp ngăn bộ nhớ đệm bằng cách gửi thông tin tiêu đề ghi đè cài đặt trình duyệt thành không lưu bộ đệm

Ghi chú. Hàm header() được sử dụng nhiều lần trong ví dụ này vì một tiêu đề được phép gửi tại một thời điểm (kể từ PHP 4. 4) để ngăn chặn các cuộc tấn công tiêm tiêu đề

công dụng

  • Thay đổi vị trí trang
  • Đặt múi giờ
  • Đặt kiểm soát bộ đệm
  • Bắt đầu tải xuống bắt buộc
  • Gửi trạng thái HTTP

Thẩm quyền giải quyết. http. //php. net/thủ công/vi/chức năng. tiêu đề. php

PHP là ngôn ngữ kịch bản phía máy chủ được thiết kế dành riêng cho phát triển web. Bạn có thể học PHP từ đầu bằng cách làm theo Hướng dẫn PHP và Ví dụ về PHP này