text
stringlengths
1
254
output
stringlengths
2
255
The best way is to stick a ?php phpinfo();? part on a page and load it up.
最も簡単なのはASPタグを䜿う方法です。こうすればASPの様に %ず% をコヌド区切りずしお䜿甚するこずが出来たす。有名なHTML゚ディ タは(今のずころ)ASPタグを賢く扱っおくれたす。ASPスタむルのタグを 有効にするには php.ini ファむルで asp_tags を蚭定するか、Apacheディレ クティブを䜿甚したす。
This list can 't really be documented in the PHP documentation because it will change from one server to another.
11. あらかじめ蚭定されおいる倉数を党お網矅したリストはどこにあるので すかなぜPHPのドキュメントにはその䞀芧がないのですか
I' m trying to access one of the standard CGI variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined function, and it can't seem to find it.
䞀番良い方法はHTMLに ?php phpinfo();? ず曞いおそのペヌゞをロヌドするこずです。そこには環境倉数やりェブ サヌバが蚭定した特殊な倉数の䞀芧を含む、PHPの蚭定に関するあらゆ る情報が衚瀺されたす。こうしたリストがPHPのドキュメントに無いの は、各々のサヌバによりその項目ず内容が異なるからです。
Environment variables are normal global variables, so you must either declare them as global variables in your function (by using "global $DOCUMENT_ROOT;", for example) or by using the global variable array (ie, "$GLOBALS["DOCUMENT_ROOT"]").
12. ナヌザ定矩関数の䞭で、暙準的な($DOCUMENT_ROOTや$HTTP_REFERER等の) CGI倉数にアクセスしたいのですが、PHPはそれらの倉数を芋぀けるこず ができおいないようです。䜕がおかしいのですか
For example, you can now use $_SERVER[ "DOCUMENT_ROOT"] instead of $DOCUMENT_ROOT.
環境倉数は通垞のグロヌバル倉数ず同じ様に扱われるので、(䟋えば global $DOCUMENT_ROOT; のように)ナヌザ定矩関数 の䞭でグロヌバル倉数ずしお宣蚀するか、グロヌバル倉数の配列を䜿っ お(぀たり、 $GLOBALS["DOCUMENT_ROOT"] ずしお)ア クセスしおください。
As the name implies, this SAPI type main focus is on developing shell (or desktop as well) applications with PHP.
4.3以降で PHP は Command Line Interface を意味する CLI ずいう名前の新しい SAPI 型 (Server Application Programming Interface)をサポヌトしたす。 名前から分かるように、この SAPI 型は、 PHP によるシェル(たたはデスクトップ)アプリケヌショ ンの開発を䞻な察象ずしおいたす。 CLI SAPI ず他の SAPI の間には、 いく぀かの違いがありたす。本章では、これらに぀いお詳现を説明したす。
The CLI SAPI was released for the first time with PHP 4.2.0, but was still experimental and had to be explicitly enabled with --enable-cli when running. / configure.
CLI SAPI は、圓初 PHP 4.2.0 でリ リヌスされたしたが、この時点では実隓的なステヌタスにあったため、 ./configure を実行する際に、明瀺的に --enable-cli を指定するこずにより、有効ずする必芁 がありたした。 PHP 4.3.0 以降、 CLI SAPI はもはや実隓的なステヌタスではなくなりた した。このため、 垞に 構築され、 php (Windowsでは php.exe ず いう名前ずなりたす)バむナリずしおむンストヌルされたす。
You may use --disable-cli to disable it.
CLI SAPI を他の SAPI ず比べた時 の倧きな違いを以䞋に瀺したす。
By default when executing make, both the CGI and CLI are built and placed as sapi / cgi / php and sapi / cli / php respectively, in your php source directory.
CGI SAPI ず異なり、ヘッダが出力されたせん。
If a module SAPI is chosen during configure, such as apxs, or the --disable-cgi option is used, the CLI is copied to {PREFIX} / bin / php during make install otherwise the CGI is placed there.
CGI SAPI は、HTTPヘッダの出力を抑制する機胜を 提䟛しおいたすが、等䟡な機胜は CLI SAPI ではサ ポヌトされおいたせん。
If you want to override the installation of the CGI binary, use make install-cli after make install.
以䞋に瀺すいく぀かの php.ini ディレクティブは、 CLI SAPI により䞊曞きされたす。これは、シェル環境では意味が ないためです。
Note:
衚 23-1䞊曞きされる php.ini のディレクティブ
The windows package distributes the CGI as php.exe and has a folder named cli with the CLI in it, so: cli / php.exe.
泚意 これらのディレクティブは、蚭定ファむル php.ini たたはカスタム蚭 定ファむル(指定した堎合のみ)で他の倀に初期化できたせん。この制 限は、これらのデフォルト倀が党おの蚭定ファむルをパヌスした埌に 適甚されるためです。しかし、これらの倀は実行時に倉曎するこずが 可胜です。 (䞊蚘のディレクティブの党おに぀いおこれが圓おはたるわけではあり たせん。䟋えば、 register_argc_argv)
See also the function php_sapi_name() and the constant PHP_SAPI.
シェル環境での動䜜を容易ずするために、以䞋の定数が定矩されおいた す。
Unlike the CGI SAPI, no headers are written to the output.
衚 23-2CLI固有の定数
CLI is started up in quiet mode by default, though the -q switch is kept for compatibility so that you can use older CGI scripts.
䞊蚘のように、 stderr のようなストリヌムを自分 でオヌプンする必芁はなく、以䞋のようにストリヌムリ゜ヌスの代わり に定数を䜿甚するだけでかたいたせん。
Plain text error messages (no HTML formatting).
CLI SAPI は、実行されるスクリプトのディレクト リにカレントディレクトリを倉曎 したせん!
Table 23-1.
CGI SAPI ずの違いを瀺す䟋を以䞋に瀺したす。
implicit_flush
CGI 版により実行した堎合、出力は以䞋のようにな りたす。
You still can use output buffering if you want to defer or manipulate standard output.
CLI SAPI を䜿甚した堎合の出力は次のようになり たす。
Whereas applications written for the web are often executed very quickly, shell application tend to have a much longer execution time.
泚意 CGI SAPI は、この CLI SAPI の動䜜をコマンドラむン実行時のスむッチ -C によ りサポヌトしおいたす。
As of PHP 4.3.0, the PHP variables $argc and $argv are registered and filled in with the appropriate values when using the CLI SAPI.
PHP バむナリにより提䟛されるコマンドラむンオプショ ンの䞀芧は、 -h スむッチを指定しお PHP を実行するこずによりい぀でも調べるこずができ たす。
Regardless of version or register_globals setting, you can always go through either $_SERVER or $HTTP_SERVER_VARS.
CLI SAPI は、実行する PHP コヌド を取埗するために䞉皮類の異なる手段をサポヌトしおいたす。
This is a limitation because those default values are applied after all configuration files have been parsed.
PHP に特定のファむルの実行を指瀺する。
To ease working in the shell environment, the following constants are defined:
実行する PHP コヌドをコマンドラむンで盎接指定する。
Given the above, you don 't need to open e.g. a stream for stderr yourself but simply use the constant instead of the stream resource:
泚意 この䟋をよくみお䞋さい。開始/終了タグがありたせん! -r スむッチを䜿甚した堎合、これらのタグは䞍芁 ずなりたす。これらのタグを䜿甚するずパヌサ゚ラヌを発生したす。
The CLI SAPI does not change the current directory to the directory of the executed script!
実行する PHP コヌドを暙準入力 (stdin )で指定する。
?php / * Our simple test application named test.php* / echo getcwd(), "\n";?
これは匷力な機胜で、以䞋の(仮想的な)䟋に瀺すように、動的に PHP コヌドを生成し、実行バむナリに入力するこず ができたす。
$some_application _BAR_ some_filter _BAR_ php _BAR_ sort -u final_output.txt
スクリプトに指定する匕数が文字 - で始たっおいない 限り、特に留意すべきこずはありたせん。スクリプトに指定する匕数が文 字 - で始たる堎合、 PHP 自䜓がこ れをパヌスする必芁があるずみなすため、問題を発生したす。 これを防止するため、匕数リストセパレヌタ -- を䜿甚 しお䞋さい。 PHP にパヌスされる匕数の埌に このセパレヌタを眮くず、その埌の党おの匕数はそのたたパヌスされずに スクリプトに枡されたす。
The number of arguments which can be passed to your script is not limited by PHP (the shell has a certain size limit in the number of characters which can be passed; usually you won't hit this limit).
たた、 PHP をシェルスクリプトずしお䜿甚する他の 手段がありたす。最初の行が #!/usr/bin/php で始たり、 PHP の開始/終了タグの䞭に通垞の PHP コヌドが続くスクリプトを曞き、適圓なファむル 実行属性を蚭定するこずが可胜です。この方法は、通垞のシェル/Perlスク リプトず同様に実行するこずができたす。
The arguments passed to your script are available in the global array $argv.
衚 23-3コマンドラむンオプション
The second registered global variable is $argc which contains the number of elements in the $argv array (not the number of arguments passed to the script).
カラヌ構文ハむラむト衚瀺された゜ヌスを衚瀺したす。
Passing an argument to your script which starts with a - will cause trouble because PHP Passing an argument to your script which starts with a - will cause trouble because PHP itself thinks it has to handle it.
このオプションは、ファむルをパヌスし、 HTML ハむラむト衚瀺版のファむルを生成し、暙準出力に曞き出す内郚機 構を䜿甚したす。行うのは、 code [...] /code のブロック を生成するこずだけで、 HTML ヘッダは出力され ないこずに泚意しお䞋さい。
After this separator has been parsed by PHP, every argument following it is passed untouched to your script.
泚意 このオプションは、 -r オプションず同時に䜿 甚するこずはできたせん。
You can write a script where the first line starts with #! / usr / bin / php.
コメントず空癜文字を削陀しお゜ヌスを衚瀺したす。
Once you have set the execution attributes of the file appropriately (e.g. chmod +x test) your script can be executed like a normal shell or perl script:
泚意 このオプションは、 -r オプションず同時に䜿 甚するこずはできたせん。
$chmod 755 test $. / test -h - - foo array( 4) {[0]= string(6) ". / test" [1]= string(2) "-h "[2]= string(2) "- -" [3]= string(3) "foo "}
-f オプションに指定したファむル名をし、 実行したす。このスむッチはオプションで省略するこずもできたす。 実行するスクリプトを指定するだけで充分です。
Display colour syntax highlighted source.
PHP, PHP SAPI, Zendのバヌゞョンを暙準出力に出力したす。䟋
Note that all it does it to generate a block of code [...] / code HTML tags, no HTML headers.
このオプションを䜿甚するこずにより、 php.ini を探すディレクト リを指定したり、カスタマむズされた INI ファ むル( php.ini ずいう名前である必芁はありたせん)を盎接指定する こずが可胜です。䟋
This switch is optional and can be left out.
PHPを察話的に実行したす。
$php -v PHP 4.3.0 (cli), Copyright (c) 1997-2002 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies
このオプションにより php.ini で指定できる蚭定ディレクティブ にカスタム倀を蚭定するこずができたす。構文は以䞋のようになりたす。
$php -c / custom / directory / my_script.php $php -c / custom / directory / custom-file.ini my_script.php
䟋:
The syntax is:
デバッガ/プロファむラ甚の拡匵情報を出力したす。
Passing a filename with an absolute path information will not use the systems library search path.
このオプションにより、指定した PHP コヌドの 構文チェックのみを簡単に行なうこずができたす。成功した堎合、 テキスト No syntax errors detected in filename が、暙準出力に曞き蟌たれ、リタヌンコヌドは 0 ずなりたす。倱敗した堎合、テキスト Errors parsing filename に加えお、内郚パヌサ゚ラヌメッセヌゞ が暙準出力に曞き蟌たれ、シェルリタヌンコヌドは、 255 ずなりたす。
On failure, the text Errors parsing filename in addition to the internal parser error message is written to standard output and the shell return code is set to 255.
このオプションは、(未定矩の関数のような)臎呜的な゚ラヌ(fatal error) はみ぀けたせん。臎呜的な゚ラヌに぀いおも調べたい堎合は、 -f を䜿甚しおください。
Use -f if you would like to test for fatal errors too.
泚意 このオプションは、オプション -r ず共に䜿甚するこずは できたせん。
$php -m [PHP Modules] xml tokenizer standard session posix pcre overload mysql mbstring ctype [Zend Modules]
このオプションを䜿甚するず、PHPは、PHPに組み蟌たれた (そしおロヌドされた) Zend モゞュヌルを出力したす。
If PHP is not working correctly, it is advisable to use php -i and see whether any error messages are printed out before or in place of the information tables.
このオプションにより、コマンドラむンのみで PHP の実行ができるようになりたす。 PHP の開始および終了タグ (?php および?) は 䞍芁 で、これらを付けるず パヌサ゚ラヌずなりたす。
The PHP start and end tags (?php and?) are not needed and will cause a parser error if present.
泚意 このように PHP を実行する際に、コマンドラむンの 倉数がシェルにより行なわれる眮換ず干枉しないように泚意しお䞋さい。
Example showing a parser error
パヌサ゚ラヌを生じる䟋
The PHP executable can be used to run PHP scripts absolutely independent from the web server.
䟋 23-1 コマンドラむンから実行されるこずを意図したスクリプト(script.php)
On a Windows platform you can associate php.exe with the double click option of the .php files, or you can make a batch file to run the script through PHP.
䞊のスクリプトでは、特殊な先頭行が甚いられおおり、このファむルが PHPにより実行されるこずを瀺しおいたす。ここではCLI版を䜿甚しおいるため、 HTTPヘッダは出力されたせん。PHPで コマンドラむンアプリケヌションを䜿甚する際には、2぀の倉数 $argc and $argv を䜿甚するこずが できたす。 最初の倉数は、匕数の数に1(実行䞭のスクリプトの名前)を加えたものです。 2番目の倉数は、匕数を保持する配列で、スクリプト名を有する 芁玠0( $argv[0] )から始たっおいたす。
A simple example of writing a command line PHP program can be found below.
䞊のプログラムでは、匕数が1より少ないかたたは倚いかを調べおいたす。 たた、匕数が --help, -help, -h, -? の堎合、 ヘルプメッセヌゞを出力し、動的にスクリプト名を出力したす。 他の匕数を受け取った堎合、これを出力したす。
In the script above, we used the special first line to indicate that this file should be run by PHP.
䞊のスクリプトをUnixで実行する堎合、実行可胜ずした埌、 script.php echothis たたは script.php -h ずする必芁がありたす。 Windowsでは、この凊理を行なう以䞋のようなバッチファむルを䜜成するこずが できたす。
Also if the argument was --help, -help, -h or -?, we printed out the help message, printing the script name dynamically.
䟋 23-2 コマンドラむンPHPスクリプトを実行するバッチファむル(script.bat)
If you would like to run the above script on Unix, you need to make it executable, and simply call it as script.php echothis or script.php -h.
䞊のプログラムが script.php ずいう名前であるず し、 c:\php\php.exe に php.exe があるずするず、このバッチファむルは、远加したオプション script.bat echothis たたは script.bat -h を指定しお、スクリプトを実行したす。
See also the Readline extension documentation for more functions you can use to enhance your command line applications in PHP.
PHPのコマンドラむンアプリケヌションを拡匵するために䜿甚できる その他の関数に぀いおは、拡匵モゞュヌル Readline に関する ドキュメントも参照しおください。
If the PHP-imposed time limit (see set_time_limit()) is hit, the TIMEOUT state flag is turned on.
泚意 以䞋は、PHP 3.0.7 版以降に適甚されたす。
Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output.
PHP 内郚で、接続ステヌタスが保持されたす。 これは、次の 3 ぀の状態をずりえたす。
When the timer expires the script will be aborted and as with the above client disconnect case, if a shutdown function has been registered it will be called.
通垞 PHP が実行されおいる堎合、NORMAL 状態がアクティブになりたす。 リモヌトクラむアントが接続を切った堎合、ABORTED 状態フラグが有効になりたす。 通垞、リモヌトクラむアントの接続断は、STOP ボタンを抌すこずにより発生したす。 PHP 偎の時間制限 (set_time_limit() 参照) にかかった堎合、 TIMEOUT 状態フラグが有効になりたす。
Any cookies sent to you from the client will automatically be turned into a PHP variable just like GET and POST method data, depending on the register_globals and variables_order configuration variables.
クラむアントから送られた党おのクッキヌは、 register_globals や variables_order の蚭定倀に埓っお、 GET や POST メ゜ッドのデヌタず党く同様に自動的に PHP 倉数に倉換 されたす。倚数の倀を䞀぀のクッキヌに割り付けたい堎合は、 [] をクッキヌ名に加えおください。
In PHP 4.1.0 and later, the $_COOKIE auto-global array will always be set with any cookies sent from the client. $HTTP_COOKIE_VARS is also set in earlier versions of PHP when the track_vars configuration variable is set.
PHP 4.1.0以降では、クラむアントから送信された党おのクッキヌは垞に $_COOKIE ずいう(垞にグロヌバルな)配列に栌玍されたす。 それ以前のバヌゞョンでも、 track_vars がセットされおいれば $HTTP_COOKIE_VARS にクッキヌの内容が栌玍されたす。
Prev
ちょっずした泚意やブラりザのバグずいった詳现に関しおは、 setcookie() を参照しおください。
The default is 2 Megabytes.
MAX_FILE_SIZE に upload_max_filesize で指定されたファむルサむズより倧きなファむルサむズを指定する こずはできたせん。デフォルトは、2メガバむトです。
Make sure to set memory_limit large enough.
メモリ制限が有効な堎合、 memory_limit により倧きな倀を蚭定 するこずが必芁ずなる可胜性がありたす。 memory_limit に充分倧きな倀 を蚭定するようにしお䞋さい。
Make sure to set max_execution_time large enough.
max_execution_time に蚭定した倀が小さすぎた堎合、スクリプトの実行時間がこの倀を越える 可胜性を生じたす。 max_execution_time に充分倧きな倀を蚭定するよう にしお䞋さい。
Make sure to set post_max_size large enough.
post_max_size の蚭定倀が小 さすぎた堎合、倧きなファむルをアップロヌドするこずができなくなりた す。 post_max_size に充分倧きな倀を蚭定するように しお䞋さい。
Please note that the CERN httpd seems to strip off everything starting at the first whitespace in the content-type mime header it gets from the client.
凊理するファむルを怜蚌しない堎合、ナヌザヌが他のディレクトリにある 非公開情報にアクセスできる可胜性を生じたす。
Due to the large amount of directory listing styles we cannot guarantee that files with exotic names (like containing spaces) are handled properly.
CERN httpd は、クラむアントから埗た content-type MIME ヘッダにおい お最初が空癜文字で始たるものを切り捚おるようですので泚意しお䞋さい。 このような動䜜をする限り、CERN httpd は、ファむルアップロヌド機胜を サポヌトしないでしょう。
The error code can be found in the ['error'] segment of the file array that is created during the file upload by PHP.
PHP 4.2.0以降、PHPはファむル配列ずずもに適圓な゚ラヌコヌドを返したす。 ゚ラヌコヌドは、PHPによるファむルアップロヌドの間に生成され、 ファむル配列の ['error'] 芁玠で アクセス可胜です。蚀い換えるず、゚ラヌは、 $_FILES['userfile']['error'] でアクセス可胜でしょう。
Value:
倀: 0; ゚ラヌはなく、ファむルアップロヌドは成功しおいたす。
Value:
倀: 1; アップロヌドされたファむルは、 php.ini の upload_max_filesize ディレクティブの倀を超えおいたす。
Value:
倀: 2; アップロヌドされたファむルは、HTMLフォヌムで指定された MAX_FILE_SIZE を超えおいたす。
Value:
倀: 3; アップロヌドされたファむルは䞀郚のみしかアップロヌドされおいたせん。
Value:
倀: 4; ファむルはアップロヌドされたせんでした。
Prev
泚意 これらはPHP 4.3.0でPHP定数ずなりたした。
Related Configurations Note:
関係する蚭定に関する泚蚘 php.ini の file_uploads, upload_max_filesize, upload_tmp_dir post_max_size ディレクティブ も参照䞋さい。
Note that PHP also supports PUT-method file uploads as used by Netscape Composer and W3C 's Amaya clients.
PHPはNetscape ComposerおよびW3CのAmayaクラむアントにより䜿甚される PUTメ゜ッドによるファむルアップロヌドもサポヌトしおいるこずに泚意 しお䞋さい。詳现は、 PUTメ゜ッドのサポヌト を参照䞋さい。
A file upload screen can be built by creating a special form which looks something like this:
ファむルアップロヌド画面は、次のような特別なフォヌムを䜜成するこず により、䜜成するこずができたす。
File Upload Form
䟋 18-1ファむルアップロヌド甚のフォヌム
Warning
MAX_FILE_SIZEはブラりザぞの勧告に過ぎたせん。この最倧倀を 出し抜くのは簡単なこずなので信頌しおはいけたせん。しかし、 PHP偎の最倧サむズの蚭定を欺くこずはできたせん。
The autoglobal $_FILES exists as of PHP 4.1.0 The $HTTP_POST_FILES array has existed since PHP 4.0.0.
$_FILES の内容は次のようになりたす。ここでは、䞊の䟋のスクリプトで䜿われたように、 アップロヌドファむルの名前ずしお userfile を䜿甚する こずを仮定しおいるこずに泚意しお䞋さい。
Using $_FILES is preferred.
クラむアントマシンの元のファむル名。
The contents of $_FILES from our example script is as follows.
ファむルのMIME型。ただし、ブラりザがこの情報を提䟛する堎合。 䟋えば、 "image/gif" のようになりたす。
The original name of the file on the client machine.
アップロヌドされたファむルのバむト単䜍のサむズ。
The error code associated with this file upload. ['error'] was added in PHP 4.2.0
アップロヌドされたファむルがサヌバヌ䞊で保存されおいるテンポラ リファむルの名前。
PHP 3 does not support $HTTP_POST_FILES.
このファむルアップロヌドに関する ゚ラヌコヌド ['error'] は、PHP 4.2.0で远加されたした。
For example, $userfile_name will equal $_FILES[ 'userfile']['name'], $userfile_type will equal $_FILES['userfile']['type'], etc.
泚意 4.1.0より前のバヌゞョンのPHPでは、この倉数は $HTTP_POST_FILES で、 $_FILES の ような オヌトグロヌバル 倉数ではありたせんでした。PHP 3は、 $HTTP_POST_FILES をサポヌトしおいたせん。
The server 's default directory can be changed by setting the environment variable TMPDIR in the environment in which PHP runs.
php.ini で register_globals が on ずなっおいる堎合、远加の倉数が利甚可胜ずなりたす。 䟋えば、 $userfile_name は、 $_FILES['userfile']['name'] ず同じで、 $userfile_type は、 $_FILES['userfile']['type'] ず同じずいったようになりたす。 PHP 4.2.0以降は、register_globalsのデフォルトはoffであるこずを 留意䞋さい。このディレクティブに䟝存しないこずが掚奚されたす。
Here' s some debugging info:\n"; print_r($_FILES);}?
䟋 18-2ファむルのアップロヌドを怜蚌する
You can for example use the $_FILES[ 'userfile']['size'] variable to throw away any files that are either too small or too big.
以䞋の䟋は、4.0.2 より埌のバヌゞョンの PHP 4 甚です。 is_uploaded_file() および move_uploaded_file() の関数の゚ントリを 参照䞋さい。
The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.
移動たたは名前の倉曎が行われおいない堎合、リク゚ストの終了時にその ファむルはテンポラリディレクトリから削陀されたす。
It is obviously not a good idea for Apache or PHP to automatically let everybody overwrite any files in your web tree.
PHP は、Netscape Composer や W3C Amaya のようなクラむアントで サポヌトされる HTTP PUT メ゜ッドをサポヌトしたす。 PUT リク゚ストは、ファむルアップロヌドよりもかなり簡単であり、 次のようなものになりたす。
The only trick here is that when PHP sees a PUT-method request it stores the uploaded file in a temporary file just like those handled but the POST-method.
これにより、この行を指定したコンテキストにマッチするURIを有する党 おのPUTリク゚ストが put.php スクリプトに送られるよう Apache に指 定したす。 もちろん、拡匵子 .php により PHP が実行されるよう蚭定 され、PHP がアクティブであるこずが必芁です。
So, your PUT handling PHP script has to copy that file somewhere.
put.php ファむルの䞭で次のように凊理を行う必芁がありたす。
Only "Basic" authentication is supported.
PHP バヌゞョンに関する泚意 $_SERVER のような オヌトグロヌバル は、 PHPバヌゞョン 4.1.0 で利甚可胜です。 $HTTP_SERVER_VARS は、PHP 3以降で利甚可胜です。
An example script fragment which would force client authentication on a page is as follows:
ペヌゞ䞊でクラむアント認蚌を匷制するスクリプトの䟋を以䞋に瀺したす。
HTTP Authentication example
䟋 16-1HTTP 認蚌の䟋
Basic realm=" My Realm"'); header('HTTP / 1.0 401 Unauthorized'); echo'Text to send if user hits Cancel button'; exit;} else {echo "p Hello {$_SERVER['PHP_AUTH_USER']}. / p"; echo "p You entered {$_SERVER['PHP_AUTH_PW']} as your password. / p";}?
互換補に関する泚意 HTTPヘッダ行をコヌディングする際には泚意を芁したす。党おのクラむア ントぞの互換性を最倧限に保蚌するために、キヌワヌド "Basic" には、 倧文字の"B"を䜿甚しお曞くべきです。realm文字列は(䞀重匕甚笊ではな く)二重匕甚笊で括る必芁がありたす。たた、"HTTP/1.0 401"ヘッダ行の コヌド"401"の前には、1぀だけ空癜を眮く必芁がありたす。
Perhaps by sending a query to a database, or by looking up the user in a dbm file.
バグのある Internet Explorer ブラりザには泚意しおください。このブラ りザは、ヘッダの順序に関しおずおもうるさいようです。今のずころ、 HTTP/1.0 401 ヘッダの前に WWW-Authenticate ヘッダを送るのが効果があるよ うです。