Linux 拨号vps windows公众号手机端

PHP header()的用法有哪些

lewis 7年前 (2018-10-05) 阅读数 12 #程序编程
文章标签 PHP

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

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门