fujimoto Tue Dec 11 17:12:54 2001 EDT Modified files: /phpdoc/ja/features error-handling.xml http-auth.xml images.xml safe-mode.xml Log: enclosing programlisting with CDATA.
Index: phpdoc/ja/features/error-handling.xml diff -u phpdoc/ja/features/error-handling.xml:1.9 phpdoc/ja/features/error-handling.xml:1.10 --- phpdoc/ja/features/error-handling.xml:1.9 Wed Nov 14 17:55:19 2001 +++ phpdoc/ja/features/error-handling.xml Tue Dec 11 17:12:54 2001 @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> +<!-- $Revision: 1.10 $ --> <chapter id="features.error-handling"> <title>エラー処理</title> @@ -143,8 +144,8 @@ この場合、その式に関するエラーメッセージの出力がオフにされます。 そのような式においてエラーが発生し、 <link linkend="ini.track-errors">track_errors</link> 機能が有効の - 場合、グローバル変数 $php_errormsg からエラーメッセージを - 得ることができます。 + 場合、グローバル変数 <literal>$php_errormsg</literal> からエラー + メッセージを得ることができます。 </para> <note> @@ -173,76 +174,77 @@ <example> <title>スクリプトでのエラー処理の使用法</title> <programlisting role="php"> -<?php +<![CDATA[ +<?php // 独自のエラー処理を行う error_reporting(0); // ユーザ定義のエラー処理関数 function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars) { // エラーエントリ用タイムスタンプ - $dt = date("Y-m-d H:i:s (T)"); + $dt = date("Y-m-d H:i:s (T)"); // エラー文字列の連想を定義 // 実際に考慮するエントリは 2,8,256,512,1024のみ $errortype = array ( - 1 => "Error", - 2 => "Warning", - 4 => "Parsing Error", - 8 => "Notice", - 16 => "Core Error", - 32 => "Core Warning", - 64 => "Compile Error", - 128 => "Compile Warning", - 256 => "User Error", - 512 => "User Warning", - 1024=> "User Notice" + 1 => "Error", + 2 => "Warning", + 4 => "Parsing Error", + 8 => "Notice", + 16 => "Core Error", + 32 => "Core Warning", + 64 => "Compile Error", + 128 => "Compile Warning", + 256 => "User Error", + 512 => "User Warning", + 1024=> "User Notice" ); // モニタするエラーの種類を設定 $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE); - $err = "<errorentry>\n"; - $err .= "\t<datetime>".$dt."</datetime>\n"; - $err .= "\t<errornum>".$errno."</errnumber>\n"; - $err .= "\t<errortype>".$errortype[$errno]."</errortype>\n"; - $err .= "\t<errormsg>".$errmsg."</errormsg>\n"; - $err .= "\t<scriptname>".$filename."</scriptname>\n"; - $err .= "\t<scriptlinenum>".$linenum."</scriptlinenum>\n"; + $err = "<errorentry>\n"; + $err .= "\t<datetime>".$dt."</datetime>\n"; + $err .= "\t<errornum>".$errno."</errnumber>\n"; + $err .= "\t<errortype>".$errortype[$errno]."</errortype>\n"; + $err .= "\t<errormsg>".$errmsg."</errormsg>\n"; + $err .= "\t<scriptname>".$filename."</scriptname>\n"; + $err .= "\t<scriptlinenum>".$linenum."</scriptlinenum>\n"; if (in_array($errno, $user_errors)) - $err .= "\t<vartrace>".wddx_serialize_value($vars,"Variables")."</vartrace>\n"; - $err .= "</errorentry>\n\n"; + $err .= +"\t<vartrace>".wddx_serialize_value($vars,"Variables")."</vartrace>\n"; + $err .= "</errorentry>\n\n"; // テスト用 // echo $err; // エラーログに保存し、致命的なエラーの場合はメールを送信する - error_log($err, 3, "/usr/local/php4/error.log"); + error_log($err, 3, "/usr/local/php4/error.log"); if ($errno == E_USER_ERROR) - mail("[EMAIL PROTECTED]","Critical User Error",$err); + mail("[EMAIL PROTECTED]","Critical User Error",$err); } function distance ($vect1, $vect2) { if (!is_array($vect1) || !is_array($vect2)) { - trigger_error("Incorrect parameters, arrays expected", E_USER_ERROR); + trigger_error("Incorrect parameters, arrays expected", E_USER_ERROR); return NULL; } if (count($vect1) != count($vect2)) { - trigger_error("Vectors need to be of the same size", E_USER_ERROR); + trigger_error("Vectors need to be of the same size", E_USER_ERROR); return NULL; } - for ($i=0; $i<count($vect1); $i++) { + for ($i=0; $i<count($vect1); $i++) { $c1 = $vect1[$i]; $c2 = $vect2[$i]; $d = 0.0; if (!is_numeric($c1)) { - trigger_error("Coordinate $i in vector 1 is not a number, using zero", + trigger_error("Coordinate $i in vector 1 is not a number, using zero", E_USER_WARNING); $c1 = 0.0; } if (!is_numeric($c2)) { - trigger_error("Coordinate $i in vector 2 is not a number, using zero", + trigger_error("Coordinate $i in vector 2 is not a number, using zero", E_USER_WARNING); $c2 = 0.0; } @@ -251,26 +253,27 @@ return sqrt($d); } -$old_error_handler = set_error_handler("userErrorHandler"); +$old_error_handler = set_error_handler("userErrorHandler"); // 未定義の定数、警告を生成 $t = I_AM_NOT_DEFINED; -// いくつかの "vectors" を定義 -$a = array(2,3,"foo"); +// いくつかの "vectors" を定義 +$a = array(2,3,"foo"); $b = array(5.5, 4.3, -1.6); $c = array (1,-3); // ユーザエラーを生成 -$t1 = distance($c,$b)."\n"; +$t1 = distance($c,$b)."\n"; // 別のユーザエラーを生成 -$t2 = distance($b,"i am not an array")."\n"; +$t2 = distance($b,"i am not an array")."\n"; // 警告を生成 -$t3 = distance($a,$b)."\n"; +$t3 = distance($a,$b)."\n"; -?> +?> +]]> </programlisting> </example> 上記のコードは、<link linkend="ref.errorfunc">エラー処理とログ関数 Index: phpdoc/ja/features/http-auth.xml diff -u phpdoc/ja/features/http-auth.xml:1.10 phpdoc/ja/features/http-auth.xml:1.11 --- phpdoc/ja/features/http-auth.xml:1.10 Wed Nov 14 17:55:19 2001 +++ phpdoc/ja/features/http-auth.xml Tue Dec 11 17:12:54 2001 @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> +<!-- $Revision: 1.11 $ --> <chapter id="features.http-auth"> <title>PHP による HTTP 認証</title> @@ -20,17 +21,19 @@ <example> <title>HTTP 認証の例</title> <programlisting role="php"> -<?php +<![CDATA[ +<?php if(!isset($PHP_AUTH_USER)) { - header("WWW-Authenticate: Basic realm=\"My Realm\""); - header("HTTP/1.0 401 Unauthorized"); - echo "ユーザーがキャンセルボタンを押した時に送信されるテキスト\n"; + header("WWW-Authenticate: Basic realm=\"My Realm\""); + header("HTTP/1.0 401 Unauthorized"); + echo +"ユーザーがキャンセルボタンを押した時に送信されるテキスト\n"; exit; } else { - echo "<p>こんにちは、$PHP_AUTH_USER さん。</p>"; - echo "<p>あなたは、$PHP_AUTH_PW をパスワードとして入力しました。</p>"; + echo "<p>こんにちは、$PHP_AUTH_USER さん。</p>"; + echo "<p>あなたは、$PHP_AUTH_PW +をパスワードとして入力しました。</p>"; } ?> +]]> </programlisting> </example> </para> @@ -93,27 +96,29 @@ <example> <title>新規に名前/パスワードを入力させるHTTP 認証の例</title> <programlisting role="php"> -<?php +<![CDATA[ +<?php function authenticate() { - header( "WWW-Authenticate: Basic realm=\"Test Authentication System\""); - header( "HTTP/1.0 401 Unauthorized"); - echo "このリソースにアクセスする際には有効なログインIDとパスワードを入力する必要があります。\n"; + header( "WWW-Authenticate: Basic realm=\"Test Authentication System\""); + header( "HTTP/1.0 401 Unauthorized"); + echo +"このリソースにアクセスする際には有効なログインIDとパスワードを入力する必要があります。\n"; exit; } - if(!isset($PHP_AUTH_USER) || ($SeenBefore == 1 && !strcmp($OldAuth, $PHP_AUTH_USER)) ) { + if(!isset($PHP_AUTH_USER) || ($SeenBefore == 1 && !strcmp($OldAuth, +$PHP_AUTH_USER)) ) { authenticate(); } else { - echo "</p>Welcome: $PHP_AUTH_USER<br>"; - echo "Old: $OldAuth"; - echo "<form action=\"$PHP_SELF\" METHOD=POST>\n"; - echo "<input type=\"hidden\" name=\"SeenBefore\" value=\"1\">\n"; - echo "<input type=\"hidden\" name=\"OldAuth\" value=\"$PHP_AUTH_USER\">\n"; - echo "<input type=\"submit\" value=\"Re Authenticate\">\n"; - echo "</form></p>\n"; + echo "</p>Welcome: $PHP_AUTH_USER<br>"; + echo "Old: $OldAuth"; + echo "<form action=\"$PHP_SELF\" METHOD=POST>\n"; + echo "<input type=\"hidden\" name=\"SeenBefore\" value=\"1\">\n"; + echo "<input type=\"hidden\" name=\"OldAuth\" value=\"$PHP_AUTH_USER\">\n"; + echo "<input type=\"submit\" value=\"Re Authenticate\">\n"; + echo "</form></p>\n"; } ?> +]]> </programlisting> </example> <simpara> Index: phpdoc/ja/features/images.xml diff -u phpdoc/ja/features/images.xml:1.4 phpdoc/ja/features/images.xml:1.5 --- phpdoc/ja/features/images.xml:1.4 Wed Nov 14 17:55:19 2001 +++ phpdoc/ja/features/images.xml Tue Dec 11 17:12:54 2001 @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> +<!-- $Revision: 1.5 $ --> <chapter id="features.images"> <title>イメージの作成および操作</title> @@ -16,7 +17,8 @@ <example> <title>PHPによるPNGの作成</title> <programlisting role="php"> -<?php +<![CDATA[ +<?php Header("Content-type: image/png"); $string=implode($argv," "); $im = imageCreateFromPng("images/button1.png"); @@ -26,6 +28,7 @@ ImagePng($im); ImageDestroy($im); ?> +]]> </programlisting> </example> Index: phpdoc/ja/features/safe-mode.xml diff -u phpdoc/ja/features/safe-mode.xml:1.4 phpdoc/ja/features/safe-mode.xml:1.5 --- phpdoc/ja/features/safe-mode.xml:1.4 Wed Nov 14 17:55:19 2001 +++ phpdoc/ja/features/safe-mode.xml Tue Dec 11 17:12:54 2001 @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> +<!-- $Revision: 1.5 $ --> <chapter id="features.safe-mode"> <title>セーフモード</title> @@ -12,12 +13,14 @@ <para> セーフモードを制御する設定ディレクティブには、次のようなものがあります。 <programlisting role="ini"> +<![CDATA[ safe_mode = Off open_basedir = safe_mode_exec_dir = safe_mode_allowed_env_vars = PHP_ safe_mode_protected_env_vars = LD_LIBRARY_PATH disable_functions = +]]> </programlisting> </para> <para> @@ -25,20 +28,26 @@ 現在のスクリプトの所有者がファイル関数により処理されているファイル の所有者に一致するかどうかを調べます。例えば、 <programlisting role="ls"> +<![CDATA[ -rw-rw-r-- 1 rasmus rasmus 33 Jul 1 19:20 script.php -rw-r--r-- 1 root root 1116 May 26 18:01 /etc/passwd +]]> </programlisting> 以下のscript.php を実行すると、 <programlisting role="php"> -<?php +<![CDATA[ +<?php readfile('/etc/passwd'); -?> +?> +]]> </programlisting> セーフモードが有効な場合、以下のようなエラーが出力されます。 - <programlisting role="php"> + <screen> +<![CDATA[ Warning: SAFE MODE Restriction in effect. The script whose uid is 500 is not allowed to access /etc/passwd owned by uid 0 in /docroot/script.php on line 2 - </programlisting> +]]> + </screen> </para> <para> <link linkend="ini.safe-mode">safe_mode</link>の代わりに、 @@ -46,28 +55,36 @@ のファイル操作は、制限されます。例を以下に示します。(Apache httpd.conf の例) <programlisting role="ini"> -<Directory /docroot> +<![CDATA[ +<Directory /docroot> php_admin_value open_basedir /docroot -</Directory> +</Directory> +]]> </programlisting> このopen_basedir設定で同じscript.phpを実行した場合、以下のような結果 となります。 - <programlisting role="php"> + <screen> +<![CDATA[ Warning: open_basedir restriction in effect. File is in wrong directory in /docroot/script.php on line 2 - </programlisting> +]]> + </screen> </para> <para> 個々の関数を無効にすることも可能です。以下の設定をphp.iniファイルに 追加してみましょう。 <programlisting role="ini"> +<![CDATA[ disable_functions readfile,system +]]> </programlisting> この場合、次のような出力となります。 - <programlisting role="php"> + <screen> +<![CDATA[ Warning: readfile() has been disabled for security reasons in /docroot/script.php on line 2 - </programlisting> +]]> + </screen> </para> <sect1 id="features.safe-mode.functions">