cvs: phpdoc-zh / language-snippets.ent /appendices history.xml /chapters security.xml tutorial.xml /language functions.xml /reference/mysql
reference.xml /reference/mysql/functions mysql-affected-rows.xml /reference/oracle/functions ora-bind.xml
| From: | Gregory Song | Date: | Tue, 20 May 2003 07:01:55 +0000 |
| Subject: | cvs: phpdoc-zh / language-snippets.ent /appendices history.xml /chapters security.xml tutorial.xml /language functions.xml /reference/mysql reference.xml /reference/mysql/functions mysql-affected-rows.xml /reference/oracle/functions ora-bind.xml |
||
| Groups: | php.doc.zh | ||
| Request: | Send a blank email to doc-zh+get-1480@lists.php.net to get a copy of this message | ||
gregory Tue May 20 03:01:55 2003 EDT
Modified files:
/phpdoc-zh/language functions.xml
/phpdoc-zh/appendices history.xml
/phpdoc-zh language-snippets.ent
/phpdoc-zh/reference/mysql/functions mysql-affected-rows.xml
/phpdoc-zh/reference/oracle/functions ora-bind.xml
/phpdoc-zh/reference/mysql reference.xml
/phpdoc-zh/chapters security.xml tutorial.xml
Log:
Co-Revision with the En Version...
Index: phpdoc-zh/language/functions.xml diff -u phpdoc-zh/language/functions.xml:1.16 phpdoc-zh/language/functions.xml:1.17 --- phpdoc-zh/language/functions.xml:1.16 Sat May 17 02:51:49 2003 +++ phpdoc-zh/language/functions.xml Tue May 20 03:01:53 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.16 $ --> -<!-- $Author: dallas $ --> -<!-- EN-Revision: 1.35 Maintainer: verdana Status: ready --> +<!-- $Revision: 1.17 $ --> +<!-- $Author: gregory $ --> +<!-- EN-Revision: 1.38 Maintainer: verdana Status: ready --> <!-- CREDITS: Gregory --> <chapter id="functions"> <title>º¯Êý</title> @@ -11,17 +11,22 @@ <para> Ò»¸öº¯Êý¿ÉÓÉÒÔϵÄÓï·¨À´¶¨Ò壺 - <informalexample> + </para> + <para> + <example> + <title>չʾº¯ÊýÓÃ;µÄαÂë</title> <programlisting role="php"> <![CDATA[ +<?php function foo ($arg_1, $arg_2, ..., $arg_n) { echo "Example function.\n"; return $retval; } +?> ]]> </programlisting> - </informalexample> + </example> </para> <!-- @@ -42,6 +47,8 @@ </simpara> <para> Èç¹ûÒ»¸öº¯ÊýÒÔÒÔÏÂÁ½¸ö·¶ÀýµÄ·½Ê½ÓÐÌõ¼þµÄ¶¨Ò壬Æä¶¨Ò屨ÐëÔÚµ÷ÓÃ<emphasis>֮ǰ</emphasis>Íê³É¡£ + </para> + <para> <example> <title>ÓÐÌõ¼þµÄº¯Êý</title> <programlisting role="php"> @@ -77,6 +84,8 @@ ]]> </programlisting> </example> + </para> + <para> <example> <title>º¯ÊýÖеĺ¯Êý</title> <programlisting role="php"> @@ -143,9 +152,9 @@ <function>func_get_arg</function>, ºÍ <function>func_get_args</function>¡£ PHP 3 ÖÐͨ¹ý´«µÝÒ»¸öÊý×é²ÎÊý¿ÉÒÔ´ïµ½ÀàËÆµÄЧ¹û£º - - <informalexample> - <programlisting role="php"> + </para> + <para> + <example> <![CDATA[ function takes_array($input) { @@ -153,7 +162,7 @@ } ]]> </programlisting> - </informalexample> + </example> </para> <sect2 id="functions.arguments.by-reference"> @@ -167,10 +176,13 @@ <para> Èç¹ûÏëÒªº¯ÊýµÄÒ»¸ö²ÎÊý×ÜÊÇͨ¹ýÒýÓô«µÝ£¬Äã¿ÉÒÔÔÚº¯Êý¶¨ÒåÖиòÎÊýµÄ Ç°ÃæÔ¤ÏȼÓÉÏ·ûºÅ£¨&£©£º - - <informalexample> + </para> + <para> + <example> + <title>ÓÃÒýÓô«µÝº¯Êý²ÎÊý</title> <programlisting role="php"> <![CDATA[ +<?php function add_some_extra(&$string) { $string .= 'and something extra.'; @@ -178,9 +190,10 @@ $str = 'This is a string, '; add_some_extra($str); echo $str; // outputs 'This is a string, and something extra.' +?> ]]> </programlisting> - </informalexample> + </example> </para> </sect2> @@ -190,23 +203,29 @@ <para> º¯Êý¿ÉÒÔ¶¨Òå C++ ·ç¸ñµÄ±êÁ¿²ÎÊýĬÈÏÖµ£¬ÈçÏ£º - - <informalexample> + </para> + <para> + <example> + <title>º¯ÊýÖÐĬÈϲÎÊýµÄÓÃ;</title> <programlisting role="php"> <![CDATA[ +<?php function makecoffee ($type = "cappuccino") { return "Making a cup of $type.\n"; } echo makecoffee (); echo makecoffee ("espresso"); +?> ]]> </programlisting> - </informalexample> + </example> </para> <para> ÉÏÊöƬ¶ÏµÄÊä³öÊÇ£º + </para> + <para> <screen> Making a cup of cappuccino. Making a cup of espresso. @@ -219,50 +238,58 @@ <para> Çë×¢Ò⵱ʹÓÃĬÈϲÎÊýʱ£¬ÈκÎĬÈϲÎÊý±ØÐë·ÅÔÚÈκηÇĬÈϲÎÊýµÄÓҲࣻ·ñÔò£¬ ¿ÉÄܺ¯Êý½«²»»á°´ÕÕÔ¤ÆÚµÄÇé¿ö¹¤×÷¡£¿¼ÂÇÏÂÃæµÄ´úÂëÆ¬¶Ï£º - - <informalexample> + </para> + <para> + <example> + <title>º¯ÊýĬÈϲÎÊý²»ÕýÈ·µÄÓ÷¨</title> <programlisting role="php"> <![CDATA[ +<?php function makeyogurt ($type = "acidophilus", $flavour) { return "Making a bowl of $type $flavour.\n"; } echo makeyogurt ("raspberry"); // won't work as expected +?> ]]> </programlisting> - </informalexample> + </example> </para> - <para> ÉÏÊöÀý×ÓµÄÊä³öʱ£º - + </para> + <para> <screen> Warning: Missing argument 2 in call to makeyogurt() in /usr/local/etc/httpd/htdocs/php3test/functest.html on line 41 Making a bowl of raspberry . </screen> </para> - <para> ÏÖÔÚ£¬±È½ÏÉÏÃæµÄÀý×ÓºÍÕâ¸öÀý×Ó£º - <informalexample> + </para> + <para> + <example> + <title>º¯ÊýĬÈϲÎÊýÕýÈ·µÄÓ÷¨</title> <programlisting role="php"> <![CDATA[ +<?php function makeyogurt ($flavour, $type = "acidophilus") { return "Making a bowl of $type $flavour.\n"; } echo makeyogurt ("raspberry"); // works as expected +?> ]]> </programlisting> - </informalexample> + </example> </para> - <para> Õâ¸öÀý×ÓµÄÊä³öÊÇ£º - + </para> + <para> <screen> Making a bowl of acidophilus raspberry. </screen> @@ -294,48 +321,62 @@ ֵͨ¹ýʹÓÿÉÑ¡µÄ·µ»ØÓï¾ä·µ»Ø¡£ÈκÎÀàÐͶ¼¿ÉÒÔ·µ»Ø£¬ÆäÖаüÀ¨ÁбíºÍ¶ÔÏó¡£ Õâµ¼Öº¯ÊýÁ¢¼´½áÊøËüµÄÔËÐУ¬²¢ÇÒ½«¿ØÖÆÈ¨´«µÝ»ØËü±»µ÷ÓõÄÐС£¸ü¶àÐÅÏ¢ Çë²ÎÕÕ <function>return</function>¡£ - <informalexample> + </para> + <para> + <example> + <title><function>return</function> º¯ÊýµÄÓ÷¨</title> <programlisting role="php"> <![CDATA[ +<?php function square ($num) { return $num * $num; } echo square (4); // outputs '16'. +?> ]]> </programlisting> - </informalexample> + </example> </para> <para> º¯Êý²»ÄÜ·µ»Ø¶à¸öÖµ£¬µ«ÎªÁË»ñµÃ¼òµ¥µÄ½á¹û£¬¿ÉÒÔ·µ»ØÒ»¸öÁÐ±í¡£ - - <informalexample> + </para> + <para> + <example> + <title>·µ»ØÒ»¸öÊý×éÒԵõ½¶à¸ö·µ»ØÖµ</title> <programlisting role="php"> <![CDATA[ +<?php function small_numbers() { return array (0, 1, 2); } list ($zero, $one, $two) = small_numbers(); +?> ]]> </programlisting> - </informalexample> + </example> </para> <para> ´Óº¯Êý·µ»ØÒ»¸öÒýÓã¬Äã±ØÐëÔÚº¯ÊýÉùÃ÷ºÍÖ¸ÅÉ·µ»ØÖµ¸øÒ»¸ö±äÁ¿Ê±¶¼Ê¹ÓÃÒýÓòÙ×÷·û & £º - <informalexample> + </para> + <para> + <example> + <title>Óɺ¯Êý·µ»ØÒ»¸öÒýÓÃ</title> <programlisting role="php"> <![CDATA[ +<?php function &returns_reference() { return $someref; } $newref =& returns_reference(); +?> ]]> </programlisting> - </informalexample> + </example> </para> <simpara> ÓйØÒýÓõĸü¶àÐÅÏ¢, Çë²é¿´ <link @@ -425,6 +466,20 @@ </sect1> +<sect1 id="functions.internal"> + <title>ÄÚ²¿£¨ÄÚ½¨£©º¯Êý</title> + + <para> + PHP Óкܶà±ê×¼µÄº¯ÊýºÍ½á¹¹¡£»¹ÓÐһЩº¯ÊýÐèÒªºÍÌØ¶¨µØ PHP À©Õ¹Ä£¿éÒ»Æð±àÒ룬·ñÔòÔÚʹÓÃËüÃǵÄʱºò¾Í»áµÃµ½Ò»¸öÖÂÃüµÄ¡°Î´¶¨Ò庯Êý¡±´íÎó¡£ÀýÈ磬ҪʹÓÃÖîÈç <function>imagecreatetruecolor</function> µÄ¡°<link linkend="ref.image">ͼÏñ</link>º¯Êý¡±£¬ÄúÐèÒªÔÚ±àÒë PHP µÄʱºò¼ÓÉÏ GD µÄÖ§³Ö¡£»òÕߣ¬ÒªÊ¹Óà <function>mysql_connect</function> º¯Êý£¬Äú¾ÍÐèÒªÔÚ±àÒë PHP µÄʱºò¼ÓÉÏ <link linkend="ref.mysql">MySQL</link> Ö§³Ö¡£ÁíÍ⻹ÓÐһЩºËÐĺ¯Êý£¬ÀýÈç¡°<link linkend="ref.strings">×Ö·û´®º¯Êý</link>¡±ºÍ¡°<link linkend="ref.variables">±äÁ¿º¯Êý</link>¡±£¬ËüÃÇ´æÔÚÓÚÿһ¸ö°æ±¾µÄ PHP ÖС£µ÷Óà <function>phpinfo</function> »òÕß <function>get_loaded_extensions</function> ¿ÉÒÔµÃÖª PHP ¼ÓÔØÁËÄÇЩÀ©Õ¹¿â¡£Í¬Ê±»¹Ó¦¸Ã×¢Ò⣬ºÜ¶àÀ©Õ¹¿âĬÈϾÍÊÇÓÐЧµÄ¡£PHP ÊֲᰴÕÕ²»Í¬µÄÀ©Õ¹¿â×éÖ¯ÁËËüÃǵÄÎĵµ¡£Çë²ÎÔÄ¡°<link linkend="configuration">ÅäÖÃ</link>¡±¡¢¡°<link linkend="installation">°²×°</link>¡±ÒÔ¼°¶ÀÁ¢µÄÀ©Õ¹¿âÕ½ÚÒÔ»ñÈ¡ÓйØÈçºÎÉèÖà PHP µÄÐÅÏ¢¡£ + </para> + <para> + ÊÖ²áÖС°<link linkend="about.prototypes">ÈçºÎÔĶÁº¯ÊýÔÐÍ</link>¡±½²½âÁËÈçºÎÔĶÁºÍÀí½âÒ»¸öº¯ÊýµÄÔÐÍ¡£È·ÈÏÒ»¸öº¯Êý½«·µ»ØÊ²Ã´£¬»òÕߺ¯ÊýÊÇ·ñÖ±½Ó×÷ÓÃÓÚ´«µÝµÄ²ÎÊýÊǺÜÖØÒªµÃ¡£ÀýÈ磬<function>str_replace</function> º¯Êý½«·µ»ØÐ޸ĹýµÄ×Ö·û´®£¬¶ø <function>usort</function> È´Ö±½Ó×÷ÓÃÓÚ´«µÝµÄ²ÎÊý±äÁ¿±¾Éí¡£ÊÖ²áÖУ¬Ã¿Ò»¸öº¯ÊýµÄÒ³ÃæÖж¼ÓйØÓÚº¯Êý²ÎÊý¡¢ÐÐΪ¸Ä±ä¡¢³É¹¦Óë·ñµÄ·µ»ØÖµÒÔ¼°Ê¹ÓÃÌõ¼þµÈÐÅÏ¢¡£Á˽âÕâÐ©ÖØÒªµÄ£¨³£³£ÊÇϸ΢µÄ£©²î±ðÊDZàдÕýÈ·µÄ PHP ´úÂëµÄ¹Ø¼ü¡£ + </para> + <para> + Çë²ÎÔĺ¯Êý <function>function_exists</function>¡¢<link linkend="funcref">º¯ÊýµÄÒýÓÃ</link>¡¢<function>get_extension_funcs</function> ºÍ <function>dl</function>¡£ + </para> + </sect1> + </chapter> <!-- Keep this comment at the end of the file Index: phpdoc-zh/appendices/history.xml diff -u phpdoc-zh/appendices/history.xml:1.11 phpdoc-zh/appendices/history.xml:1.12 --- phpdoc-zh/appendices/history.xml:1.11 Sat May 17 02:33:37 2003 +++ phpdoc-zh/appendices/history.xml Tue May 20 03:01:54 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.11 $ --> -<!-- $Author: dallas $ --> -<!-- EN-Revision: 1.17 Maintainer: class007 Status: ready --> +<!-- $Revision: 1.12 $ --> +<!-- $Author: gregory $ --> +<!-- EN-Revision: 1.18 Maintainer: class007 Status: ready --> <appendix id="history"> <title>PHP ¼°ÆäÏà¹Ø¹¤³ÌµÄÀúÊ·</title> <para> Index: phpdoc-zh/language-snippets.ent diff -u phpdoc-zh/language-snippets.ent:1.27 phpdoc-zh/language-snippets.ent:1.28 --- phpdoc-zh/language-snippets.ent:1.27 Tue May 6 03:26:15 2003 +++ phpdoc-zh/language-snippets.ent Tue May 20 03:01:54 2003 @@ -1,6 +1,6 @@ -<!-- $Revision: 1.27 $ --> +<!-- $Revision: 1.28 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.49 Maintainer: Gregory Status: ready --> +<!-- EN-Revision: 1.51 Maintainer: Gregory Status: ready --> <!ENTITY warn.experimental '<warning><simpara>±¾À©Õ¹Ä£¿éÊÇ<emphasis>ʵÑéÐÔ</emphasis>µÄ¡£¸ÃÄ£¿éµÄÐÐΪ£¬°üÀ¨Æäº¯ÊýµÄÃû³ÆÒÔ¼°ÆäËüÈκιØÓÚ´ËÄ£¿éµÄÎĵµ¿ÉÄÜ»áÔÚûÓÐ֪ͨµÄÇé¿öÏÂËæ PHP ÒÔºóµÄ·¢²¼¶ø¸Ä±ä¡£ÎÒÃÇÌáÐÑÄúÔÚʹÓñ¾À©Õ¹Ä£¿éµÄͬʱ×Ôµ£·çÏÕ¡£ </simpara></warning>'> @@ -136,6 +136,9 @@ <!-- These are here as helpers for manual consistency and brievety--> <!ENTITY php '<literal>PHP</literal>'> <!ENTITY safemode '<link linkend="ini.safe-mode">°²È«Ä£Ê½</link>'> + +<!-- Some MySQL Notes --> +<!ENTITY mysql.field-case '<note><simpara>¸Ãº¯Êý·µ»ØµÄ×Ö¶ÎÃûÊÇ<emphasis>´óСдÃô¸ÐµÄ</emphasis>£¡</simpara></note>'> <!-- These are using in reference/$extname/reference.xml and other supplemental files to mark section titles --> Index: phpdoc-zh/reference/mysql/functions/mysql-affected-rows.xml diff -u phpdoc-zh/reference/mysql/functions/mysql-affected-rows.xml:1.2 phpdoc-zh/reference/mysql/functions/mysql-affected-rows.xml:1.3 --- phpdoc-zh/reference/mysql/functions/mysql-affected-rows.xml:1.2 Sat Dec 28 04:28:42 2002 +++ phpdoc-zh/reference/mysql/functions/mysql-affected-rows.xml Tue May 20 03:01:54 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.6 Maintainer: yorgo Status: ready --> +<!-- EN-Revision: 1.7 Maintainer: yorgo Status: ready --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-affected-rows"> <refnamediv> @@ -53,6 +53,7 @@ /* Á¬½ÓÊý¾Ý¿â */ mysql_pconnect("localhost", "mysql_user", "mysql_password") or die ("Could not connect" . mysql_error()); + mysql_select_db("mydb"); /* Õâ»á·µ»ØÓÐЧµÄ±»É¾³ý¼Ç¼Êý¡£ */ mysql_query("DELETE FROM mytable WHERE id < 10"); @@ -82,6 +83,7 @@ /* Á¬½ÓÊý¾Ý¿â */ mysql_pconnect("localhost", "mysql_user", "mysql_password") or die ("Could not connect" . mysql_error()); + mysql_select_db("mydb"); /* Update ¼Ç¼ */ mysql_query("UPDATE mytable SET used=1 WHERE id < 10"); Index: phpdoc-zh/reference/oracle/functions/ora-bind.xml diff -u phpdoc-zh/reference/oracle/functions/ora-bind.xml:1.2 phpdoc-zh/reference/oracle/functions/ora-bind.xml:1.3 --- phpdoc-zh/reference/oracle/functions/ora-bind.xml:1.2 Tue Feb 25 03:10:04 2003 +++ phpdoc-zh/reference/oracle/functions/ora-bind.xml Tue May 20 03:01:54 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.2 Maintainer: yincheng Status: ready --> +<!-- EN-Revision: 1.3 Maintainer: yincheng Status: ready --> <!-- splitted from ./en/functions/oracle.xml, last change in rev 1.2 --> <refentry id="function.ora-bind"> <refnamediv> @@ -13,8 +13,8 @@ <methodsynopsis> <type>int</type><methodname>ora_bind</methodname> <methodparam><type>int</type><parameter>cursor</parameter></methodparam> - <methodparam><type>string</type><parameter>PHP variable name</parameter></methodparam> - <methodparam><type>string</type><parameter>SQL parameter name</parameter></methodparam> + <methodparam><type>string</type><parameter>PHP_variable_name</parameter></methodparam> + <methodparam><type>string</type><parameter>SQL_parameter_name</parameter></methodparam> <methodparam><type>int</type><parameter>length</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>type</parameter></methodparam> </methodsynopsis> @@ -32,11 +32,12 @@ ORA_BIND_OUT ´úÌæÊý×Ö¡£ </para> <para> -ora_bind ±ØÐëÔÚ <function>ora_parse</function> Ö®ºóºÍ +<function>ora_bind</function> ±ØÐëÔÚ <function>ora_parse</function> Ö®ºóºÍ <function>ora_exec</function> ֮ǰµ÷Óá£ÊäÈëÖµÓÉ°ó¶¨µÄ PHP ±äÁ¿Ö¸ÅÉ¡£ÔÚµ÷Óà <function>ora_exec</function> º¯ÊýÖ®ºó£¬Èç¹û°ó¶¨µÄ PHP ±äÁ¿ÓÐÖµÊä³ö£¬Ôò PHP ±äÁ¿½«µÈÓÚ¸ÃÖµ¡£ - <informalexample> + <example> + <title><function>ora_bind</function> º¯Êý·¶Àý</title> <programlisting role="php"> <![CDATA[ <?php @@ -50,7 +51,7 @@ ?> ]]> </programlisting> - </informalexample> + </example> </para> </refsect1> </refentry> Index: phpdoc-zh/reference/mysql/reference.xml diff -u phpdoc-zh/reference/mysql/reference.xml:1.8 phpdoc-zh/reference/mysql/reference.xml:1.9 --- phpdoc-zh/reference/mysql/reference.xml:1.8 Sat Dec 28 04:09:54 2002 +++ phpdoc-zh/reference/mysql/reference.xml Tue May 20 03:01:54 2003 @@ -1,8 +1,7 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.15 Maintainer: yorgo Status: ready --> -<!-- CREDITS: Gregory --> +<!-- EN-Revision: 1.16 Maintainer: Gregory Status: ready --> <reference id="ref.mysql"> <title>MySQL º¯Êý¿â</title> <titleabbrev>MySQL</titleabbrev> @@ -53,13 +52,13 @@ <?php /* Á¬½ÓÑ¡ÔñÊý¾Ý¿â */ $link = mysql_connect("mysql_host", "mysql_user", "mysql_password") - or die("Could not connect"); + or die("Could not connect : " . mysql_error()); print "Connected successfully"; mysql_select_db("my_database") or die("Could not select database"); /* Ö´ÐÐ SQL ²éѯ */ $query = "SELECT * FROM my_table"; - $result = mysql_query($query) or die("Query failed"); + $result = mysql_query($query) or die("Query failed : " . mysql_error()); /* ÔÚ HTML ÖдòÓ¡½á¹û */ print "<table>\n"; Index: phpdoc-zh/chapters/security.xml diff -u phpdoc-zh/chapters/security.xml:1.6 phpdoc-zh/chapters/security.xml:1.7 --- phpdoc-zh/chapters/security.xml:1.6 Tue Apr 1 04:15:12 2003 +++ phpdoc-zh/chapters/security.xml Tue May 20 03:01:55 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.52 Maintainer: Gregory Status: ready --> +<!-- EN-Revision: 1.55 Maintainer: Gregory Status: ready --> <chapter id="security"> <title>°²È«</title> @@ -780,83 +780,142 @@ </sect1> <sect1 id="security.registerglobals"> - <title>ÀûÓÃÈ«¾Ö±äÁ¿×¢²á£¨Register Globals£©</title> + <title>Using Register Globals</title> + <para> + Perhaps the most controversial change in PHP is when the default value + for the PHP directive <link linkend="ini.register-globals"> + register_globals</link> went from ON to OFF in PHP + <ulink url="&url.php.release4.2.0;">4.2.0</ulink>. Reliance on this + directive was quite common and many people didn't even know it existed + and assumed it's just how PHP works. This page will explain how one can + write insecure code with this directive but keep in mind that the + directive itself isn't insecure but rather it's the misuse of it. + </para> + <para> + When on, register_globals will inject (poison) your scripts will all + sorts of variables, like request variables from html forms. This + coupled with the fact that PHP doesn't require variable initialization + means writing insecure code is that much easier. It was a difficult + decision, but the PHP community decided to disable this directive by + default. When on, people use variables yet really don't know for sure + where they come from and can only assume. Internal variables that are + defined in the script itself get mixed up with request data sent by + users and disabling register_globals changes this. Let's demonstrate + with an example misuse of register_globals: + </para> <para> - One feature of PHP that can be used to enhance security is configuring PHP with - <link linkend="ini.register-globals">register_globals</link> = off. - By turning off the ability for any user-submitted variable to be injected - into PHP code, you can reduce the amount of variable - poisoning a potential attacker may inflict. They will have - to take the additional time to forge submissions, and your - internal variables are effectively isolated from user - submitted data. - </para> - <para> - While it does slightly increase the amount of effort required - to work with PHP, it has been argued that the benefits far - outweigh the effort. <example> - <title>ÔÚ register_globals = on µÄÇé¿öϹ¤×÷</title> + <title>Example misuse with register_globals = on</title> <programlisting role="php"> <![CDATA[ <?php -if ($username) { // can be forged by a user in get/post/cookies - $good_login = 1; +// define $authorized = true only if user is authenticated +if (authenticated_user()) { + $authorized = true; } -if ($good_login == 1) { // can be forged by a user in get/post/cookies, - fpassthru ("/highly/sensitive/data/index.html"); +// Because we didn't first initialize $authorized as false, this might be +// defined through register_globals, like from GET auth.php?authorized=1 +// So, anyone can be seen as authenticated! +if ($authorized) { + include "/highly/sensitive/data.php"; } ?> ]]> </programlisting> </example> + </para> + <para> + When register_globals = on, our logic above may be compromised. When + off, <varname>$authorized</varname> can't be set via request so it'll + be fine, although it really is generally a good programming practice to + initialize variables first. For example, in our example above we might + have first done <literal>$authorized = false</literal>. Doing this + first means our above code would work with register_globals on or off as + users by default would be unauthorized. + </para> + <para> + Another example is that of <link linkend="ref.session">sessions</link>. + When register_globals = on, we could also use + <varname>$username</varname> in our example below but again you must + realize that <varname>$username</varname> could also come from other + means, such as GET (through the URL). + </para> + <para> <example> - <title>ÔÚ register_globals = off µÄÇé¿öϹ¤×÷</title> + <title>Example use of sessions with register_globals on or off</title> <programlisting role="php"> <![CDATA[ <?php -if($_COOKIE['username']){ - // can only come from a cookie, forged or otherwise - $good_login = 1; - fpassthru ("/highly/sensitive/data/index.html"); +// We wouldn't know where $username came from but do know $_SESSION is +// for session data +if (isset($_SESSION['username'])) { + + echo "Hello <b>{$_SESSION['username']}</b>"; + +} else { + + echo "Hello <b>Guest</b><br />"; + echo "Would you like to login?"; + } ?> ]]> </programlisting> </example> - By using this wisely, it's even possible to take preventative - measures to warn when forging is being attempted. If you know - ahead of time exactly where a variable should be coming from, - you can check to see if submitted data is coming from an - inappropriate kind of submission. While it doesn't guarantee - that data has not been forged, it does require an attacker - to guess the right kind of forging. + </para> + <para> + It's even possible to take preventative measures to warn when forging is + being attempted. If you know ahead of time exactly where a variable + should be coming from, you can check to see if the submitted data is + coming from an inappropriate kind of submission. While it doesn't + guarantee that data has not been forged, it does require an attacker to + guess the right kind of forging. If you don't care where the request + data comes from, you can use <varname>$_REQUEST</varname> as it contains + a mix of GET, POST and COOKIE data. See also the manual section on + using <link linkend="language.variables.external">variables from outside + of PHP</link>. + </para> + <para> <example> - <title>̽²â¼òµ¥µÄ±äÁ¿¹¥»÷</title> + <title>Detecting simple variable poisoning</title> <programlisting role="php"> <![CDATA[ <?php -if ($_COOKIE['username'] && - !$_POST['username'] && - !$_GET['username'] ) { - // Perform other checks to validate the user name... - $good_login = 1; - fpassthru ("/highly/sensitive/data/index.html"); -} else { +if (isset($_COOKIE['MAGIC_COOKIE'])) { + + // MAGIC_COOKIE comes from a cookie. + // Be sure to validate the cookie data! + +} elseif (isset($_GET['MAGIC_COOKIE']) || isset($_POST['MAGIC_COOKIE'])) { + mail("admin@example.com", "Possible breakin attempt", $_SERVER['REMOTE_ADDR']); echo "Security violation, admin has been alerted."; exit; + +} else { + + // MAGIC_COOKIE isn't set through this REQUEST + } ?> ]]> </programlisting> </example> - Of course, simply turning off register_globals does not mean code - is secure. For every piece of data that is submitted, it - should also be checked in other ways. </para> + <para> + Of course, simply turning off register_globals does not mean your code + is secure. For every piece of data that is submitted, it should also be + checked in other ways. Always validate your user data and initialize + your variables! To check for unitialized variables you may turn up + <function>error_reporting</function> to show + <constant>E_NOTICE</constant> level errors. + </para> + + ¬e.superglobals; + </sect1> + <sect1 id="security.variables"> Index: phpdoc-zh/chapters/tutorial.xml diff -u phpdoc-zh/chapters/tutorial.xml:1.16 phpdoc-zh/chapters/tutorial.xml:1.17 --- phpdoc-zh/chapters/tutorial.xml:1.16 Wed May 7 05:21:31 2003 +++ phpdoc-zh/chapters/tutorial.xml Tue May 20 03:01:55 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.16 $ --> +<!-- $Revision: 1.17 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.18 Maintainer: Gregory Status: ready --> +<!-- EN-Revision: 1.19 Maintainer: Gregory Status: ready --> <chapter id="tutorial"> <title>¼òÃ÷½Ì³Ì</title> @@ -186,7 +186,8 @@ </para> <para> ÎÒÃÇÐèÒª½éÉܵĵڶþ¸öÔÀí£¬ÊÇ¶Ô <function>strstr</function> º¯ÊýµÄµ÷Óá£<function>strstr</function> ÊÇ PHP µÄÒ»¸öÄÚ½¨º¯Êý£¬Æä¹¦ÄÜÊÇÔÚÒ»¸ö×Ö·û´®ÖÐËÑË÷ÁíÍâÒ»¸ö×Ö·û´®¡£ÀýÈçÎÒÃÇÏÖÔÚÐèÒªÔÚ <varname>$_SERVER["HTTP_USER_AGENT"]</varname> ±äÁ¿ÖÐѰÕÒ <literal>"MSIE"</literal>¡£Èç¹û¸Ã×Ö·û´®±»ÕÒµ½£¬Ôòº¯Êý·µ»Ø &true;£¬Èç¹ûûÓУ¬Ôò·µ»Ø &false;¡£Èç¹û¸Ãº¯Êý·µ»ØÁË &true;£¬Ôò <link linkend="control-structures.if">if</link> »á½«Ìõ¼þÅжÏΪ &true; ²¢ÔËÐÐÆä´óÀ¨ºÅ {} ÄڵĴúÂ룻·ñÔò£¬Ôò²»ÔËÐС£Äú¿ÉÒÔ×Ô¼º³¢ÊÔÀûÓÃ<link linkend="control-structures.if">if</link>¡¢<link linkend="control-structures.else">else</link>ÒÔ¼°ÆäËüµÄº¯Êý£¬ÀýÈç <function>strtoupper</function> ºÍ - <function>strlen</function>£¬À´½¨Á¢ÀàËÆµÄ½Å±¾¡£ÔÚ±¾ÊÖ²áÖУ¬Ïà¹ØµÄÒ³ÃæÒ²°üº¬Óз¶Àý¡£ + <function>strlen</function>£¬À´½¨Á¢ÀàËÆµÄ½Å±¾¡£ÔÚ±¾ÊÖ²áÖУ¬Ïà¹ØµÄÒ³ÃæÒ²°üº¬Óз¶Àý¡£Èç¹ûÄú¶ÔÈçºÎʹÓú¯Êý²»ÊǺÜÈ·¶¨£¬Äú¿ÉÒÔÔĶÁÊÖ²áÖÐÓйء°<link linkend="about.prototypes">ÈçºÎÔĶÁº¯Êý¶¨Òå</link>¡±ºÍ¡°<link linkend="functions">PHP º¯Êý</link>¡±µÄÓйغ¯Êý¡£ + </para> <para> ÒÔÏÂÎÒÃǽøÒ»²½ÏÔʾÈçºÎ½ø³ö PHP ģʽ£¬ÉõÖÁÊÇÔÚÒ»¸ö PHP ´úÂë¿éµÄÖм䣺
Index: phpdoc-zh/language/functions.xml diff -u phpdoc-zh/language/functions.xml:1.16 phpdoc-zh/language/functions.xml:1.17 --- phpdoc-zh/language/functions.xml:1.16 Sat May 17 02:51:49 2003 +++ phpdoc-zh/language/functions.xml Tue May 20 03:01:53 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.16 $ --> -<!-- $Author: dallas $ --> -<!-- EN-Revision: 1.35 Maintainer: verdana Status: ready --> +<!-- $Revision: 1.17 $ --> +<!-- $Author: gregory $ --> +<!-- EN-Revision: 1.38 Maintainer: verdana Status: ready --> <!-- CREDITS: Gregory --> <chapter id="functions"> <title>º¯Êý</title> @@ -11,17 +11,22 @@ <para> Ò»¸öº¯Êý¿ÉÓÉÒÔϵÄÓï·¨À´¶¨Ò壺 - <informalexample> + </para> + <para> + <example> + <title>չʾº¯ÊýÓÃ;µÄαÂë</title> <programlisting role="php"> <![CDATA[ +<?php function foo ($arg_1, $arg_2, ..., $arg_n) { echo "Example function.\n"; return $retval; } +?> ]]> </programlisting> - </informalexample> + </example> </para> <!-- @@ -42,6 +47,8 @@ </simpara> <para> Èç¹ûÒ»¸öº¯ÊýÒÔÒÔÏÂÁ½¸ö·¶ÀýµÄ·½Ê½ÓÐÌõ¼þµÄ¶¨Ò壬Æä¶¨Ò屨ÐëÔÚµ÷ÓÃ<emphasis>֮ǰ</emphasis>Íê³É¡£ + </para> + <para> <example> <title>ÓÐÌõ¼þµÄº¯Êý</title> <programlisting role="php"> @@ -77,6 +84,8 @@ ]]> </programlisting> </example> + </para> + <para> <example> <title>º¯ÊýÖеĺ¯Êý</title> <programlisting role="php"> @@ -143,9 +152,9 @@ <function>func_get_arg</function>, ºÍ <function>func_get_args</function>¡£ PHP 3 ÖÐͨ¹ý´«µÝÒ»¸öÊý×é²ÎÊý¿ÉÒÔ´ïµ½ÀàËÆµÄЧ¹û£º - - <informalexample> - <programlisting role="php"> + </para> + <para> + <example> <![CDATA[ function takes_array($input) { @@ -153,7 +162,7 @@ } ]]> </programlisting> - </informalexample> + </example> </para> <sect2 id="functions.arguments.by-reference"> @@ -167,10 +176,13 @@ <para> Èç¹ûÏëÒªº¯ÊýµÄÒ»¸ö²ÎÊý×ÜÊÇͨ¹ýÒýÓô«µÝ£¬Äã¿ÉÒÔÔÚº¯Êý¶¨ÒåÖиòÎÊýµÄ Ç°ÃæÔ¤ÏȼÓÉÏ·ûºÅ£¨&£©£º - - <informalexample> + </para> + <para> + <example> + <title>ÓÃÒýÓô«µÝº¯Êý²ÎÊý</title> <programlisting role="php"> <![CDATA[ +<?php function add_some_extra(&$string) { $string .= 'and something extra.'; @@ -178,9 +190,10 @@ $str = 'This is a string, '; add_some_extra($str); echo $str; // outputs 'This is a string, and something extra.' +?> ]]> </programlisting> - </informalexample> + </example> </para> </sect2> @@ -190,23 +203,29 @@ <para> º¯Êý¿ÉÒÔ¶¨Òå C++ ·ç¸ñµÄ±êÁ¿²ÎÊýĬÈÏÖµ£¬ÈçÏ£º - - <informalexample> + </para> + <para> + <example> + <title>º¯ÊýÖÐĬÈϲÎÊýµÄÓÃ;</title> <programlisting role="php"> <![CDATA[ +<?php function makecoffee ($type = "cappuccino") { return "Making a cup of $type.\n"; } echo makecoffee (); echo makecoffee ("espresso"); +?> ]]> </programlisting> - </informalexample> + </example> </para> <para> ÉÏÊöƬ¶ÏµÄÊä³öÊÇ£º + </para> + <para> <screen> Making a cup of cappuccino. Making a cup of espresso. @@ -219,50 +238,58 @@ <para> Çë×¢Ò⵱ʹÓÃĬÈϲÎÊýʱ£¬ÈκÎĬÈϲÎÊý±ØÐë·ÅÔÚÈκηÇĬÈϲÎÊýµÄÓҲࣻ·ñÔò£¬ ¿ÉÄܺ¯Êý½«²»»á°´ÕÕÔ¤ÆÚµÄÇé¿ö¹¤×÷¡£¿¼ÂÇÏÂÃæµÄ´úÂëÆ¬¶Ï£º - - <informalexample> + </para> + <para> + <example> + <title>º¯ÊýĬÈϲÎÊý²»ÕýÈ·µÄÓ÷¨</title> <programlisting role="php"> <![CDATA[ +<?php function makeyogurt ($type = "acidophilus", $flavour) { return "Making a bowl of $type $flavour.\n"; } echo makeyogurt ("raspberry"); // won't work as expected +?> ]]> </programlisting> - </informalexample> + </example> </para> - <para> ÉÏÊöÀý×ÓµÄÊä³öʱ£º - + </para> + <para> <screen> Warning: Missing argument 2 in call to makeyogurt() in /usr/local/etc/httpd/htdocs/php3test/functest.html on line 41 Making a bowl of raspberry . </screen> </para> - <para> ÏÖÔÚ£¬±È½ÏÉÏÃæµÄÀý×ÓºÍÕâ¸öÀý×Ó£º - <informalexample> + </para> + <para> + <example> + <title>º¯ÊýĬÈϲÎÊýÕýÈ·µÄÓ÷¨</title> <programlisting role="php"> <![CDATA[ +<?php function makeyogurt ($flavour, $type = "acidophilus") { return "Making a bowl of $type $flavour.\n"; } echo makeyogurt ("raspberry"); // works as expected +?> ]]> </programlisting> - </informalexample> + </example> </para> - <para> Õâ¸öÀý×ÓµÄÊä³öÊÇ£º - + </para> + <para> <screen> Making a bowl of acidophilus raspberry. </screen> @@ -294,48 +321,62 @@ ֵͨ¹ýʹÓÿÉÑ¡µÄ·µ»ØÓï¾ä·µ»Ø¡£ÈκÎÀàÐͶ¼¿ÉÒÔ·µ»Ø£¬ÆäÖаüÀ¨ÁбíºÍ¶ÔÏó¡£ Õâµ¼Öº¯ÊýÁ¢¼´½áÊøËüµÄÔËÐУ¬²¢ÇÒ½«¿ØÖÆÈ¨´«µÝ»ØËü±»µ÷ÓõÄÐС£¸ü¶àÐÅÏ¢ Çë²ÎÕÕ <function>return</function>¡£ - <informalexample> + </para> + <para> + <example> + <title><function>return</function> º¯ÊýµÄÓ÷¨</title> <programlisting role="php"> <![CDATA[ +<?php function square ($num) { return $num * $num; } echo square (4); // outputs '16'. +?> ]]> </programlisting> - </informalexample> + </example> </para> <para> º¯Êý²»ÄÜ·µ»Ø¶à¸öÖµ£¬µ«ÎªÁË»ñµÃ¼òµ¥µÄ½á¹û£¬¿ÉÒÔ·µ»ØÒ»¸öÁÐ±í¡£ - - <informalexample> + </para> + <para> + <example> + <title>·µ»ØÒ»¸öÊý×éÒԵõ½¶à¸ö·µ»ØÖµ</title> <programlisting role="php"> <![CDATA[ +<?php function small_numbers() { return array (0, 1, 2); } list ($zero, $one, $two) = small_numbers(); +?> ]]> </programlisting> - </informalexample> + </example> </para> <para> ´Óº¯Êý·µ»ØÒ»¸öÒýÓã¬Äã±ØÐëÔÚº¯ÊýÉùÃ÷ºÍÖ¸ÅÉ·µ»ØÖµ¸øÒ»¸ö±äÁ¿Ê±¶¼Ê¹ÓÃÒýÓòÙ×÷·û & £º - <informalexample> + </para> + <para> + <example> + <title>Óɺ¯Êý·µ»ØÒ»¸öÒýÓÃ</title> <programlisting role="php"> <![CDATA[ +<?php function &returns_reference() { return $someref; } $newref =& returns_reference(); +?> ]]> </programlisting> - </informalexample> + </example> </para> <simpara> ÓйØÒýÓõĸü¶àÐÅÏ¢, Çë²é¿´ <link @@ -425,6 +466,20 @@ </sect1> +<sect1 id="functions.internal"> + <title>ÄÚ²¿£¨ÄÚ½¨£©º¯Êý</title> + + <para> + PHP Óкܶà±ê×¼µÄº¯ÊýºÍ½á¹¹¡£»¹ÓÐһЩº¯ÊýÐèÒªºÍÌØ¶¨µØ PHP À©Õ¹Ä£¿éÒ»Æð±àÒ룬·ñÔòÔÚʹÓÃËüÃǵÄʱºò¾Í»áµÃµ½Ò»¸öÖÂÃüµÄ¡°Î´¶¨Ò庯Êý¡±´íÎó¡£ÀýÈ磬ҪʹÓÃÖîÈç <function>imagecreatetruecolor</function> µÄ¡°<link linkend="ref.image">ͼÏñ</link>º¯Êý¡±£¬ÄúÐèÒªÔÚ±àÒë PHP µÄʱºò¼ÓÉÏ GD µÄÖ§³Ö¡£»òÕߣ¬ÒªÊ¹Óà <function>mysql_connect</function> º¯Êý£¬Äú¾ÍÐèÒªÔÚ±àÒë PHP µÄʱºò¼ÓÉÏ <link linkend="ref.mysql">MySQL</link> Ö§³Ö¡£ÁíÍ⻹ÓÐһЩºËÐĺ¯Êý£¬ÀýÈç¡°<link linkend="ref.strings">×Ö·û´®º¯Êý</link>¡±ºÍ¡°<link linkend="ref.variables">±äÁ¿º¯Êý</link>¡±£¬ËüÃÇ´æÔÚÓÚÿһ¸ö°æ±¾µÄ PHP ÖС£µ÷Óà <function>phpinfo</function> »òÕß <function>get_loaded_extensions</function> ¿ÉÒÔµÃÖª PHP ¼ÓÔØÁËÄÇЩÀ©Õ¹¿â¡£Í¬Ê±»¹Ó¦¸Ã×¢Ò⣬ºÜ¶àÀ©Õ¹¿âĬÈϾÍÊÇÓÐЧµÄ¡£PHP ÊֲᰴÕÕ²»Í¬µÄÀ©Õ¹¿â×éÖ¯ÁËËüÃǵÄÎĵµ¡£Çë²ÎÔÄ¡°<link linkend="configuration">ÅäÖÃ</link>¡±¡¢¡°<link linkend="installation">°²×°</link>¡±ÒÔ¼°¶ÀÁ¢µÄÀ©Õ¹¿âÕ½ÚÒÔ»ñÈ¡ÓйØÈçºÎÉèÖà PHP µÄÐÅÏ¢¡£ + </para> + <para> + ÊÖ²áÖС°<link linkend="about.prototypes">ÈçºÎÔĶÁº¯ÊýÔÐÍ</link>¡±½²½âÁËÈçºÎÔĶÁºÍÀí½âÒ»¸öº¯ÊýµÄÔÐÍ¡£È·ÈÏÒ»¸öº¯Êý½«·µ»ØÊ²Ã´£¬»òÕߺ¯ÊýÊÇ·ñÖ±½Ó×÷ÓÃÓÚ´«µÝµÄ²ÎÊýÊǺÜÖØÒªµÃ¡£ÀýÈ磬<function>str_replace</function> º¯Êý½«·µ»ØÐ޸ĹýµÄ×Ö·û´®£¬¶ø <function>usort</function> È´Ö±½Ó×÷ÓÃÓÚ´«µÝµÄ²ÎÊý±äÁ¿±¾Éí¡£ÊÖ²áÖУ¬Ã¿Ò»¸öº¯ÊýµÄÒ³ÃæÖж¼ÓйØÓÚº¯Êý²ÎÊý¡¢ÐÐΪ¸Ä±ä¡¢³É¹¦Óë·ñµÄ·µ»ØÖµÒÔ¼°Ê¹ÓÃÌõ¼þµÈÐÅÏ¢¡£Á˽âÕâÐ©ÖØÒªµÄ£¨³£³£ÊÇϸ΢µÄ£©²î±ðÊDZàдÕýÈ·µÄ PHP ´úÂëµÄ¹Ø¼ü¡£ + </para> + <para> + Çë²ÎÔĺ¯Êý <function>function_exists</function>¡¢<link linkend="funcref">º¯ÊýµÄÒýÓÃ</link>¡¢<function>get_extension_funcs</function> ºÍ <function>dl</function>¡£ + </para> + </sect1> + </chapter> <!-- Keep this comment at the end of the file Index: phpdoc-zh/appendices/history.xml diff -u phpdoc-zh/appendices/history.xml:1.11 phpdoc-zh/appendices/history.xml:1.12 --- phpdoc-zh/appendices/history.xml:1.11 Sat May 17 02:33:37 2003 +++ phpdoc-zh/appendices/history.xml Tue May 20 03:01:54 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.11 $ --> -<!-- $Author: dallas $ --> -<!-- EN-Revision: 1.17 Maintainer: class007 Status: ready --> +<!-- $Revision: 1.12 $ --> +<!-- $Author: gregory $ --> +<!-- EN-Revision: 1.18 Maintainer: class007 Status: ready --> <appendix id="history"> <title>PHP ¼°ÆäÏà¹Ø¹¤³ÌµÄÀúÊ·</title> <para> Index: phpdoc-zh/language-snippets.ent diff -u phpdoc-zh/language-snippets.ent:1.27 phpdoc-zh/language-snippets.ent:1.28 --- phpdoc-zh/language-snippets.ent:1.27 Tue May 6 03:26:15 2003 +++ phpdoc-zh/language-snippets.ent Tue May 20 03:01:54 2003 @@ -1,6 +1,6 @@ -<!-- $Revision: 1.27 $ --> +<!-- $Revision: 1.28 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.49 Maintainer: Gregory Status: ready --> +<!-- EN-Revision: 1.51 Maintainer: Gregory Status: ready --> <!ENTITY warn.experimental '<warning><simpara>±¾À©Õ¹Ä£¿éÊÇ<emphasis>ʵÑéÐÔ</emphasis>µÄ¡£¸ÃÄ£¿éµÄÐÐΪ£¬°üÀ¨Æäº¯ÊýµÄÃû³ÆÒÔ¼°ÆäËüÈκιØÓÚ´ËÄ£¿éµÄÎĵµ¿ÉÄÜ»áÔÚûÓÐ֪ͨµÄÇé¿öÏÂËæ PHP ÒÔºóµÄ·¢²¼¶ø¸Ä±ä¡£ÎÒÃÇÌáÐÑÄúÔÚʹÓñ¾À©Õ¹Ä£¿éµÄͬʱ×Ôµ£·çÏÕ¡£ </simpara></warning>'> @@ -136,6 +136,9 @@ <!-- These are here as helpers for manual consistency and brievety--> <!ENTITY php '<literal>PHP</literal>'> <!ENTITY safemode '<link linkend="ini.safe-mode">°²È«Ä£Ê½</link>'> + +<!-- Some MySQL Notes --> +<!ENTITY mysql.field-case '<note><simpara>¸Ãº¯Êý·µ»ØµÄ×Ö¶ÎÃûÊÇ<emphasis>´óСдÃô¸ÐµÄ</emphasis>£¡</simpara></note>'> <!-- These are using in reference/$extname/reference.xml and other supplemental files to mark section titles --> Index: phpdoc-zh/reference/mysql/functions/mysql-affected-rows.xml diff -u phpdoc-zh/reference/mysql/functions/mysql-affected-rows.xml:1.2 phpdoc-zh/reference/mysql/functions/mysql-affected-rows.xml:1.3 --- phpdoc-zh/reference/mysql/functions/mysql-affected-rows.xml:1.2 Sat Dec 28 04:28:42 2002 +++ phpdoc-zh/reference/mysql/functions/mysql-affected-rows.xml Tue May 20 03:01:54 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.6 Maintainer: yorgo Status: ready --> +<!-- EN-Revision: 1.7 Maintainer: yorgo Status: ready --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-affected-rows"> <refnamediv> @@ -53,6 +53,7 @@ /* Á¬½ÓÊý¾Ý¿â */ mysql_pconnect("localhost", "mysql_user", "mysql_password") or die ("Could not connect" . mysql_error()); + mysql_select_db("mydb"); /* Õâ»á·µ»ØÓÐЧµÄ±»É¾³ý¼Ç¼Êý¡£ */ mysql_query("DELETE FROM mytable WHERE id < 10"); @@ -82,6 +83,7 @@ /* Á¬½ÓÊý¾Ý¿â */ mysql_pconnect("localhost", "mysql_user", "mysql_password") or die ("Could not connect" . mysql_error()); + mysql_select_db("mydb"); /* Update ¼Ç¼ */ mysql_query("UPDATE mytable SET used=1 WHERE id < 10"); Index: phpdoc-zh/reference/oracle/functions/ora-bind.xml diff -u phpdoc-zh/reference/oracle/functions/ora-bind.xml:1.2 phpdoc-zh/reference/oracle/functions/ora-bind.xml:1.3 --- phpdoc-zh/reference/oracle/functions/ora-bind.xml:1.2 Tue Feb 25 03:10:04 2003 +++ phpdoc-zh/reference/oracle/functions/ora-bind.xml Tue May 20 03:01:54 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.2 Maintainer: yincheng Status: ready --> +<!-- EN-Revision: 1.3 Maintainer: yincheng Status: ready --> <!-- splitted from ./en/functions/oracle.xml, last change in rev 1.2 --> <refentry id="function.ora-bind"> <refnamediv> @@ -13,8 +13,8 @@ <methodsynopsis> <type>int</type><methodname>ora_bind</methodname> <methodparam><type>int</type><parameter>cursor</parameter></methodparam> - <methodparam><type>string</type><parameter>PHP variable name</parameter></methodparam> - <methodparam><type>string</type><parameter>SQL parameter name</parameter></methodparam> + <methodparam><type>string</type><parameter>PHP_variable_name</parameter></methodparam> + <methodparam><type>string</type><parameter>SQL_parameter_name</parameter></methodparam> <methodparam><type>int</type><parameter>length</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>type</parameter></methodparam> </methodsynopsis> @@ -32,11 +32,12 @@ ORA_BIND_OUT ´úÌæÊý×Ö¡£ </para> <para> -ora_bind ±ØÐëÔÚ <function>ora_parse</function> Ö®ºóºÍ +<function>ora_bind</function> ±ØÐëÔÚ <function>ora_parse</function> Ö®ºóºÍ <function>ora_exec</function> ֮ǰµ÷Óá£ÊäÈëÖµÓÉ°ó¶¨µÄ PHP ±äÁ¿Ö¸ÅÉ¡£ÔÚµ÷Óà <function>ora_exec</function> º¯ÊýÖ®ºó£¬Èç¹û°ó¶¨µÄ PHP ±äÁ¿ÓÐÖµÊä³ö£¬Ôò PHP ±äÁ¿½«µÈÓÚ¸ÃÖµ¡£ - <informalexample> + <example> + <title><function>ora_bind</function> º¯Êý·¶Àý</title> <programlisting role="php"> <![CDATA[ <?php @@ -50,7 +51,7 @@ ?> ]]> </programlisting> - </informalexample> + </example> </para> </refsect1> </refentry> Index: phpdoc-zh/reference/mysql/reference.xml diff -u phpdoc-zh/reference/mysql/reference.xml:1.8 phpdoc-zh/reference/mysql/reference.xml:1.9 --- phpdoc-zh/reference/mysql/reference.xml:1.8 Sat Dec 28 04:09:54 2002 +++ phpdoc-zh/reference/mysql/reference.xml Tue May 20 03:01:54 2003 @@ -1,8 +1,7 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.15 Maintainer: yorgo Status: ready --> -<!-- CREDITS: Gregory --> +<!-- EN-Revision: 1.16 Maintainer: Gregory Status: ready --> <reference id="ref.mysql"> <title>MySQL º¯Êý¿â</title> <titleabbrev>MySQL</titleabbrev> @@ -53,13 +52,13 @@ <?php /* Á¬½ÓÑ¡ÔñÊý¾Ý¿â */ $link = mysql_connect("mysql_host", "mysql_user", "mysql_password") - or die("Could not connect"); + or die("Could not connect : " . mysql_error()); print "Connected successfully"; mysql_select_db("my_database") or die("Could not select database"); /* Ö´ÐÐ SQL ²éѯ */ $query = "SELECT * FROM my_table"; - $result = mysql_query($query) or die("Query failed"); + $result = mysql_query($query) or die("Query failed : " . mysql_error()); /* ÔÚ HTML ÖдòÓ¡½á¹û */ print "<table>\n"; Index: phpdoc-zh/chapters/security.xml diff -u phpdoc-zh/chapters/security.xml:1.6 phpdoc-zh/chapters/security.xml:1.7 --- phpdoc-zh/chapters/security.xml:1.6 Tue Apr 1 04:15:12 2003 +++ phpdoc-zh/chapters/security.xml Tue May 20 03:01:55 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.52 Maintainer: Gregory Status: ready --> +<!-- EN-Revision: 1.55 Maintainer: Gregory Status: ready --> <chapter id="security"> <title>°²È«</title> @@ -780,83 +780,142 @@ </sect1> <sect1 id="security.registerglobals"> - <title>ÀûÓÃÈ«¾Ö±äÁ¿×¢²á£¨Register Globals£©</title> + <title>Using Register Globals</title> + <para> + Perhaps the most controversial change in PHP is when the default value + for the PHP directive <link linkend="ini.register-globals"> + register_globals</link> went from ON to OFF in PHP + <ulink url="&url.php.release4.2.0;">4.2.0</ulink>. Reliance on this + directive was quite common and many people didn't even know it existed + and assumed it's just how PHP works. This page will explain how one can + write insecure code with this directive but keep in mind that the + directive itself isn't insecure but rather it's the misuse of it. + </para> + <para> + When on, register_globals will inject (poison) your scripts will all + sorts of variables, like request variables from html forms. This + coupled with the fact that PHP doesn't require variable initialization + means writing insecure code is that much easier. It was a difficult + decision, but the PHP community decided to disable this directive by + default. When on, people use variables yet really don't know for sure + where they come from and can only assume. Internal variables that are + defined in the script itself get mixed up with request data sent by + users and disabling register_globals changes this. Let's demonstrate + with an example misuse of register_globals: + </para> <para> - One feature of PHP that can be used to enhance security is configuring PHP with - <link linkend="ini.register-globals">register_globals</link> = off. - By turning off the ability for any user-submitted variable to be injected - into PHP code, you can reduce the amount of variable - poisoning a potential attacker may inflict. They will have - to take the additional time to forge submissions, and your - internal variables are effectively isolated from user - submitted data. - </para> - <para> - While it does slightly increase the amount of effort required - to work with PHP, it has been argued that the benefits far - outweigh the effort. <example> - <title>ÔÚ register_globals = on µÄÇé¿öϹ¤×÷</title> + <title>Example misuse with register_globals = on</title> <programlisting role="php"> <![CDATA[ <?php -if ($username) { // can be forged by a user in get/post/cookies - $good_login = 1; +// define $authorized = true only if user is authenticated +if (authenticated_user()) { + $authorized = true; } -if ($good_login == 1) { // can be forged by a user in get/post/cookies, - fpassthru ("/highly/sensitive/data/index.html"); +// Because we didn't first initialize $authorized as false, this might be +// defined through register_globals, like from GET auth.php?authorized=1 +// So, anyone can be seen as authenticated! +if ($authorized) { + include "/highly/sensitive/data.php"; } ?> ]]> </programlisting> </example> + </para> + <para> + When register_globals = on, our logic above may be compromised. When + off, <varname>$authorized</varname> can't be set via request so it'll + be fine, although it really is generally a good programming practice to + initialize variables first. For example, in our example above we might + have first done <literal>$authorized = false</literal>. Doing this + first means our above code would work with register_globals on or off as + users by default would be unauthorized. + </para> + <para> + Another example is that of <link linkend="ref.session">sessions</link>. + When register_globals = on, we could also use + <varname>$username</varname> in our example below but again you must + realize that <varname>$username</varname> could also come from other + means, such as GET (through the URL). + </para> + <para> <example> - <title>ÔÚ register_globals = off µÄÇé¿öϹ¤×÷</title> + <title>Example use of sessions with register_globals on or off</title> <programlisting role="php"> <![CDATA[ <?php -if($_COOKIE['username']){ - // can only come from a cookie, forged or otherwise - $good_login = 1; - fpassthru ("/highly/sensitive/data/index.html"); +// We wouldn't know where $username came from but do know $_SESSION is +// for session data +if (isset($_SESSION['username'])) { + + echo "Hello <b>{$_SESSION['username']}</b>"; + +} else { + + echo "Hello <b>Guest</b><br />"; + echo "Would you like to login?"; + } ?> ]]> </programlisting> </example> - By using this wisely, it's even possible to take preventative - measures to warn when forging is being attempted. If you know - ahead of time exactly where a variable should be coming from, - you can check to see if submitted data is coming from an - inappropriate kind of submission. While it doesn't guarantee - that data has not been forged, it does require an attacker - to guess the right kind of forging. + </para> + <para> + It's even possible to take preventative measures to warn when forging is + being attempted. If you know ahead of time exactly where a variable + should be coming from, you can check to see if the submitted data is + coming from an inappropriate kind of submission. While it doesn't + guarantee that data has not been forged, it does require an attacker to + guess the right kind of forging. If you don't care where the request + data comes from, you can use <varname>$_REQUEST</varname> as it contains + a mix of GET, POST and COOKIE data. See also the manual section on + using <link linkend="language.variables.external">variables from outside + of PHP</link>. + </para> + <para> <example> - <title>̽²â¼òµ¥µÄ±äÁ¿¹¥»÷</title> + <title>Detecting simple variable poisoning</title> <programlisting role="php"> <![CDATA[ <?php -if ($_COOKIE['username'] && - !$_POST['username'] && - !$_GET['username'] ) { - // Perform other checks to validate the user name... - $good_login = 1; - fpassthru ("/highly/sensitive/data/index.html"); -} else { +if (isset($_COOKIE['MAGIC_COOKIE'])) { + + // MAGIC_COOKIE comes from a cookie. + // Be sure to validate the cookie data! + +} elseif (isset($_GET['MAGIC_COOKIE']) || isset($_POST['MAGIC_COOKIE'])) { + mail("admin@example.com", "Possible breakin attempt", $_SERVER['REMOTE_ADDR']); echo "Security violation, admin has been alerted."; exit; + +} else { + + // MAGIC_COOKIE isn't set through this REQUEST + } ?> ]]> </programlisting> </example> - Of course, simply turning off register_globals does not mean code - is secure. For every piece of data that is submitted, it - should also be checked in other ways. </para> + <para> + Of course, simply turning off register_globals does not mean your code + is secure. For every piece of data that is submitted, it should also be + checked in other ways. Always validate your user data and initialize + your variables! To check for unitialized variables you may turn up + <function>error_reporting</function> to show + <constant>E_NOTICE</constant> level errors. + </para> + + ¬e.superglobals; + </sect1> + <sect1 id="security.variables"> Index: phpdoc-zh/chapters/tutorial.xml diff -u phpdoc-zh/chapters/tutorial.xml:1.16 phpdoc-zh/chapters/tutorial.xml:1.17 --- phpdoc-zh/chapters/tutorial.xml:1.16 Wed May 7 05:21:31 2003 +++ phpdoc-zh/chapters/tutorial.xml Tue May 20 03:01:55 2003 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.16 $ --> +<!-- $Revision: 1.17 $ --> <!-- $Author: gregory $ --> -<!-- EN-Revision: 1.18 Maintainer: Gregory Status: ready --> +<!-- EN-Revision: 1.19 Maintainer: Gregory Status: ready --> <chapter id="tutorial"> <title>¼òÃ÷½Ì³Ì</title> @@ -186,7 +186,8 @@ </para> <para> ÎÒÃÇÐèÒª½éÉܵĵڶþ¸öÔÀí£¬ÊÇ¶Ô <function>strstr</function> º¯ÊýµÄµ÷Óá£<function>strstr</function> ÊÇ PHP µÄÒ»¸öÄÚ½¨º¯Êý£¬Æä¹¦ÄÜÊÇÔÚÒ»¸ö×Ö·û´®ÖÐËÑË÷ÁíÍâÒ»¸ö×Ö·û´®¡£ÀýÈçÎÒÃÇÏÖÔÚÐèÒªÔÚ <varname>$_SERVER["HTTP_USER_AGENT"]</varname> ±äÁ¿ÖÐѰÕÒ <literal>"MSIE"</literal>¡£Èç¹û¸Ã×Ö·û´®±»ÕÒµ½£¬Ôòº¯Êý·µ»Ø &true;£¬Èç¹ûûÓУ¬Ôò·µ»Ø &false;¡£Èç¹û¸Ãº¯Êý·µ»ØÁË &true;£¬Ôò <link linkend="control-structures.if">if</link> »á½«Ìõ¼þÅжÏΪ &true; ²¢ÔËÐÐÆä´óÀ¨ºÅ {} ÄڵĴúÂ룻·ñÔò£¬Ôò²»ÔËÐС£Äú¿ÉÒÔ×Ô¼º³¢ÊÔÀûÓÃ<link linkend="control-structures.if">if</link>¡¢<link linkend="control-structures.else">else</link>ÒÔ¼°ÆäËüµÄº¯Êý£¬ÀýÈç <function>strtoupper</function> ºÍ - <function>strlen</function>£¬À´½¨Á¢ÀàËÆµÄ½Å±¾¡£ÔÚ±¾ÊÖ²áÖУ¬Ïà¹ØµÄÒ³ÃæÒ²°üº¬Óз¶Àý¡£ + <function>strlen</function>£¬À´½¨Á¢ÀàËÆµÄ½Å±¾¡£ÔÚ±¾ÊÖ²áÖУ¬Ïà¹ØµÄÒ³ÃæÒ²°üº¬Óз¶Àý¡£Èç¹ûÄú¶ÔÈçºÎʹÓú¯Êý²»ÊǺÜÈ·¶¨£¬Äú¿ÉÒÔÔĶÁÊÖ²áÖÐÓйء°<link linkend="about.prototypes">ÈçºÎÔĶÁº¯Êý¶¨Òå</link>¡±ºÍ¡°<link linkend="functions">PHP º¯Êý</link>¡±µÄÓйغ¯Êý¡£ + </para> <para> ÒÔÏÂÎÒÃǽøÒ»²½ÏÔʾÈçºÎ½ø³ö PHP ģʽ£¬ÉõÖÁÊÇÔÚÒ»¸ö PHP ´úÂë¿éµÄÖм䣺