php-doc-en/functions/http.sgml
James Gingerich 82c6591284 Many minor cleanups.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@9864 c90b9560-bf6c-de11-be94-00142212c4b1
1999-06-20 03:04:56 +00:00

152 lines
6.1 KiB
Text

<reference id="ref.http">
<title>functions related to HTTP</title>
<titleabbrev>HTTP</titleabbrev>
<partintro>
<simpara>
These functions let you manipulate the output sent back to the
remote browser right down to the HTTP protocol level.
</partintro>
<refentry id="function.header">
<refnamediv>
<refname>header</refname>
<refpurpose>Send a raw HTTP header</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>header</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcsynopsis>
<para>
The <function>Header</function> function is used at the top of an
<acronym>HTML</acronym> file to send raw <acronym>HTTP</acronym>
header strings. See the <ulink url="&spec.http1.1;">HTTP 1.1
Specification</ulink> for more information on raw http headers.
<emphasis>Note:</emphasis> Remember that the
<function>Header</function> function must be called before any actual
output is sent either by normal HTML tags or from PHP. It is a very
common error to read code with <function>include</function> or with
auto_prepend and have spaces or empty lines in this code that force
output before <function>header</function> is called.
<para>
<informalexample><programlisting role=php>
Header("Location: http://www.php.net"); /* Redirect browser to PHP web site */
exit; /* Make sure that code below does not get executed when we redirect. */
</programlisting></informalexample>
<para>
PHP scripts often generate dynamic HTML that must not be cached
by the client browser or any proxy caches between the server and the
client browser. Many proxies and clients can be forced to disable
caching with
<informalexample><programlisting role=php>
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // HTTP/1.0
</programlisting></informalexample>
</refsect1>
</refentry>
<refentry id="function.setcookie">
<refnamediv>
<refname>setcookie</refname>
<refpurpose>Send a cookie</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>setcookie</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
<paramdef>int <parameter>expire</parameter></paramdef>
<paramdef>string <parameter>path</parameter></paramdef>
<paramdef>string <parameter>domain</parameter></paramdef>
<paramdef>int <parameter>secure</parameter></paramdef>
</funcsynopsis>
<para>
<function>SetCookie</function> defines a cookie to be sent along
with the rest of the header information. Cookies must be sent
<emphasis>before</emphasis> any other headers are sent (this is a
restriction of Cookies, not PHP). This requires you to place
calls to this function before any <literal>&lt;html></literal> or
<literal>&lt;head></literal> tags.
<para>
All the arguments except the <parameter>name</parameter> argument are
optional. If only the name argument is present, the cookie by that name will
be deleted from the remote client. You may also replace any
argument with an empty string (<emphasis>&quot;&quot;</emphasis>)
in order to skip that argument. The
<parameter>expire</parameter> and <parameter>secure</parameter>
arguments are integers and cannot be skipped with an empty
string. Use a zero (<emphasis>0</emphasis>) instead. The
<parameter>expire</parameter> argument is a regular Unix time
integer as returned by the <function>time</function> or
<function>mktime</function> functions. The
<parameter>secure</parameter> indicates that the cookie should
only be transmitted over a secure HTTPS connection.
<para>
Common Pitfalls:
<simpara>
Cookies will not become visable until the next loading of a page that
the cookie should be visable for.
<simpara>
Multiple calls to setcookie in the same script will be performed in the reverse
order. If you are trying to delete one cookie before inserting another you
should put the insert before the delete.
<para>
Some examples follow:
<example>
<title>SetCookie examples</title>
<programlisting role=php>
SetCookie("TestCookie","Test Value");
SetCookie("TestCookie",$value,time()+3600); /* expire in 1 hour */
SetCookie("TestCookie",$value,time()+3600,"/~rasmus/",".utoronto.ca",1);
</programlisting></example>
<para>
Note that the value portion of the cookie will automatically be
urlencoded when you send the cookie, and when it is received, it
is automatically decoded and assigned to a variable by the same
name as the cookie name. To see the contents of our test
cookie in a script, simply use one of the following examples:
<informalexample><programlisting role=php>
echo $TestCookie;
echo $HTTP_COOKIE_VARS["TestCookie"];
</programlisting></informalexample>
<para>
For more information on cookies, see Netscape's cookie
specification at <ulink url="&spec.cookies;">&spec.cookies;</ulink>.
<simpara>
<simpara>
Microsoft Internet Explorer 4 with Service Pack 1 applied does
not correctly deal with cookies that have their path parameter
set.
<simpara>
Netscape Communicator 4.05 and Microsoft Internet Explorer 3.x
appear to handle cookies incorrectly when the path and time
are not set.
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->