PHP header()的7种用法
1. 重定向到其他页面:
```php
header("Location: http://www.example.com");
exit;
```
2. 强迫下载文件:
```php
header("Content-Disposition: attachment; filename='example.pdf'");
header("Content-Type: application/pdf");
readfile("path/to/example.pdf");
```
3. 设置刷新页面时间:
```php
header("Refresh: 5; url=http://www.example.com");
echo "页面将在5秒后刷新到新的页面";
```
4. 设置页面编码:
```php
header("Content-Type: text/html; charset=UTF⑻");
```
5. 制止页面缓存:
```php
header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");
```
6. 设置页面状态码:
```php
header("HTTP/1.1 404 Not Found");
```
7. 设置文件下载大小:
```php
header("Content-Length: " . filesize("path/to/example.pdf"));
```
TOP