Submitted by:
Reviewed by:
Obtained from:


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@38980 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
WonHee Hwang 2001-01-09 10:41:17 +00:00
parent d81f1decab
commit a8a8b56e06
4 changed files with 219 additions and 263 deletions

View file

@ -1,24 +1,19 @@
<chapter id="features.cookies">
<title>Cookies</title>
<para>
PHP transparently supports HTTP cookies. Cookies are a mechanism
for storing data in the remote browser and thus tracking
or identifying return users. You can set cookies using the
<function>setcookie</function> function. Cookies are part of the
HTTP header, so <function>setcookie</function> must be called before
any output is sent to the browser. This is the same limitation that
<function>header</function> has.</para>
<para>
Any cookies sent to you from the client will automatically be
turned into a PHP variable just like GET and POST method data. If
you wish to assign multiple values to a single cookie, just add
<emphasis>[]</emphasis> to the cookie name. For more details see
the <function>setcookie</function> function.</para>
</chapter>
<chapter id="features.cookies">
<title>Cookies</title>
<para>
PHP는 HTTP Cookie를 투명하게(transparently) 지원한다.
Cookie 메카니즘은 트래킹이나 사용자 식별 등을 위해 원격 browser에
저장된 데이터를 돌려 받는 과정을 말한다.
여러분은 cookie를 설정하기 위해 <function>setcookie</function> 함수를 사용할 수 있다.
Cookie는 HTTP 헤더의 한 부분이므로, <function>setcookie</function> 함수는 브라우저로
보내는 어떤 데이터보다도 앞에 사용해야 한다.
이 제약은 <function>header</function> 함수와 같은 제약으로 보면 된다.</para>
<para>
클라이언트가 보내준 모든 cookie는 자동적으로 GET이나 POST 방식 데이터와 같은 PHP 변수로 변환된다.
만약 여러분이 동일한 cookie에 여러 값을 저장하고 싶다면 Cookie이름에 <emphasis>[]</emphasis>를 더하면 된다.
자세한 것은 <function>setcookie</function> 함수 설명을 참조하자.
</para>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml

View file

