1
0
mirror of https://github.com/php/doc-en.git synced 2026-03-23 23:32:18 +01:00

Merged the dev_xml branch into the main trunk.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@16980 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Stig Bakken
1999-12-10 00:34:45 +00:00
parent a9171a6d94
commit c8f33da553
92 changed files with 2415 additions and 118 deletions

View File

@@ -193,7 +193,7 @@ convert_string_to_number(arg1); /* Converts string to either LONG or DOUBLE dep
variable in the symbol table:
<itemizedlist>
<listitem><simpara>SET_VAR_STRING(name,value) <footnoteref linkend="symtab-1"></simpara></listitem>
<listitem><simpara>SET_VAR_STRING(name,value) <footnoteref linkend="symtab-1"/></simpara></listitem>
<listitem><simpara>SET_VAR_DOUBLE(name,value)</simpara></listitem>
<listitem><simpara>SET_VAR_LONG(name,value)</simpara></listitem>
</itemizedlist></para>

View File

@@ -1,90 +1,90 @@
<!ENTITY preface SYSTEM "preface.sgml">
<!ENTITY bookinfo SYSTEM "bookinfo.sgml">
<!ENTITY preface SYSTEM "preface.xml">
<!ENTITY bookinfo SYSTEM "bookinfo.xml">
<!ENTITY chapter.copyright SYSTEM "chapters/copyright.sgml">
<!ENTITY chapter.introduction SYSTEM "chapters/intro.sgml">
<!ENTITY chapter.install SYSTEM "chapters/install.sgml">
<!ENTITY chapter.config SYSTEM "chapters/config.sgml">
<!ENTITY chapter.security SYSTEM "chapters/security.sgml">
<!ENTITY chapter.copyright SYSTEM "chapters/copyright.xml">
<!ENTITY chapter.introduction SYSTEM "chapters/intro.xml">
<!ENTITY chapter.install SYSTEM "chapters/install.xml">
<!ENTITY chapter.config SYSTEM "chapters/config.xml">
<!ENTITY chapter.security SYSTEM "chapters/security.xml">
<!ENTITY features.http-auth SYSTEM "features/http-auth.sgml">
<!ENTITY features.cookies SYSTEM "features/cookies.sgml">
<!ENTITY features.file-upload SYSTEM "features/file-upload.sgml">
<!ENTITY features.remote-files SYSTEM "features/remote-files.sgml">
<!ENTITY features.connection-handling SYSTEM "features/connection-handling.sgml">
<!ENTITY features.error-handling SYSTEM "features/error-handling.sgml">
<!ENTITY features.images SYSTEM "features/images.sgml">
<!ENTITY features.persistent-connections SYSTEM "features/persistent-connections.sgml">
<!ENTITY features.http-auth SYSTEM "features/http-auth.xml">
<!ENTITY features.cookies SYSTEM "features/cookies.xml">
<!ENTITY features.file-upload SYSTEM "features/file-upload.xml">
<!ENTITY features.remote-files SYSTEM "features/remote-files.xml">
<!ENTITY features.connection-handling SYSTEM "features/connection-handling.xml">
<!ENTITY features.error-handling SYSTEM "features/error-handling.xml">
<!ENTITY features.images SYSTEM "features/images.xml">
<!ENTITY features.persistent-connections SYSTEM "features/persistent-connections.xml">
<!ENTITY language.basic-syntax SYSTEM "language/basic-syntax.sgml">
<!ENTITY language.types SYSTEM "language/types.sgml">
<!ENTITY language.variables SYSTEM "language/variables.sgml">
<!ENTITY language.constants SYSTEM "language/constants.sgml">
<!ENTITY language.expressions SYSTEM "language/expressions.sgml">
<!ENTITY language.operators SYSTEM "language/operators.sgml">
<!ENTITY language.functions SYSTEM "language/functions.sgml">
<!ENTITY language.control-structures SYSTEM "language/control-structures.sgml">
<!ENTITY language.oop SYSTEM "language/oop.sgml">
<!ENTITY language.basic-syntax SYSTEM "language/basic-syntax.xml">
<!ENTITY language.types SYSTEM "language/types.xml">
<!ENTITY language.variables SYSTEM "language/variables.xml">
<!ENTITY language.constants SYSTEM "language/constants.xml">
<!ENTITY language.expressions SYSTEM "language/expressions.xml">
<!ENTITY language.operators SYSTEM "language/operators.xml">
<!ENTITY language.functions SYSTEM "language/functions.xml">
<!ENTITY language.control-structures SYSTEM "language/control-structures.xml">
<!ENTITY language.oop SYSTEM "language/oop.xml">
<!ENTITY reference.adabas SYSTEM "functions/adabas.sgml">
<!ENTITY reference.apache SYSTEM "functions/apache.sgml">
<!ENTITY reference.array SYSTEM "functions/array.sgml">
<!ENTITY reference.aspell SYSTEM "functions/aspell.sgml">
<!ENTITY reference.bc SYSTEM "functions/bc.sgml">
<!ENTITY reference.cpdf SYSTEM "functions/cpdf.sgml">
<!ENTITY reference.datetime SYSTEM "functions/datetime.sgml">
<!ENTITY reference.dbase SYSTEM "functions/dbase.sgml">
<!ENTITY reference.dba SYSTEM "functions/dba.sgml">
<!ENTITY reference.dbm SYSTEM "functions/dbm.sgml">
<!ENTITY reference.calendar SYSTEM "functions/calendar.sgml">
<!ENTITY reference.dir SYSTEM "functions/dir.sgml">
<!ENTITY reference.dl SYSTEM "functions/dl.sgml">
<!ENTITY reference.exec SYSTEM "functions/exec.sgml">
<!ENTITY reference.fdf SYSTEM "functions/fdf.sgml">
<!ENTITY reference.filepro SYSTEM "functions/filepro.sgml">
<!ENTITY reference.filesystem SYSTEM "functions/filesystem.sgml">
<!ENTITY reference.ftp SYSTEM "functions/ftp.sgml">
<!ENTITY reference.http SYSTEM "functions/http.sgml">
<!ENTITY reference.hw SYSTEM "functions/hw.sgml">
<!ENTITY reference.ibase SYSTEM "functions/ibase.sgml">
<!ENTITY reference.ifx SYSTEM "functions/ifx.sgml">
<!ENTITY reference.image SYSTEM "functions/image.sgml">
<!ENTITY reference.imap SYSTEM "functions/imap.sgml">
<!ENTITY reference.mcal SYSTEM "functions/mcal.sgml">
<!ENTITY reference.ldap SYSTEM "functions/ldap.sgml">
<!ENTITY reference.mail SYSTEM "functions/mail.sgml">
<!ENTITY reference.math SYSTEM "functions/math.sgml">
<!ENTITY reference.mcrypt SYSTEM "functions/mcrypt.sgml">
<!ENTITY reference.mhash SYSTEM "functions/mhash.sgml">
<!ENTITY reference.misc SYSTEM "functions/misc.sgml">
<!ENTITY reference.msql SYSTEM "functions/msql.sgml">
<!ENTITY reference.mssql SYSTEM "functions/mssql.sgml">
<!ENTITY reference.mysql SYSTEM "functions/mysql.sgml">
<!ENTITY reference.nis SYSTEM "functions/nis.sgml">
<!ENTITY reference.sybase SYSTEM "functions/sybase.sgml">
<!ENTITY reference.network SYSTEM "functions/network.sgml">
<!ENTITY reference.oci8 SYSTEM "functions/oci8.sgml">
<!ENTITY reference.oracle SYSTEM "functions/oracle.sgml">
<!ENTITY reference.pcre SYSTEM "functions/pcre.sgml">
<!ENTITY reference.pdf SYSTEM "functions/pdf.sgml">
<!ENTITY reference.posix SYSTEM "functions/posix.sgml">
<!ENTITY reference.recode SYSTEM "functions/recode.sgml">
<!ENTITY reference.info SYSTEM "functions/info.sgml">
<!ENTITY reference.pgsql SYSTEM "functions/pgsql.sgml">
<!ENTITY reference.regex SYSTEM "functions/regex.sgml">
<!ENTITY reference.sem SYSTEM "functions/sem.sgml">
<!ENTITY reference.session SYSTEM "functions/session.sgml">
<!ENTITY reference.solid SYSTEM "functions/solid.sgml">
<!ENTITY reference.snmp SYSTEM "functions/snmp.sgml">
<!ENTITY reference.strings SYSTEM "functions/strings.sgml">
<!ENTITY reference.uodbc SYSTEM "functions/uodbc.sgml">
<!ENTITY reference.url SYSTEM "functions/url.sgml">
<!ENTITY reference.var SYSTEM "functions/var.sgml">
<!ENTITY reference.vmailmgr SYSTEM "functions/vmailmgr.sgml">
<!ENTITY reference.wddx SYSTEM "functions/wddx.sgml">
<!ENTITY reference.zlib SYSTEM "functions/zlib.sgml">
<!ENTITY reference.xml SYSTEM "functions/xml.sgml">
<!ENTITY reference.adabas SYSTEM "functions/adabas.xml">
<!ENTITY reference.apache SYSTEM "functions/apache.xml">
<!ENTITY reference.array SYSTEM "functions/array.xml">
<!ENTITY reference.aspell SYSTEM "functions/aspell.xml">
<!ENTITY reference.bc SYSTEM "functions/bc.xml">
<!ENTITY reference.cpdf SYSTEM "functions/cpdf.xml">
<!ENTITY reference.datetime SYSTEM "functions/datetime.xml">
<!ENTITY reference.dbase SYSTEM "functions/dbase.xml">
<!ENTITY reference.dba SYSTEM "functions/dba.xml">
<!ENTITY reference.dbm SYSTEM "functions/dbm.xml">
<!ENTITY reference.calendar SYSTEM "functions/calendar.xml">
<!ENTITY reference.dir SYSTEM "functions/dir.xml">
<!ENTITY reference.dl SYSTEM "functions/dl.xml">
<!ENTITY reference.exec SYSTEM "functions/exec.xml">
<!ENTITY reference.fdf SYSTEM "functions/fdf.xml">
<!ENTITY reference.filepro SYSTEM "functions/filepro.xml">
<!ENTITY reference.filesystem SYSTEM "functions/filesystem.xml">
<!ENTITY reference.ftp SYSTEM "functions/ftp.xml">
<!ENTITY reference.http SYSTEM "functions/http.xml">
<!ENTITY reference.hw SYSTEM "functions/hw.xml">
<!ENTITY reference.ibase SYSTEM "functions/ibase.xml">
<!ENTITY reference.ifx SYSTEM "functions/ifx.xml">
<!ENTITY reference.image SYSTEM "functions/image.xml">
<!ENTITY reference.imap SYSTEM "functions/imap.xml">
<!ENTITY reference.mcal SYSTEM "functions/mcal.xml">
<!ENTITY reference.ldap SYSTEM "functions/ldap.xml">
<!ENTITY reference.mail SYSTEM "functions/mail.xml">
<!ENTITY reference.math SYSTEM "functions/math.xml">
<!ENTITY reference.mcrypt SYSTEM "functions/mcrypt.xml">
<!ENTITY reference.mhash SYSTEM "functions/mhash.xml">
<!ENTITY reference.misc SYSTEM "functions/misc.xml">
<!ENTITY reference.msql SYSTEM "functions/msql.xml">
<!ENTITY reference.mssql SYSTEM "functions/mssql.xml">
<!ENTITY reference.mysql SYSTEM "functions/mysql.xml">
<!ENTITY reference.nis SYSTEM "functions/nis.xml">
<!ENTITY reference.sybase SYSTEM "functions/sybase.xml">
<!ENTITY reference.network SYSTEM "functions/network.xml">
<!ENTITY reference.oci8 SYSTEM "functions/oci8.xml">
<!ENTITY reference.oracle SYSTEM "functions/oracle.xml">
<!ENTITY reference.pcre SYSTEM "functions/pcre.xml">
<!ENTITY reference.pdf SYSTEM "functions/pdf.xml">
<!ENTITY reference.posix SYSTEM "functions/posix.xml">
<!ENTITY reference.recode SYSTEM "functions/recode.xml">
<!ENTITY reference.info SYSTEM "functions/info.xml">
<!ENTITY reference.pgsql SYSTEM "functions/pgsql.xml">
<!ENTITY reference.regex SYSTEM "functions/regex.xml">
<!ENTITY reference.sem SYSTEM "functions/sem.xml">
<!ENTITY reference.session SYSTEM "functions/session.xml">
<!ENTITY reference.solid SYSTEM "functions/solid.xml">
<!ENTITY reference.snmp SYSTEM "functions/snmp.xml">
<!ENTITY reference.strings SYSTEM "functions/strings.xml">
<!ENTITY reference.uodbc SYSTEM "functions/uodbc.xml">
<!ENTITY reference.url SYSTEM "functions/url.xml">
<!ENTITY reference.var SYSTEM "functions/var.xml">
<!ENTITY reference.vmailmgr SYSTEM "functions/vmailmgr.xml">
<!ENTITY reference.wddx SYSTEM "functions/wddx.xml">
<!ENTITY reference.zlib SYSTEM "functions/zlib.xml">
<!ENTITY reference.xml SYSTEM "functions/xml.xml">
<!ENTITY appendix.migration SYSTEM "appendices/migration.sgml">
<!ENTITY appendix.development SYSTEM "appendices/phpdevel.sgml">
<!ENTITY appendix.debugger SYSTEM "appendices/debugger.sgml">
<!ENTITY appendix.migration SYSTEM "appendices/migration.xml">
<!ENTITY appendix.development SYSTEM "appendices/phpdevel.xml">
<!ENTITY appendix.debugger SYSTEM "appendices/debugger.xml">

View File

@@ -83,7 +83,7 @@
<title>Description</title>
<funcsynopsis>
<funcdef>array <function>getallheaders</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
This function returns an associative array of all the HTTP headers in the

View File

@@ -13,7 +13,7 @@
<title>Description</title>
<funcsynopsis>
<funcdef>array <function>array</function></funcdef>
<varargs>
<varargs/>
</funcsynopsis>
<para>
Returns an array of the parameters. The parameters can be given
@@ -1343,7 +1343,7 @@ fruits[d] = lemon
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>list</function></funcdef>
<varargs>
<varargs/>
</funcsynopsis>
<para>
Like <function>array</function>, this is not really a function,

View File

@@ -282,7 +282,7 @@ echo gmstrftime ("%b %d %Y %H:%M:%S",mktime(20,0,0,12,31,98))."\n";
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>microtime</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
Returns the string "msec sec" where sec is the current time
@@ -438,7 +438,7 @@ print(strftime("%A.\n"));
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>time</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
Returns the current time measured in the number of seconds since

View File

@@ -1,4 +1,4 @@
<reference>
<reference id="ref.dba">
<title>Database (dbm-style) abstraction layer functions</title>
<titleabbrev>dba</titleabbrev>
@@ -117,7 +117,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</partintro>
<refentry>
<refentry id="function.dba-close">
<refnamediv>
<refname>dba_close</refname>
<refpurpose>Close database</refpurpose>
@@ -149,7 +149,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-delete">
<refnamediv>
<refname>dba_delete</refname>
<refpurpose>Delete entry specified by key</refpurpose>
@@ -189,7 +189,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-exists">
<refnamediv>
<refname>dba_exists</refname>
<refpurpose>Check whether key exists</refpurpose>
@@ -229,7 +229,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-fetch">
<refnamediv>
<refname>dba_fetch</refname>
<refpurpose>Fetch data specified by key</refpurpose>
@@ -269,7 +269,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-firstkey">
<refnamediv>
<refname>dba_firstkey</refname>
<refpurpose>Fetch first key</refpurpose>
@@ -302,7 +302,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-insert">
<refnamediv>
<refname>dba_insert</refname>
<refpurpose>Insert entry</refpurpose>
@@ -347,7 +347,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-nextkey">
<refnamediv>
<refname>dba_nextkey</refname>
<refpurpose>Fetch next key</refpurpose>
@@ -380,7 +380,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-popen">
<refnamediv>
<refname>dba_popen</refname>
<refpurpose>Open database persistently</refpurpose>
@@ -428,7 +428,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-open">
<refnamediv>
<refname>dba_open</refname>
<refpurpose>Open database</refpurpose>
@@ -476,7 +476,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-optimize">
<refnamediv>
<refname>dba_optimize</refname>
<refpurpose>Optimize database</refpurpose>
@@ -508,7 +508,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-replace">
<refnamediv>
<refname>dba_replace</refname>
<refpurpose>Replace or insert entry</refpurpose>
@@ -552,7 +552,7 @@ for($i = 0; $i &lt; count($handle_later); $i++)
</refsect1>
</refentry>
<refentry>
<refentry id="function.dba-sync">
<refnamediv>
<refname>dba_sync</refname>
<refpurpose>Synchronize database</refpurpose>

View File

@@ -102,7 +102,7 @@
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>filepro_fieldcount</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
Returns the number of fields (columns) in the opened filePro
@@ -121,7 +121,7 @@
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>filepro_rowcount</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
Returns the number of rows in the opened filePro database.</para>

View File

@@ -140,7 +140,7 @@ chmod( "/somedir/somefile", 0755 ); // octal; correct value of mode
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>clearstatcache</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
Invoking the <systemitem>stat</systemitem> or

View File

@@ -429,7 +429,7 @@ ifx_free_result($res_id);
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>ifx_error</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
The Informix error codes (SQLSTATE & SQLCODE) formatted as

View File

@@ -254,7 +254,7 @@ This is a cup with my coffee in it.
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>exit</function></funcdef>
<void>
<void/>
</funcsynopsis>
<simpara>
This language construct terminates parsing of the script. It

View File

@@ -624,7 +624,7 @@
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>msql_list_dbs</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
<function>msql_list_dbs</function> will return a result pointer
@@ -755,7 +755,7 @@
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>msql_numrows</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
Identical to <function>msql_num_rows</function>.</para>

View File

@@ -50,7 +50,7 @@
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>closelog</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
<function>closelog</function> closes the descriptor being used to
@@ -68,7 +68,7 @@
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>debugger_off</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
Disables the internal PHP debugger. The debugger is still under

2069
functions/pdf.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -268,7 +268,7 @@ close
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>session_start</function></funcdef>
<void>
<void/>
</funcsynopsis>
<simpara>
<function>session_start</function> creates a session (or resumes
@@ -292,7 +292,7 @@ close
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>session_destroy</function></funcdef>
<void>
<void/>
</funcsynopsis>
<simpara>
<function>session_destroy</function> destroys all of the data
@@ -537,7 +537,7 @@ echo "The previous session name was $previous_name&lt;p&gt;";
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>session_encode</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>
<function>session_encode</function> returns a string with the

View File

@@ -396,7 +396,7 @@ $pieces = explode(" ", $pizza);
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>flush</function></funcdef>
<void>
<void/>
</funcsynopsis>
<simpara>
Flushes the output buffers of PHP and whatever backend PHP is

View File

@@ -170,7 +170,7 @@
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>odbc_close_all</function></funcdef>
<void>
<void/>
</funcsynopsis>
<para>

228
security/index.xml Normal file
View File

@@ -0,0 +1,228 @@
<chapter id="security">
<title>Security</title>
<simpara>
PHP is a powerful language and the interpreter, whether included
in a web server as a module or executed as a separate
<acronym>CGI</acronym> binary, is able to access files, execute
commands and open network connections on the server. These
properties make anything run on a web server insecure by default.
PHP is designed specifically to be a more secure language for
writing CGI programs than Perl or C, and with correct selection of
compile-time and runtime configuration options it gives you
exactly the combination of freedom and security you need.</simpara>
<simpara>
As there are many different ways of utilizing PHP, there are many
configuration options controlling its behaviour. A large
selection of options guarantees you can use PHP for a lot of
purposes, but it also means there are combinations of these
options and server configurations that result in an insecure
setup. This chapter explains the different configuration option
combinations and the situations they can be safely used.</simpara>
<sect1 id="security.cgi">
<title>CGI binary</title>
<sect2>
<title>Possible attacks</title>
<simpara>
Using PHP as a <acronym>CGI</acronym> binary is an option for
setups that for some reason do not wish to integrate PHP as a
module into server software (like Apache), or will use PHP with
different kinds of CGI wrappers to create safe chroot and setuid
environments for scripts. This setup usually involves
installing executable PHP binary to the web server cgi-bin
directory. CERT advisory <ulink url="http://www.cert.org/advisories/CA-96.11.interpreters_in_cgi_bin_dir.html">CA-96.11</ulink>
recommends against placing any interpreters into cgi-bin. Even
if the PHP binary can be used as a standalone interpreter, PHP
is designed to prevent the attacks this setup makes possible:</simpara>
<itemizedlist>
<listitem><simpara>Accessing system files:
<filename role="url">http://my.host/cgi-bin/php?/etc/passwd</filename></simpara>
<simpara>
The query information in a url after the question mark (?)
is passed as command line arguments to the interpreter by the
CGI interface. Usually interpreters open and execute the
file specified as the first argument on the command line.</simpara>
<simpara>
When invoked as a CGI binary, PHP refuses to interpret the
command line arguments.
</simpara></listitem>
<listitem><simpara>Accessing any web document on server:
<filename role="url">http://my.host/cgi-bin/php/secret/doc.html</filename></simpara>
<simpara>
The path information part of the url after the PHP binary
name, <filename role="uri">/secret/doc.html</filename> is
conventionally used to specify the name of the file to be
opened and interpreted by the <acronym>CGI</acronym> program.
Usually some web server configuration directives (Apache:
Action) are used to redirect requests to documents like
<filename role="url">http://my.host/secret/script.php3</filename> to the
PHP interpreter. With this setup, the web server first checks
the access permissions to the directory <filename role="uri">/secret</filename>, and after that creates the
redirected request <filename role="url">http://my.host/cgi-bin/php/secret/script.php3</filename>.
Unfortunately, if the request is originally given in this
form, no access checks are made by web server for file
<filename role="uri">/secret/script.php3</filename>, but only
for the <filename role="uri">/cgi-bin/php</filename> file. This
way any user able to access <filename role="uri">/cgi-bin/php</filename> is able to access any
protected document on the web server.</simpara>
<simpara>
In PHP, compile-time configuration option <link linkend="enable-force-cgi-redirect">--enable-force-cgi-redirect</link>
and runtime configuration directives <link linkend="ini.doc-root">doc_root</link> and <link linkend="ini.user-dir">user_dir</link> can be used to prevent
this attack, if the server document tree has any directories
with access restrictions. See below for full the explanation of
the different combinations.
</simpara></listitem>
</itemizedlist></sect2>
<sect2 id="security.cgi.default">
<title>Case 1: only public files served</title>
<simpara>
If your server does not have any content that is not restricted
by password or ip based access control, there is no need for
these configuration options. If your web server does not allow
you to do redirects, or the server does not have a way to
communicate to the PHP binary that the request is a safely
redirected request, you can specify the option <link linkend="enable-force-cgi-redirect">--disable-force-cgi-redirect</link>
to the configure script. You still have to make sure your PHP
scripts do not rely on one or another way of calling the script,
neither by directly <filename role="php">http://my.host/cgi-bin/php/dir/script.php3</filename>
nor by redirection <filename role="php">http://my.host/dir/script.php3</filename>.</simpara>
<simpara>
Redirection can be configured in Apache by
using AddHandler and Action directives (see below).</simpara></sect2>
<sect2 id="security.cgi.force-redirect">
<title>Case 2: using --enable-force-cgi-redirect</title>
<simpara>
This compile-time option prevents anyone from calling PHP
directly with a url like <filename role="php">http://my.host/cgi-bin/php/secretdir/script.php3</filename>.
Instead, PHP will only parse in this mode if it has gone through
a web server redirect rule.</simpara>
<simpara>
Usually the redirection in the Apache configuration is done with
the following directives:</simpara>
<programlisting role="apache-conf">
Action php3-script /cgi-bin/php
AddHandler php3-script .php3
</programlisting>
<simpara>
This option has only been tested with the Apache web server, and
relies on Apache to set the non-standard CGI environment
variable <envar>REDIRECT_STATUS</envar> on redirected requests.
If your web server does not support any way of telling if the
request is direct or redirected, you cannot use this option and
you must use one of the other ways of running the CGI version
documented here.</simpara></sect2>
<sect2 id="security.cgi.doc-root">
<title>Case 3: setting doc_root or user_dir</title>
<simpara>
To include active content, like scripts and executables, in the
web server document directories is sometimes consider an
insecure practice. If, because of some configuration mistake, the
scripts are not executed but displayed as regular HTML documents,
this may result in leakage of intellectual property or security
information like passwords. Therefore many sysadmins will
prefer setting up another directory structure for scripts that
are accessible only through the PHP CGI, and therefore always
interpreted and not displayed as such.</simpara>
<simpara>
Also if the method for making sure the requests are not
redirected, as described in the previous section, is not
available, it is necessary to set up a script doc_root that is
different from web document root.</simpara>
<simpara>
You can set the PHP script document root by the configuration
directive <link linkend="ini.doc-root">doc_root</link> in the <link linkend="configuration.file">configuration file</link>, or you
can set the environment variable <envar>PHP_DOCUMENT_ROOT</envar>.
If it is set, the CGI version of PHP will always construct the file
name to open with this <parameter>doc_root</parameter> and the path
information in the request, so you can be sure no script is executed
outside this directory (except for <parameter>user_dir</parameter>
below).</simpara>
<simpara>
Another option usable here is <link linkend="ini.user-dir">user_dir</link>. When user_dir is unset,
only thing controlling the opened file name is
<parameter>doc_root</parameter>. Opening an url like <filename role="url">http://my.host/~user/doc.php3</filename> does not
result in opening a file under users home directory, but a file
called <filename role="uri">~user/doc.php3</filename> under
doc_root (yes, a directory name starting with a tilde
[<literal>~</literal>]).</simpara>
<simpara>
If user_dir is set to for example <filename role="dir">public_php</filename>, a request like <filename role="url">http://my.host/~user/doc.php3</filename> will open a
file called <filename>doc.php3</filename> under the directory
named <filename role="dir">public_php</filename> under the home
directory of the user. If the home of the user is <filename role="dir">/home/user</filename>, the file executed is
<filename>/home/user/public_php/doc.php3</filename>.</simpara>
<simpara>
<parameter>user_dir</parameter> expansion happens regardless of
the <parameter>doc_root</parameter> setting, so you can control
the document root and user directory access separately.</simpara></sect2>
<sect2 id="security.cgi.shell">
<title>Case 4: PHP parser outside of web tree</title>
<para>
A very secure option is to put the PHP parser binary somewhere
outside of the web tree of files. In <filename role="dir">/usr/local/bin</filename>, for example. The only real
downside to this option is that you will now have to put a line
similar to:
<informalexample>
<programlisting>
#!/usr/local/bin/php
</programlisting>
</informalexample>
as the first line of any file containing PHP tags. You will
also need to make the file executable. That is, treat it
exactly as you would treat any other CGI script written in Perl
or sh or any other common scripting language which uses the
<literal>#!</literal> shell-escape mechanism for launching
itself.</para>
<para>
To get PHP to handle <envar>PATH_INFO</envar> and
<envar>PATH_TRANSLATED</envar> information correctly with this
setup, the php parser should be compiled with the <link linkend="enable-discard-path">--enable-discard-path</link>
configure option.</para></sect2></sect1>
<sect1 id="security.apache">
<title>Apache module</title>
<simpara>
When PHP is used as an Apache module it inherits Apache's user
permissions (typically those of the "nobody" user).</simpara></sect1>
</chapter>
<!-- 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:
-->