PHP header()的用法有哪些

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

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

设置页面重定向:

header("Location: http://www.example.com");
exit;

设置页面字符编码:

header("Content-Type: text/html; charset=UTF-8");

设置缓存控制:

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

设置文件下载:

header("Content-Disposition: attachment; filename=\"example.txt\"");
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");

设置页面刷新:

header("Refresh: 5; url=http://www.example.com");

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

阅读剩余
THE END