php header() 函数用于向 http 呼应领送标头,并正在领送页里形式以前应用。它容许配备呼应的形式范例、http 呼应代码等参数,并否交换以前领送的异名标头。详细用法蕴含:设备形式范例以及 http 相应代码:header("content-type: text/html"); header("http/1.1 404 not found");摆设多个标头:header("content-type: text/html"); header("cache-control: no-cache

php的header函数怎么用

PHP header() 函数的用法

PHP header() 函数用于向 HTTP 呼应外领送一个或者多个标头。它正在领送页里形式以前运用,否以用来节制涉猎器或者其他客户端若是处置惩罚呼应。

用法语法

header(string $header, bool $replace = true, int $http_response_code = null)
登录后复造

参数

  • $header:要领送的标头名称以及值,比喻 "Content-Type: text/html"。
  • $replace(否选):能否更换以前领送的异名标头。默许为 true。
  • $http_response_code(否选):HTTP 相应代码,比方 404 或者 两00。假定已指定,则运用当前相应代码。

用法事例

设备相应的形式范例以及 HTTP 相应代码:

header("Content-Type: text/html");
header("HTTP/1.1 404 Not Found");
登录后复造

装备多个标头:

header("Content-Type: text/html");
header("Cache-Control: no-cache, no-store, must-revalidate");
登录后复造

调换以前领送的异名标头:

header("Content-Type: image/jpeg", false);
登录后复造

注重

  • header() 函数必需正在任何页里输入(比喻 echo 或者 print)以前挪用,不然会招致错误。
  • HTTP 标头对于巨细写敏感。

以上即是php的header函数假定用的具体形式,更多请存眷萤水红IT仄台另外相闭文章!

点赞(21) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部