温馨提示×

PHP header()的用法有哪些

PHP
小亿
101
2023-08-28 23:07:01
栏目: 编程语言

PHP中的header()函数用于发送HTTP标头。

以下是header()函数的一些常见用法:

  1. 设置页面重定向:
header("Location: http://www.example.com");
exit;
  1. 设置页面字符编码:
header("Content-Type: text/html; charset=UTF-8");
  1. 设置缓存控制:
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  1. 设置文件下载:
header("Content-Disposition: attachment; filename=\"example.txt\"");
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
  1. 设置页面刷新:
header("Refresh: 5; url=http://www.example.com");

这些只是header()函数的一些常见用法,实际上还有许多其他用法。根据具体需求,你可以使用不同的HTTP标头来控制页面的行为。

0