新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

PHP header()的用法有哪几种,php的header作用

发布时间:2023-08-29 08:02:53

PHP header()的用法有哪几种

PHP中的header()函数用于发送HTTP标头。
以下是header()函数的一些常见用法:
1. 设置页面重定向:
```php
header("Location: http://www.example.com");
exit;
```
2. 设置页面字符编码:
```php
header("Content-Type: text/html; charset=UTF⑻");
```
3. 设置缓存控制:
```php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
```
4. 设置文件下载:
```php
header("Content-Disposition: attachment; filename="example.txt"");
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
```
5. 设置页面刷新:
```php
header("Refresh: 5; url=http://www.example.com");
```
这些只是header()函数的一些常见用法,实际上还有许多其他用法。根据具体需求,你可使用区分的HTTP标头来控制页面的行动。