您的位置:首页 > 编程语言 > PHP开发

PHP header函数使用大全

2015-03-20 13:13 253 查看
PHP header函数大全

header('Content-Type: text/html; charset=utf-8');

header('Location: http://blog.snsgou.com/');
view
source

?

01
<?php
02
//
fix 404 pages:
03
header(
'HTTP/1.1
200 OK'
);
04
05
//
set 404 header:
06
header(
'HTTP/1.1
404 Not Found'
);
07
08
//
set Moved Permanently header ('good for redrictions')
09
//
use with location header
10
header(
'HTTP/1.1
301 Moved Permanently'
);
11
12
//
redirect to a new location:
' target='_blank'>http://blog.snsgou.com/'[/code]
);
13
header(
'Location: 
);
14
15
//
redrict with delay:
16
header(
'Refresh:
10; url=http://blog.snsgou.com/'
);
17
//print
You will be redirected in 10 seconds;
18
19
//
you could also use the HTML syntax:// <meta http-equiv="refresh" content="10;http://blog.snsgou.com/ />
20
21
//
override X-Powered-By: PHP:
22
header(
'X-Powered-By:
PHP/4.4.0'
);
23
header(
'X-Powered-By:
Brain/0.6b'
);
24
25
//
content language ('en = English')
26
header(
'Content-language:
en'
);
27
28
//
last modified ('good for caching')
29
$time
=
time(
''
)
– 60;
//
or filemtime('$fn'), etc
30
header(
'Last-Modified:
.gmdate("D, d M Y H:i:s, '
.
$time
.
'").
GMT'
);
31
32
//
header for telling the browser that the content
33
//
did not get changed
34
header(
'HTTP/1.1
304 Not Modified'
);
35
36
//
set content length ('good for caching'):
37
header(
'Content-Length:
1234'
);
38
39
//
Headers for an download:
40
header(
'Content-Type:
application/octet-stream'
);
41
header(
'Content-Disposition:
attachment; filename="example.zip"'
);
42
header(
'Content-Transfer-Encoding:
binary'
);
43
44
//
load the file to send:readfile('example.zip');
45
//
Disable caching of the current document:
46
header(
'Cache-Control:
no-cache, no-store, max-age=0, must-revalidate'
);
47
header(
'Expires:
Mon, 26 Jul 1997 05:00:00 GMT'
);
48
//
Date in the pastheader('Pragma: no-cache');
49
50
//
set content type:
51
header(
'Content-Type:
text/html; charset=iso-8859-1'
);
52
header(
'Content-Type:
text/html; charset=utf-8'
);
53
header(
'Content-Type:
text/plain'
);
54
55
//
plain text file
56
header(
'Content-Type:
image/jpeg'
);
57
58
//
JPG picture
59
header(
'Content-Type:
application/zip'
);
60
61
//
ZIP file
62
header(
'Content-Type:
application/pdf'
);
63
64
//
PDF file
65
header(
'Content-Type:
audio/mpeg'
);
66
67
//
Audio MPEG ('MP3,…') file
68
header(
'Content-Type:
application/x-shockwave-flash'
);
69
70
//
Flash animation// show sign in box
71
header(
'HTTP/1.1
401 Unauthorized'
);
72
header(
'WWW-Authenticate:
Basic realm="Top Secret"'
);
73
//print
Text that will be displayed if the user hits cancel or ;
74
//print
enters wrong login data;
75
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: