Doc #51011 [Opn->Csd]: [ZH] The Content and the sample were mixed

From: Date: Sat, 23 Oct 2010 12:33:59 +0000
Subject: Doc #51011 [Opn->Csd]: [ZH] The Content and the sample were mixed
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5371@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51011&edit=1 ID: 51011 Updated by: kalle@php.net Reported by: lne1030 at gmail dot com Summary: [ZH] The Content and the sample were mixed -Status: Open +Status: Closed Type: Documentation Problem Package: Translation problem Operating System: Windows XP PHP Version: 5.2.12 -Assigned To: +Assigned To: kalle Block user comment: N New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2010-10-23 14:33:52] kalle@php.net Automatic comment from SVN on behalf of kalle Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=304656 Log: Fixed bug #51011 ([ZH] The Content and the sample were mixed) ------------------------------------------------------------------------ [2010-02-19 14:08:16] yannick@php.net -Summary: The Content and the sample were mixed +Summary: [ZH] The Content and the sample were mixed ------------------------------------------------------------------------ [2010-02-11 09:18:09] lne1030 at gmail dot com Description: ------------ http://docs.php.net/manual/zh/features.http-auth.php This page have the error! "Example #7 Digest HTTP" Reproduce code: --------------- <?php $realm = 'Restricted area'; //user => password $users = array('admin' => 'mypass', 'guest' => 'guest'); if (empty($_SERVER['PHP_AUTH_DIGEST'])) { header('HTTP/1.1 401 Unauthorized'); header('WWW-Authenticate: Digest realm="'.$realm. '" qop="auth" nonce="'.uniqid().'" opaque="'.md5($realm).'"'); die('Text to send if user hits Cancel button'); } // analyze the PHP_AUTH_DIGEST variable if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) || !isset($users[$data['username']])) die('Wrong Credentials!'); // generate the valid response $A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]); $A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']); $valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2); if ($data['response'] != $valid_response) die('Wrong Credentials!'); // ok, valid username & password echo 'Your are logged in as: ' . $data['username']; // function to parse the http auth header function http_digest_parse($txt) { // protect against missing data $needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1); $data = array(); preg_match_all('@(\w+)=([\'"]?)([a-zA-Z0-9=./\_-]+)\2@', $txt, $matches, PREG_SET_ORDER); foreach ($matches as $m) { $data[$m[1]] = $m[3]; unset($needed_parts[$m[1]]); } return $needed_parts ? false : $data; } ?> </programlisting> </example> </para> <note> <title>¼æÈÝÐÔÎÊÌâ</title> <para> ÔÚ±àд HTTP ±êÍ·´úÂëʱÇë¸ñÍâСÐÄ¡£ÎªÁ˶ÔËùÓеĿͻ§¶Ë±£Ö¤¼æÈÝÐÔ£¬¹Ø¼ü×Ö¡°Basic¡±µÄµÚÒ»¸ö×Öĸ±ØÐë´óдΪ¡°B¡±£¬·Ö½ç×Ö·û´®±ØÐëÓÃË«ÒýºÅ£¨²»Êǵ¥ÒýºÅ£©ÒýÓ㻲¢ÇÒÔÚ±êÍ·ÐÐ <emphasis>HTTP/1.0 401</emphasis> ÖУ¬ÔÚ <emphasis>401</emphasis> ǰ±ØÐëÓÐÇÒ½öÓÐÒ»¸ö¿Õ¸ñ¡£ </para> </note> <para> ÔÚÒÔÉÏÀý×ÓÖУ¬½ö½öÖ»´òÓ¡³öÁË <varname>PHP_AUTH_USER</varname> ºÍ <varname>PHP_AUTH_PW</varname> µÄÖµ£¬µ«ÔÚʵ¼ÊÔËÓÃÖУ¬¿ÉÄÜÐèÒª¶ÔÓû§ÃûºÍÃÜÂëµÄºÏ·¨ÐÔ½øÐмì²é¡£»òÐí½øÐÐÊý¾Ý¿âµÄ²éѯ£¬»òÐí´Ó dbm ÎļþÖмìË÷¡£ </para> <para> ×¢ÒâÓÐЩ Internet Explorer ä¯ÀÀÆ÷±¾ÉíÓÐÎÊÌâ¡£Ëü¶Ô±êÍ·µÄ˳ÐòÏÔµÃËÆºõÓе㴵ëÇó´Ã¡£Ä¿Ç°¿´À´ÔÚ·¢ËÍ <literal>HTTP/1.0 401</literal> ֮ǰÏÈ·¢ËÍ <emphasis>WWW-Authenticate</emphasis> ±êÍ·ËÆºõ¿ÉÒÔ½â¾ö´ËÎÊÌâ¡£ </para> <simpara> ×Ô PHP 4.3.0 Æð£¬ÎªÁË·ÀÖ¹ÓÐÈËͨ¹ý±àд½Å±¾À´´ÓÓô«Í³Íⲿ»úÖÆÈÏÖ¤µÄÒ³ÃæÉÏ»ñÈ¡ÃÜÂ룬µ±ÍⲿÈÏÖ¤¶ÔÌØ¶¨Ò³ÃæÓÐЧ£¬²¢ÇÒ&safemode;±»¿ªÆôʱ£¬PHP_AUTH ±äÁ¿½«²»»á±»ÉèÖᣵ«ÎÞÂÛÈçºÎ£¬<varname>REMOTE_USER</varname> ¿ÉÒÔ±»ÓÃÀ´±æÈÏÍⲿÈÏÖ¤µÄÓû§£¬Òò´Ë¿ÉÒÔÓà <varname>$_SERVER['REMOTE_USER']</varname> ±äÁ¿¡£ </simpara> <note> <title>ÅäÖÃ˵Ã÷</title> <para> PHP ÓÃÊÇ·ñÓÐ <literal>AuthType</literal> Ö¸ÁîÀ´ÅжÏÍⲿÈÏÖ¤»úÖÆÊÇ·ñÓÐЧ¡£ </para> </note> <simpara> ×¢Ò⣬ÕâÈÔÈ»²»ÄÜ·ÀÖ¹ÓÐÈËͨ¹ýδÈÏÖ¤µÄ URL À´´Óͬһ·þÎñÆ÷ÉÏÈÏÖ¤µÄ URL ÉÏ͵ȡÃÜÂë¡£ </simpara> <simpara> Netscape Navigator ºÍ Internet Explorer ä¯ÀÀÆ÷¶¼»áÔÚÊÕµ½ 401 µÄ·þÎñ¶Ë·µ»ØÐÅϢʱÇå¿ÕËùÓеı¾µØä¯ÀÀÆ÷Õû¸öÓòµÄ Windows ÈÏÖ¤»º´æ¡£ÕâÄܹ»ÓÐЧµÄ×¢ÏúÒ»¸öÓû§£¬²¢ÆÈʹËûÃÇÖØÐÂÊäÈëËûÃǵÄÓû§ÃûºÍÃÜÂë¡£ÓÐЩÈËÓÃÕâÖÖ·½·¨À´Ê¹µÇ¼״̬¡°¹ýÆÚ¡±£¬»òÕß×÷Ϊ¡°×¢Ïú¡±°´Å¥µÄÏìÓ¦ÐÐΪ¡£ </simpara> <para> <example> <title>Ç¿ÆÈÖØÐÂÊäÈëÓû§ÃûºÍÃÜÂëµÄ HTTP ÈÏÖ¤µÄ·¶Àý</title> <programlisting role="php"> <![CDATA[ <?php function authenticate() { header('WWW-Authenticate: Basic realm="Test Authentication System"'); header('HTTP/1.0 401 Unauthorized'); echo "You must enter a valid login ID and password to access this resource\n"; exit; } if (!isset($_SERVER['PHP_AUTH_USER']) || ($_POST['SeenBefore'] == 1 && $_POST['OldAuth'] == $_SERVER['PHP_AUTH_USER'])) { authenticate(); } else { echo "<p>Welcome: {$_SERVER['PHP_AUTH_USER']}<br />"; echo "Old: {$_REQUEST['OldAuth']}"; echo "<form action='{$_SERVER['PHP_SELF']}' METHOD='post'>\n"; echo "<input type='hidden' name='SeenBefore' value='1' />\n"; echo "<input type='hidden' name='OldAuth' value='{$_SERVER['PHP_AUTH_USER']}' />\n"; echo "<input type='submit' value='Re Authenticate' />\n"; echo "</form></p>\n"; } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51011&edit=1

« previous php.doc.bugs (#5371) next »