@ -1,104 +1,100 @@
<chapter id="features.error-handling">
<title>Error Handling</title>
<para>
There are several types of errors and warnings in PHP. They are:
<chapter id="features.error-handling">
<title>Error Handling</title>
<para>
PHP에는 다음과 같은 여러 에러와 경고 형태가 있다.:
<table>
<title>PHP error types</title>
<tgroup cols="4">
<thead>
<row>
<entry>Value</entry>
<entry>Constant</entry>
<entry>Description</entry>
<entry>Note</entry>
</row>
</thead>
<tbody>
<row>
<entry>1</entry>
<entry>E_ERROR</entry>
<entry>fatal run-time errors</entry>
<entry></entry>
</row>
<row>
<entry>2</entry>
<entry>E_WARNING</entry>
<entry>run-time warnings (non fatal errors)</entry>
<entry></entry>
</row>
<row>
<entry>4</entry>
<entry>E_PARSE</entry>
<entry>compile-time parse errors</entry>
<entry></entry>
</row>
<row>
<entry>8</entry>
<entry>E_NOTICE </entry>
<entry>
run-time notices (less serious than warnings)
</entry>
<entry></entry>
</row>
<row>
<entry>16</entry>
<entry>E_CORE_ERROR</entry>
<entry>fatal errors that occur during PHP's initial startup</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>32</entry>
<entry>E_CORE_WARNING</entry>
<entry>
warnings (non fatal errors) that occur during PHP's initial
startup
</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>64</entry>
<entry>E_COMPILE_ERROR</entry>
<entry>fatal compile-time errors</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>128</entry>
<entry>E_COMPILE_WARNING</entry>
<entry>compile-time warnings (non fatal errors)</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>256</entry>
<entry>E_USER_ERROR</entry>
<entry>user-generated error message</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>512</entry>
<entry>E_USER_WARNING</entry>
<entry>user-generated warning message</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>1024</entry>
<entry>E_USER_NOTICE </entry>
<entry>user-generated notice message</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry></entry>
<entry>E_ALL</entry>
<entry>all of the above, as supported</entry>
<entry></entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
<title>PHP error types</title>
<tgroup cols="4">
<thead>
<row>
<entry>Value</entry>
<entry>Constant</entry>
<entry>Description</entry>
<entry>Note</entry>
</row>
</thead>
<tbody>
<row>
<entry>1</entry>
<entry>E_ERROR</entry>
<entry>Normal Function Errors (일반적인 에러)</entry>
<entry/>
</row>
<row>
<entry>2</entry>
<entry>E_WARNING</entry>
<entry>Normal Warnings (일반적인 경고)</entry>
<entry/>
</row>
<row>
<entry>4</entry>
<entry>E_PARSE</entry>
<entry>Parser Errors (문법 에러)</entry>
<entry/>
</row>
<row>
<entry>8</entry>
<entry>E_NOTICE </entry>
<entry>
Notices (무시할 수 있는 알림이지만 버그의 가능성을 가지고 있는 경우)
</entry>
<entry/>
</row>
<row>
<entry>16</entry>
<entry>E_CORE_ERROR</entry>
<entry>fatal errors that occur during PHP's initial startup
(PHP가 처음 시작될 때 발생한 치명적 에러)</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>32</entry>
<entry>E_CORE_WARNING</entry>
<entry>warnings (non fatal errors) that occur during PHP's initial startup
(PHP가 처음 시작될 때 발생한 치명적이지 않은 경고)</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>64</entry>
<entry>E_COMPILE_ERROR</entry>
<entry>fatal compile-time errors (컴파일시 생긴 치명적 에러)</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>128</entry>
<entry>E_COMPILE_WARNING</entry>
<entry>compile-time warnings (non fatal errors) (컴파일시 발생한 치명적이지 않은 경고)</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>256</entry>
<entry>E_USER_ERROR</entry>
<entry>user-generated error message (사용자가 만든 에러 메세지)</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>512</entry>
<entry>E_USER_WARNING</entry>
<entry>user-generated warning message (사용자가 만든 경고 메세지)</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>1024</entry>
<entry>E_USER_NOTICE </entry>
<entry>user-generated notice message (사용자가 만든 알림 메세지)</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry/>
<entry>E_ALL</entry>
<entry>all of the above, as supported (지원가능한 위의 것 모두)</entry>
<entry/>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
The above values (either numerical or symbolic) are used to build
up a bitmask that specifies which errors to report. You can use the
<link linkend="language.operators.bitwise">bitwise operators</link>
@ -107,29 +103,24 @@
<filename>php.ini</filename>, however, and that no bitwise
operators will be understood within <filename>php3.ini</filename>.
</para>
<para>
In PHP 4, the default <link
linkend="ini.error-reporting">error_reporting</link> setting is
<para>
In PHP 4, the default <link linkend="ini.error-reporting">error_reporting</link> setting is
<literal>E_ALL &amp; ~E_NOTICE</literal>, meaning to display all errors
and warnings which are not E_NOTICE-level. In PHP 3, the default
setting is <literal>(E_ERROR | E_WARNING | E_PARSE)</literal>,
meaning the same thing. Note, however, that since constants are not
supported in PHP 3's <filename>php3.ini</filename>, the <link
linkend="ini.error-reporting">error_reporting</link> setting there
supported in PHP 3's <filename>php3.ini</filename>, the <link linkend="ini.error-reporting">error_reporting</link> setting there
must be numeric; hence, it is <literal>7</literal>.
</para>
<para>
The initial setting can be changed in the ini file with the <link
linkend="ini.error-reporting">error_reporting</link> directive, in
<para>
The initial setting can be changed in the ini file with the <link linkend="ini.error-reporting">error_reporting</link> directive, in
your Apache <filename>httpd.conf</filename> file with the
php_error_reporting (php3_error_reporting for PHP 3) directive, and
lastly it may be set at runtime within a script by using the
<function>error_reporting</function> function.
</para>
<warning>
<para>
<warning>
<para>
When upgrading code or servers from PHP 3 to PHP 4 you should
check these settings and calls to
<function>error_reporting</function> or you might disable
@ -137,39 +128,31 @@
may lead to empty documents without any feedback of what happened
or where to look for the problem.
</para>
</warning>
<para>
All <link linkend="language.expressions">PHP expressions</link> can
also be called with the "@" prefix, which turns off error reporting
for that particular expression. If an error occurred during such
an expression and the <link
linkend="ini.track-errors">track_errors</link> feature is enabled,
you can find the error message in the global variable
$php_errormsg.
</warning>
<para>
모든 <link linkend="language.expressions">PHP 표현식(expression)</link>은 "@"를 앞에 붙이고 호출되면 error reporting을 하지 않는다.
만약 <link linkend="ini.track-errors">track_errors</link> 옵션이 Enabled로 되어 있고 해당 문장에서 에러가 발생했다면,
$php_errormsg라는 전역변수에 에러 메시지가 담겨 있게 된다.
</para>
<warning>
<para>
<warning>
<para>
Currently the <link linkend="language.operators.errorcontrol">@
error-control operator</link> prefix will even disable error
reporting for critical errors that will terminate script
execution. Among other things, this means that if you use <link
linkend="language.operators.errorcontrol">@</link> to suppress
execution. Among other things, this means that if you use <link linkend="language.operators.errorcontrol">@</link> to suppress
errors from a certain function and either it isn't available or
has been mistyped, the script will die right there with no
indication as to why.
</para>
</warning>
<para>
</warning>
<para>
Below we can see an example of using the error handling capabilities in
PHP. We define a error handling function which logs the information into
a file (using an XML format), and e-mails the developer in case a critical
error in the logic happens.
<example>
<title>Using error handling in a script</title>
<programlisting role="php">
<title>Using error handling in a script</title>
<programlisting role="php">
&lt;?php
// we will do our own error handling
error_reporting(0);
@ -270,23 +253,20 @@ $t3 = distance($a,$b).&quot;\n&quot;;
?&gt;
</programlisting>
</example>
</example>
This is just a simple example showing how to use the
<link linkend="ref.errorfunc">Error Handling and Logging
functions</link>.
</para>
<para>
<para>
See also <function>error_reporting</function>,
<function>error_log</function>,
<function>set_error_handler</function>,
<function>restore_error_handler</function>,
<function>trigger_error</function>,
<function>user_error</function>
</para>
</chapter>
</para>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml

