PHP header()的7种用法

50次阅读
没有评论

共计 562 个字符,预计需要花费 2 分钟才能阅读完成。

  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"));

丸趣 TV 网 – 提供最优质的资源集合!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-13发表,共计562字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)