Phpheader () function and its common use. Syntax: send the original message to the client. note: The Header parameter description is required for string. Specifies the header string to be sent. Replace is optional. Indicates whether the header replaces the syntax:
Send the original
Note:
Header
Parameter description:
|
Parameters |
Description |
|
String |
Required. Specifies the header string to be sent. |
|
Replace |
Optional. Indicates whether the header replaces the previous header or adds the second header.
The default value is |
|
Http_response_code |
Optional. Set |
Examples of common usage:
1. sending server status code
Header ("HTTP/1.0 404 Not Found ");
Common status codes
|
Status Code |
Description |
|
100-199 |
The request is successfully received, and the client is required to submit the next request to complete the entire process. |
|
200-299 |
The request is successfully received and the entire processing process has been completed. |
|
300-399 |
The client needs to further refine the request if the requested resource has been moved to a new address. |
|
400-499 |
Client request errors |
|
500-599 |
Server errors, common |
2. page jump
3 s
3. set browser cache
Force the browser not to cache!
("Expires: Mon, 26 Jul 1997 05:00:00 GMT"("Cache-Control:no-cache,must-revalidate"("pragma:no-cache"("Last-Modified: ". ("D, j M Y H:i:s T") );
Description
Expiresgmdate ("M d y h: I: s ");
Common Cache-control values:
|
Cache-directive |
Description |
|
Public |
All content will be cached |
|
Private |
Content is only cached in private cache |
|
No-cache |
All content will not be cached |
|
No-store |
All content is not cached in the cache or |
|
Must-revalidation/proxy-revalidation |
If the cached content is invalid, the request must be sent to the server. |
|
Max-age = xxx (xxx is numeric) |
The cached content will be stored in |
1. open a new window
If you specify
Header ("cache-control: max-age = 5 ");
Indicates
2. press enter in the address bar.
If the value is private
If the value is
No matter what the value is, it will be accessed again
When
In addition,
Expires: Fri, 31 Dec 1999 16:00:00 GMT
5. "Last-Modified
The first time a browser requests
The second request from the client
If the server resources do not change, the system automatically returns
Smart developers will
The procedure is as follows:
1. the client requests a page (
2. server return page
3. the client displays the page and displays the page together
4. customer re-request page
5. the server checks
3. file download
For example, download
('Content-type: application/pdf'('Content-Disposition: attachment; filename="downloaded.pdf"'('1.pdf');
Average
(“content-type:application/octet-(“Accept-Ranges:bytes”);(“content-disposition:attachement;filename=(“Accept-length:”.);
In fact, to better understand this, you still have to study the http protocol!
References: Internet ....
Before sending the original token to the client, you must note that the Header parameter description is required for string. Specifies the header string to be sent. Replace is optional. Indicates whether the header is replaced...