温馨提示×

PHP header()的7种用法

PHP
小云
103
2023-08-28 12:59:13
栏目: 编程语言

  1. 重定向到其他页面:
header("Location: http://www.example.com");
exit;
  1. 强制下载文件:
header("Content-Disposition: attachment; filename='example.pdf'");
header("Content-Type: application/pdf");
readfile("path/to/example.pdf");
  1. 设置刷新页面时间:
header("Refresh: 5; url=http://www.example.com");
echo "页面将在5秒后刷新到新的页面";
  1. 设置页面编码:
header("Content-Type: text/html; charset=UTF-8");
  1. 禁止页面缓存:
header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");
  1. 设置页面状态码:
header("HTTP/1.1 404 Not Found");
  1. 设置文件下载大小:
header("Content-Length: " . filesize("path/to/example.pdf"));

0