View file

@ -1,26 +1,28 @@
<chapter id="features.http-auth">
<title>HTTP authentication with PHP</title>
<simpara>
The HTTP Authentication hooks in PHP are only available when it is
running as an Apache module and is hence not available in the CGI version.
In an Apache module PHP script, it is possible to use the
<function>Header</function> function to send an "Authentication Required"
message to the client browser causing it to pop up a Username/Password
input window. Once the user has filled in a username and a password,
the URL containing the PHP script will be called again with the variables,
$PHP_AUTH_USER, $PHP_AUTH_PW and $PHP_AUTH_TYPE set to the user
name, password and authentication type respectively. Only "Basic"
authentication is supported at this point. See the <function>Header</function>
function for more information.</simpara>
<para>
An example script fragment which would force client authentication
on a page would be the following:
<chapter id="features.http-auth">
<title>HTTP authentication with PHP</title>
<simpara>
(역자주. HTTP authentication이란 Web Client에게 ID와 Password를 입력받아,
그 ID와 Password로 Web문서에 접근을 허가, 불허하는 기능을 말한다.
자세히 알고 싶다면 RFC1945의 Authentication 부분을 참고하기 바란다.
http://pec.etri.re.kr/!qkim/HTTP/에 한글 번역 문서도 있으니 참조하자.)
</simpara>
<simpara>
PHP를 사용한 HTTP 인증은 Apache 모듈로 사용될 때만 동작한다.
CGI 버젼에서는 이 기능을 사용할 수 없다.
Apache 모듈의 PHP 스크립트에서 <function>Header</function>라는 함수를 사용하면
Client 브라우저에게 Username과 Password를 입력받는 윈도우를 띄우도록 하는
"인증 요구"("Authentication Required") 메시지를 보낼 수 있다.
일단 사용자가 Username과 Password를 입력하면,
user name, password, authentication type의 값을 가지는
$PHP_AUTH_USER, $PHP_AUTH_PW, $PHP_AUTH_TYPE의 3개의 변수를 가지고
해당 URL(PHP 스크립트를 포함한)이 다시 불리워진다.
현재 authentication type은 "Basic"만이 지원된다.
자세한 사용법은 <function>Header</function> 함수를 살펴 보자.</simpara>
<para>
client authentication을 사용하여 그 입력된 값을 출력하는 예제가 아래에 있다. :
<example>
<title>HTTP Authentication example</title>
<programlisting role="php">
<title>HTTP Authentication example</title>
<programlisting role="php">
&lt;?php
if(!isset($PHP_AUTH_USER)) {
Header(&quot;WWW-Authenticate: Basic realm=\&quot;My Realm\&quot;&quot;);
@ -33,43 +35,36 @@
}
?>
</programlisting>
</example></para>
<para>
Instead of simply printing out the $PHP_AUTH_USER and
$PHP_AUTH_PW, you would probably want to check the username and
password for validity. Perhaps by sending a query to a database,
or by looking up the user in a dbm file.</para>
<para>
Watch out for buggy Internet Explorer browsers out there. They
seem very picky about the order of the headers. Sending the
<emphasis>WWW-Authenticate</emphasis> header before the
<errorcode>HTTP/1.0 401</errorcode> header seems to do the trick
for now.</para>
<simpara>
In order to prevent someone from writing a script which reveals
the password for a page that was authenticated through a
traditional external mechanism, the PHP_AUTH variables will not be
set if external authentication is enabled for that particular
page. In this case, the $REMOTE_USER variable can be used to
identify the externally-authenticated user.</simpara>
<simpara>
Note, however, that the above does not prevent someone who
controls a non-authenticated URL from stealing passwords from
authenticated URLs on the same server.</simpara>
<simpara>
Both Netscape and Internet Explorer will clear the local browser
window's authentication cache for the realm upon receiving a
server response of 401. This can effectively "log out" a user,
forcing them to re-enter their username and password. Some people
use this to "time out" logins, or provide a "log-out" button.</simpara>
<simpara></simpara>
<example>
<title>HTTP Authentication example forcing a new name/password</title>
<programlisting role="php">
</example>
</para>
<para>
여러분은 $PHP_AUTH_USER 와 $PHP_AUTH_PW를 단순히 출력하는 대신,
사용자의 식별을 위해 username과 password를 사용하기를 원할 것이다.
이때는 Database에 Query하거나 직접 dbm 파일에서 찾아보는 등의 방법으로 가능할 것이다.</para>
<para>
Internet Explorer browser에서는 버그로 인해 Header의 순서가 매우 까다롭다.
<emphasis>WWW-Authenticate</emphasis>
<errorcode>HTTP/1.0 401</errorcode>보다 먼저 보내는 것이 현재 가능한 트릭으로 보인다.
</para>
<simpara>
비밀번호의 유출을 우려하여 HTTP에서 제공하는 인증을 사용하는 대신
기존의 외부 메카니즘을 사용할 경우에는 물론 PHP_AUTH 변수는 설정되지 않는다.
이런경우 externally-authenticated user를 확인하기 위해 $REMOTE_USER 변수를 사용할 수 있다.
</simpara>
<simpara>
유의할 점은 인증이 필요한 페이지와 인증이 필요없는 페이지가 같은 서버상에 존재할 때,
인증이 필요없는 URL을 control할 수 있는 누군가가,
인증이 필요한 URL의 암호를 훔쳐보는 것은 막을 수 없다는 점이다.
</simpara>
<simpara>
Netscape와 Internet Explorer 모두 401응답 코드를 서버에서 받게되면
local browser window의 authentication cache를 clear한다.
즉, 이것은 "log out"개념이 되는 것으로, 사용자들로 하여금 username과 암호를 다시 입력하게 한다.
일부는 이것을 통해 login의 "time out"이나 "log-out"버튼을 만드는데 사용한다
</simpara>
<example>
<title>HTTP Authentication example forcing a new name/password</title>
<programlisting role="php">
&lt;?php
function authenticate() {
Header( &quot;WWW-authenticate: basic realm=\&quot;Test Authentication System\&quot;&quot;);
@ -93,20 +88,16 @@
}
?>
</programlisting>
</example>
<simpara>
This behavior is not required by the HTTP Basic authentication
standard, so you should never depend on this. Testing with Lynx
has shown that Lynx does not clear the authentication credentials
with a 401 server response, so pressing back and then forward
again will open the resource (as long as the credential
requirements haven't changed).</simpara>
<simpara>
Also note that this does not work using Microsoft's IIS server and
the CGI version of PHP due to a limitation of IIS.</simpara>
</chapter>
</example>
<simpara>
그러나 이 동작은 HTTP Basic authentication 기준에 보장된 것은 아니므로 이 기능에 의존하여서는 안된다.
Lynx에서는 401 서버 응답을 받아도 authentication 정보를 clear하지 않는다.
따라서 Back을 누르고 다시 Forward 버튼을 눌러서 다시 접근할 수 있다.</simpara>
<simpara>
또한 이 Authentication 기능은 Microsoft's IIS server에서
CGI version의 PHP를 사용할 경우에는 IIS의 제약으로인해 동작하지 않는다.
</simpara>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml

View file

@ -1,21 +1,17 @@
<chapter id="features.images">
<title>Creating and manipulating images</title>
<simpara>
PHP is not limited to creating just HTML output. It can also be
used to create and manipulate image files in a variety of different
image formats, including gif, png, jpg, wbmp, and xpm. Even more
convenient, php can output image streams directly to a browser. You
will need to compile PHP with the GD library of image functions for
this to work. GD and PHP may also require other libraries, depending
on which image formats you want to work with. GD stopped supporting
Gif images in version 1.6.
<chapter id="features.images">
<title>PHP에서 이미지 생성과 수정(Creating and manipulating images)</title>
<simpara>
PHP는 단지 HTML출력을 만드는 것만 할 수 있는 것이 아니다.
PHP는 GIF image file도 만들 수 있을 있을 뿐아니라,
사용하기에 편리한 GIF image stream까지 만들 수 있다.
이를 위해서 여러분은 PHP를 컴파일 할 때, image 함수를 가지고 있는 GD 라이브러리를 포함하여야 한다.
GD와 PHP는 사용하는 이미지 포맷 형태에 따라 다른 라이브러리도 요구한다.
GD는 버전 1.6부터 GIF 이미지 지원을 하지 않는다.
</simpara>
<para>
<example>
<title>PNG creation with PHP</title>
<programlisting role="php">
<para>
<example>
<title>PNG creation with PHP</title>
<programlisting role="php">
&lt;?php
Header("Content-type: image/png");
$string=implode($argv," ");
@ -27,20 +23,14 @@
ImageDestroy($im);
?>
</programlisting>
</example>
This example would be called from a page with a tag like: &lt;img
src=&quot;button.php?text&quot;&gt; The above button.php script
then takes this &quot;text&quot; string an overlays it on top of a
base image which in this case is &quot;images/button1.png&quot;
and outputs the resulting image. This is a very convenient way to
avoid having to draw new button images every time you want to
change the text of a button. With this method they are
dynamically generated.
</example>
위의 예제는 &lt;img src=&quot;button.php?text&quot;&gt; 와 같은 tag이 있는 페이지로부터 불려지게 될 것이다.
그러면 위에있는 button.php 스크립트는 "text"라는 문자열을
"images/button1.gif"에 오버레이 시켜 결과 image에 출력한다.
이렇게 하면 버튼에 들어가는 글씨를 매번 손쉽게 바꿔 쓸 수 있고,
또한 매번 이미지 파일을 만들 필요가 없어 효율적이고 간단하다.
</para>
</chapter>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml