PHP header()的用法有哪些

   2025-02-22 8020
核心提示:PHP中的header()函数用于发送HTTP标头。以下是header()函数的一些常见用法:设置页面重定向:header(Location: http://www.examp

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标头来控制页面的行为。

 
 
更多>同类维修知识
推荐图文
推荐维修知识
点击排行
网站首页  |  关于我们  |  联系方式  |  用户协议  |  隐私政策  |  网站留言