How to set HTTP header with php header function

王林
Release: 2023-03-07 08:46:02
Original
2045 people have browsed it

php header function sets the HTTP header method: [header( 'Content-Type: text/html; charset=utf-8 '); ], which means setting the encoding to utf-8.

How to set HTTP header with php header function

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 ');
Copy after login

Set a 404 header:

header('HTTP/1.1 404 Not Found');
Copy after login

Set the address to be permanently redirected

header('HTTP/1.1 301 Moved Permanently');
Copy after login

Go to a new address

header('Location: http://www.example.org/');
Copy after login

File delayed redirection:

header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
Copy after login

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');
Copy after login

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');
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!