以下是一些PHP中设置和获取头部信息的实例,表格形式呈现:

| 实例 | 代码 | 说明 |

实例php头部信息,PHP头部信息实例详解  第1张

| --- | --- | --- |

| 设置HTTP状态码 | `header('HTTP/1.1 200 OK');` | 返回200状态码,表示请求成功 |

| 设置自定义HTTP头部 | `header('Content-Type: text/html; charset=UTF-8');` | 设置响应内容的类型和字符集 |

| 设置响应内容编码 | `header('Content-Encoding: gzip');` | 设置响应内容的编码格式,例如gzip压缩 |

| 重定向到另一个页面 | `header('Location: http://www.example.com/');` | 将浏览器重定向到指定的URL |

| 设置Cookie | `setcookie('name', 'value', time() + 3600, '/');` | 创建一个名为"