Home >Backend Development >PHP Problem >How to set HTTP header with php header function
php header function sets the HTTP header method: [header( 'Content-Type: text/html; charset=utf-8 '); ], which means setting the encoding to utf-8.
The example of PHP header function setting HTTP header is as follows:
(Video tutorial recommendation: java video tutorial)
Define encoding
header( 'Content-Type:text/html;charset=utf-8 ');
Set a 404 header:
header('HTTP/1.1 404 Not Found');
Set the address to be permanently redirected
header('HTTP/1.1 301 Moved Permanently');
Go to a new address
header('Location: http://www.example.org/');
File delayed redirection:
header('Refresh: 10; url=http://www.example.org/'); print 'You will be redirected in 10 seconds';
Tell the browser the last modification time
$time = time() - 60; // or filemtime($fn), etc header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
Disable caching for the current document
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Pragma: no-cache');
Related recommendations : php training
The above is the detailed content of How to set HTTP header with php header function. For more information, please follow other related articles on the PHP Chinese website!