- Header ("Location:http://www.php.net");
- ?>
Copy Code<2> forces users to get the latest information each time they access the page, rather than using a cache that exists on the client.
- Tell the browser how long this page will expire (in Greenwich Mean Time), as long as the date has passed.
- Header ("Expires:mon, Jul 1970 05:00:00 GMT");
- Tells the browser that the last update date of this page (in Greenwich Mean Time) is the same day, the purpose is to force the browser to get the latest information
- Header ("last-modified:".) Gmdate ("D, D M Y h:i:s"). "GMT");
- Tell the client browser not to use the cache
- Header ("Cache-control:no-cache, must-revalidate");
- Parameters (compatible with previous servers), which is compatible with the HTTP1.0 protocol
- Header ("Pragma:no-cache");
- Output MIME type
- Header ("Content-type:application/file");
- File length
- Header ("content-length:227685");
- Accepted range units
- Header ("Accept-ranges:bytes");
- File name in the File Save dialog box by default
- Header ("content-disposition:attachment; Filename= $filename ");
- ?>
Copy Code<3> output status value to the browser, mainly for access rights control
- Header (' http/1.1 401 Unauthorized ');
- Header (' status:401 unauthorized ');
- ?>
Copy CodeFor example, to restrict a user from accessing the page, you can set the status to 404, as shown below, so that the browser is displayed as if the page does not exist
- Header (' http/1.1 404 Not Found ');
- Header ("status:404 not Found");
- ?>
Copy CodeNote: The traditional header must contain one of the following three headers and can only occur once. CONTENT-TYPE:XXXX/YYYY location:xxxx:yyyy/zzzz status:nnn xxxxxx can appear more than two times in the new multi-header specification (Multipart MIME). The above is about the header information of the PHP content introduction, more information can be consulted: the header of the PHP file is detailed. Give some concrete examples. Example 1: This example redirects the browser to the official PHP website.
- Header ("Location:http://www.php.net"); Exit
Copy CodeExample 2: The user can get the latest information each time, instead of the Proxy or cache data, you may use the following headers
- Header ("Expires:mon, Jul 1997 05:00:00 GMT");
- Header ("last-modified:".) Gmdate ("D, D M Y h:i:s"). "GMT"); Header ("Cache-control:no-cache, must-revalidate");
- Header ("Pragma:no-cache");
Copy CodeExample 3: Let the user's browser appear unable to find the file information.
- Header ("status:404 not Found");
Copy CodeExample 4: Let the user download the file.
- Header ("Content-type:application/x-gzip");
- Header ("content-disposition:attachment; Filename= file name ");
- Header ("Content-description:php3 Generated Data");
Copy CodeNote: No matter how many headers the page has, it will execute the last one, but conditionally, for example:
- Header (' location:http://bbs.it-home.org ');
- Header (' location:http://www.g.cn ');
- Header (' location:http://www.baidu.com ');
- Skip to Baidu
- Header (' location:http://bbs.it-home.org '); Echo ' Programmer's house ';
- Header (' location:http://www.g.cn ');
- Header (' location:http://www.baidu.com ');
- Skip to Google
Copy Code |