Skip to content

Commit eecf090

Browse files
Improve headers_list() example (#1007)
Two & 1/2 things with the PHP example code: 1. `X-` prefix header names June 2012 [1], [2]. 2. PHP prepends the `default_charset` [3] on any `text/*` media type in Content-Type header, unless the `charset` is with the `header()` call, like in the example. 3. PHP version 5.1.3 (May 2006) -> 8.0.11, the X-Powered-By header [4] removed (only distracting w/ the example). PHP version in use to generate the output: 8.0.11. [1]: https://datatracker.ietf.org/doc/html/rfc6648 [2]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers [3]: https://www.php.net/manual/en/ini.core.php#ini.default-charset [4]: https://www.php.net/manual/en/ini.core.php#ini.expose-php Co-authored-by: Tiffany <[email protected]>
1 parent f57925e commit eecf090

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

reference/network/functions/headers-list.xml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<refname>headers_list</refname>
66
<refpurpose>Returns a list of response headers sent (or ready to send)</refpurpose>
77
</refnamediv>
8-
8+
99
<refsect1 role="description">
1010
&reftitle.description;
1111
<methodsynopsis>
@@ -35,7 +35,7 @@
3535
&reftitle.examples;
3636
<para>
3737
<example>
38-
<title>Examples using <function>headers_list</function></title>
38+
<title>Example using <function>headers_list</function></title>
3939
<programlisting role="php">
4040
<![CDATA[
4141
<?php
@@ -45,29 +45,27 @@ setcookie('foo', 'bar');
4545
4646
/* Define a custom response header
4747
This will be ignored by most clients */
48-
header("X-Sample-Test: foo");
48+
header("Example-Test: foo");
4949
5050
/* Specify plain text content in our response */
51-
header('Content-type: text/plain');
51+
header('Content-Type: text/plain; charset=UTF-8');
5252
5353
/* What headers are going to be sent? */
5454
var_dump(headers_list());
5555
5656
?>
5757
]]>
5858
</programlisting>
59-
&example.outputs;
59+
&example.outputs.similar;
6060
<screen>
6161
<![CDATA[
62-
array(4) {
62+
array(3) {
6363
[0]=>
64-
string(23) "X-Powered-By: PHP/5.1.3"
65-
[1]=>
6664
string(19) "Set-Cookie: foo=bar"
65+
[1]=>
66+
string(17) "Example-Test: foo"
6767
[2]=>
68-
string(18) "X-Sample-Test: foo"
69-
[3]=>
70-
string(24) "Content-type: text/plain"
68+
string(39) "Content-Type: text/plain; charset=UTF-8"
7169
}
7270
7371
]]>

0 commit comments

Comments
 (0)