You are on page 1of 288

Larry Ullman

PHP for the


World Wide Web

Peachpit Press

, 2001

004.438
32.973.26-018.2
51
51 .
: . . -.: , 2001. 288 .: . ().

ISBN 5-94074-124-
- HTML . : , , , ;
. , , , cookie .
Web-, . , Web-,
.
Web-,
, ,
.
Authorized translation from the English language edition, entitled "PHP for the World Wide Web
' Visual Quickstart Guide ".published by Peachpit Press, Copyright2001.
All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording or by any information storage retrieval system,
without permission from the Publisher.
Russian language edition published by DMK Press. Copyright2001
.
.
, , . , ,
. , .
, , . .

ISBN 0-201-72787-0 (.)


ISBN 5-94074-124- (.)

2001 by Peachpit Press


,
, 2001

19





HTML
v.
HTML

32

.32
33
...34
36
36

HTML-

38


Get Post

19
20
22
23
25
26
28

38
41
43
45

, ,

50
50
53
55
56
58

61
'.


(, )


79

if

if-else
if-elseif
switch
while
for

79
83
89
91
94
101
106

.61
65
67
71
74

109
.

9


,
,

110
112
115
118
121
125
128

130
130
131
..133
137
140

144
144
148
152
157

10

165

..165
167
173
180
185
188

11

195

12

197
200
204
207

cookie

211

cookie
cookie
cookie

212
217
220

13
Web-
include require

HTTP-

14




die



Linux
Windows

224
,

224
228
236
240 .

245
245
248
252
256

260
260
265
267

SSL
PHP-

269
269
270
272




Web-

273
273
274
277
278
279

283

. , , , .
(OSS - Open Source
Software), -, . Unix, Linux. ,
,
.
, . ,
Web, , , , .
, ,
. ,
, Web-
.


Personal Homft Page
( ). 1994 (Rasmus Lerdorf), , . ,
^
, (: Hypertext Preprocessor), ,
, HTML- (HTML - ).
)' (www.php.net. . 1), HTML . ,
, .

Whit It PHP?
is t sarver-side,
cross-platform, HTML
embedded icflptlng
language. If you ire
completely newto PHP
and went to gat some
Idee of how It works,
have a look at the
Introductory tutorial.
Once you get beyond
that, have a look at the
example archive altes
end torn* ofthe other
resources ivttlablt in
the tmf(i wtlon
PHPISaprolettOflhe
Apache SofNvare
FpunelitlQn

So, How Much


DoltCott?
This may sound a little
foreign to *H you folkr
coming from i non-Unix
bsekground.butPHP
doeenlceitenythlno..
Youcah-uaeltfor
non-commercial uit all
you wtnt You can give it
to your IHende. print It out
nd hang It on your will
or itltrbr lunch.
Weltwi loth world of
Oiwi Source

Mailing Lists temporarily unavailable


.'(^'.'!),- !'>/While the CVS repository has bean reactivated, we are still working on reestablishing our
mailing list infrastructure. Wfl will keep you poeted ebout the progress. Thank you for your patience.
Note also the! the PDF version of the documentation is also unavailable until furt.her notice.

New Usage Stats For May available


.'; NalcraH and bSd have published the current results for their Web
Sewer surveys both of which continue to show impressive growth for PHP.
Check out the u

ApacheCon Europe 2001 Call for Participation


'C^'.'M^.'iX'^The call for oarticipujon has gone out for ApecheCon Europe 2001. which will run
October 15-17 in Dublin, Inlend. Have an Idea for a ssstion or tutorial you could present ibout PHP or
other Apache Software Foundation projects? Submit it before June 2,30011

PHP Conference
JMttiyWjl The rat official PHP Conference, pan of the QRalllv oen Smrc. Cnmamian will bring
the community together for sessions end tutorials deeigned to explore and etrengthen PHP in the open
sourcs space. Take a took under the hood et everything PHP~from understanding PHP on wiretoes
devices to participating in a discussion on the future of PHP featuring eoms of the core developere and
luminariee from tha PHP community. The confaranca runs July 23-27,2001, at the Sheraton San Diego
Hotel anil Marina In SanDilgo, Cekfcmia, tfrysl.rbefcr. Jya to ..v. uol. 1.

PHP 4.0.5 Releasedl

. 1 Web- , . , , , . ,

-, ,
( , ,
Web-). -
. , ,
, Navigator Internet Explorer.
.
, Unix, Windows NT, Macintosh, OS/2 ,
.
. , PHP- , HTML-.
HTML , HTML, Web-.
,
HTML.
, , . ,

, , URL (Uniform Resource Locator - , Web-). ,


Java, Perl, ,
Internet.
-JavaScript. , Web-. JavaScript
, .
. , JavaScript -, - Java.
, , , - 3.x.
4.0, , , .
- .
4.0 www.zend.com (. 2).

lto ^. ^^fr*wi(to^a^;*^:?>:^C>-'^^n;.

Cet Gaiety SpeOgM: Need to


create a form quickly and easily?
In Part 1 of a series on FormMail,
ynull find out wtiyfliie Is such
powerful and usefur script
{12.JUN.2001] MORE
PHP WeekVSumroav PHP 4.0.6
RC 3 gets rolled out, matting lists
still unavailable, Apache 2 end core dumping. [1 1 JUN.2001]
PHP In Korea: A PHPffend
seminar m Seoul highlights PHP's
growing popularity In the Far East.
[07 JUN.2001] MORE
Mew! PubtclMf ' Corner:
Wondering whan new on tht
PHP bookshelf? At the Publishers'
Comer, vouli flnd Intormatrve
excerpts from the latest books on
PHP.[oe.JUN.2001] MORE
Cede Galwy SpoMoM: Learn how
you can use PHP to simulate GET
and POST form submissions torn
wtttiln your PHP scripts.
[05 JUN.2001] MOM?
PHP WMMySumm-y Mat ling
list tribulations^ new TUX SAPl
module and zip extension, ftxes to
the CURL extension and PHP test
sutte. (04 JUN.2001] MORE
JokiournewZeodZ-PM.
Pi van*: Are you a Web
developer or isv? Them you may

Zend, a unique leader in PHP technology. provides exceptional commercial vtabHKy artti backing tor PHP-bawd
solutions. At the same me, the company remains committed to the advancement and proliferation of PHP as an
open-source Web scripting language.

Encoder Unlimited1*
Encode *n unlimited number of PHP applications
The Company
Mission Technology * Founders fuss Relaasaa
Career

Zend Pr duett
Zend com' ?end Engine' Z*nd Cache *ftQ6
Encoder Unlimited * Zend IDE ' 2and
Stfvr Suite * Zend Launched land SOS * ZjGtl

AtooutgHP' What" Newln PHP^4 Downioafl PJ^P Ticket Usl * Buv Inctdtntt Submit Titkete
PHP Manual Zpnd API pocs Mpno Usf Archive Ustr Qulde
* A|ohibe,pcall.tst

'
TonRalad * Ton Authors *

Aittcle Studltf
lutortat Column*

' TPR'ted 'To Authors

Who^Wha- Hail Of Fame

PHP . Q^.n*fa^ Zend Pmdudt * 2\ OnBmiaar

- .
urn &*
.

. 2 Zend - , 4.0.

PHP
, , , . Web- : HTML,
CGI- (Common Gateway Interface, ( ) Perl), ASP (Active Server Pages) JSP (Java Server Pages).
JavaScript , , HTML-
, CGI.
^
HTML ,
,
. HTML-, .
Web- (, ). HTML ,
.
Web- , Web- HTML. , CGI-, .

Web-, , .
Web- , HTML.
, : Web- CGI, ASP JSP
Web-? -, ' , CGI,
.

. ,
, . , , . : ASP CGI
, , ,
VBScript, a CGI - Perl ( ).
- -, Perl, VBScript Java Web-,
, . , , , , ,

CGI ASP, . , , Java Perl.


- HTML. Internet
. HTML
, JavaScript . HTML
. , , , . : HTML; HTML,
, .
Web-, ,
?


- . , , Web- .
Web-,
www.DMCinsights.com. ,
.
. Web- HTML (. 3).
, HTML- , ,
HTML-.
HTML- -.
Web- HTML,
(. 4).
,
, home.html home.php,
, , . HTML-. , .
Web- - , , .

HI
HTML
ML

HTML

URL

. 3 , (, )
HTML- .
, ASP, , ,

URL

I
'

. 4 Web- , . 3. HTML-
.

Web-,

HTML ,
. ,
. , , .

Web-
. ,
- , . ,
, (ISP - Internet Service Provider),
Web-, .
- , .
Web- (. 5).
- ( ,
Windows NT Linux), Web-. Apache Unix
NT Personal Web Sharing - Windows. , . , www.php.net. .
-
. NotePad, WordPad, SimpleText
, BBEdit, WordPerfect, Word
. , (WYSIWYG -

PHP is a server-side, cross-platform, HTML embedded scripting language. If you are completely new to PHP and wait to get some idea of now it works
have a took at the W
TNs'powerful scripting language (s gaming support from hosting companies world-wide, in an effort t6 help people find a hosting company that sifts
their needs, we've developed this drectory.
'isatch the directory now for hosting companies that have PHP and the other toots and servtes you need
What's New Here?
User Comments: Are you pleased or Disappointed with one of the companies listed in the directory? Add your own comments on the Mms
Board, and heb other users make a better-informed decision,
Want to list your company?
Add your company to the drectory. It's free.
Need to update your listing?
Go to the clients' section.

. 5 hosts.php.net ,
PHP-

What You See Is What You Get) Dreamweaver GoLive, , .


-, . , .
FTP- (File Transfer Protocol) .
- Telnet Vi Pico .
HTML.
, HTML , Dreamweaver, GoLive, FrontPage PageMill,
.
HTML,
. - HTML
- (Elizabeth Castro) Peachpit Press.
. ,
, , , Perl JavaScript .


,
, , . .
,
. :
<?php print ("Hello, World! " ) ; ?>
PHP- , ( 1). ,
. , ,
. (. 14).
1
.
1 <?php
2 print ("Hello, W o r l d ! " ) ;
3 ?>

,
.
(. 6).
HTML (. 7),
Netscape Navigator View > Page Source, Internet Explorer- > HTML.
, , . 7 , , . 6 , .
, .

, . PHP-

*>" * " S? ** >


, world!

. 6 .
,
Netscape Navigator, Internet Explorer ..
Macintosh, Windows, Linux

Web-

^-*'^WV^T^* '

'

' "', **1*^

**^7
. 7 Page Source View Netscape HTML Internet
Explorer, HTML,
.
Hello, World!

. .
, :
<HTMLxHEADxTITLE>First PHP Script
-</TITLEx/HEADxBODY>

, . ( .)
, ,
. , . - , ,
. (. ).
Web-,
. .
, ( HTML),
. , .
, .

Web-
, , www.DMCinsights.com/php.
.
. .

Web-,
. , , .

, ,
,
, . . ,
php@DMCinsights.com.


,
,
,
, .
!
.


,
HTML.
HTML- PHP- . -, PHP- ,php (, index.php). -, PHP- <? ?>
HTML.

HTML
1. SimpleText, WordPad .
2. File > New .
3. :
<HTMLxHEADxTITLE>First PHP Script</TITLEx/HEADxBODY>


.
4. <? .

5. Enter ?>.
6. </BODYx/HTML>.
7. File > Save As. Text Only ( ASCII).
8. .
9. first.php ( 1.1).
1.1 HTML- . .
, , PHP-. PHP- , HTML.
1.
2.
3.
4.
5.
6.

<HTML>
<HEAD>
<TITLE>First PHP Script</TITLE>
</HEAD>
<BODY>
<?PHP

'

7. ?>

8. </BODY>
9. </HTML>
, . .,
.phtml. .. , : file. , file.asp
ASP, a file.html HTML-.
, (<? ?>
<? ?>) ASP- (<% %>). , Macromedia
Dreamweaver, PHP-, ASP.


, PHP-,
- . , , .
phpinf ( ) .
Web- .

phpinfo
1. first.php.
2. PHP- (<? ?>) , Enter.
,

3. phpinf ( ) , - .
4. , First Test HTML ( 1.2).
5. test.php.
1.2 , HTML phpinf ( ) .
1. <HTML>
2. <HEAD> .

3. <TITLE>Test PHP Script</TITLE>


4. </HEAD>
5. <BODY>
6. <?PHP

7 . phpinf();
8. ?>

9. </BODY>
10. </HTML>

PHP- (,-). - . , .
.
- , print ( )
phpinf ( ) . . , , PHP-, ( , .) ,
, .
, . , PHP-; . .. ,

, .
, , PHPINFO ( ) . PHPinf () PHPINFO () . , . ,
HTML .
Phpinf () - . 9.
test.php. ' ,
, ( , GIF .) . test.php

1
.
, , , - .


HTML,
Web-, PHP- , . ,
.
,
FTP ( ). Web- FTP-. FTP, Fetch Macintosh WS_FTP Windows.

FTP
1. FTP-.
2. ,
, , (. 1.1).
3. HTML- ( www/ htdocs/).
4. (test.php) .
( , FTP ,
).
,
, test.php.

. 1.1 in .
, ,

1. .
2. , . (
http://www.DMCinsights.com/php.)
3. /test.php.
4. Enter.
(. 1.2).

phpinf ( )
, .

Sywrn

.1&(> #1 SMP Thu 312 06-28


5 Uf*Mwn:
*
.

Build Dt
Cenfigutt CMMMM4

. 1.2 phpinf () ;,
, ( .php) -

, , .
, BBEdit, FTP, .


, . HTML-. print ().


1. first.php .
2. PHP- , Enter.
3. print ("Hello, world!"); ( 1.3).
4. .
5. (. 1.3).

1.3 ^ print PHP-, Hello, world! . ,


HTML-.
1. <HTML>
2. <HEAD>

3. <TITLE>First PHP Script</TITLE>


4. </HEAD>
5. <BODY>
6. <?PHP

7. print ("Hello, world! ") ;


8. ?>
9. </BODY>
10. </HTML>

Hello, world! - , . , .
, echo () print f (). echo print, . print f () 13.
,
, print "Hello, world!";. , .
.
, ,
-
print ().
, .

. 1.3 , ( , )

HTML

HTML
, HTML, ,
Web- . , HTML
. HTML , HTML .

HTML
1. first.php .
2. Hello, world! 7,
print ("<BxCENTER>Hello, world! </CENTERx/B>") ;

3. ( 1.4) , (. 1.4).
1.4 print HTML- , .
1. <HTML>
2. <HEAD>

3. <TITLE>First PHP Script</TITLE>


4. </HEAD>
5. <BODY>
6. <?PHP
7. print ("<BxCENTER>Hello, world!</CENTERx/B>") ; .
8. ?> '
9. </BODY>
10. </HTML>

E*

. 1.4 . HTML
-
HTML ( , )

1
HTML-, (, <FONT COLOR=" # 0 0 0 0 0 0 ">),
, print () . (\). : print "<FONT
COLOR=\"#000000\">",-. , . , .


HTML
, HTML- , , (, ,
)
, , . , , .
. ,
, HTML-.
, , Web-. PHP-. , PHP- ( HTML). , .
.
PHP- ,
( ) .
. .
HTML ( 1.4, 1-5) , HTML-. ( 1.4, 7), HTML-.

PHP- ,

1. first.php .
2. Enter.
.
3. ( 8) \
( 1.5).

HTRfii.

4. ,
(. 1.5).
1.5 , . \, , HTML- (
HTML- <BR>, ).
1. <HTML>

2. <HEAD>
3. <TITLE>First PHP Script</TITLE>
4. </HEAD>
5. <BODY>
6. <?PHP
7.

8. print ("<BxCENTER>Hell6, world!</CENTERx/B>\n") ;

9.

10. ?>

11.
12.

</BODY>
</HTML>

\ HTML-.
, Enter.
HTML ,
(. 1.5).
HTML- (
- &nbsp,, Enter HTML - <BR>).
.
HTML-, .
, , View>-Source
View>-Page>-Source.

jfr.
HUe,, world'

. 1.5 , , \ -
HTML-, PHP- ( 7 9)

1
(. 1.6 1.7).
.
.
, HTML ,
. ,
, . , .

. 1.6 Web- - ,
. ,
\

. 1.7 \ , Hello, world! HTML-. HTML-


, -
, , . ,
, , .
.
, .

, / / #
. :
Print ( " H e l l o . " ) ; // .


1 . first.php .
2. 8 / / # ( 1.6).
3. ,
(. 1.8).
1.6 / / # , .
1 . <HTML>
<HEAD>
<TITLE>First PHP Script</TITLE>
</HEAD>
<BODY>
<?PHP

2.
3.
4.
5.
6.
7.
8.
9.
10.
11,
12.

// print ("<BxCENTER>Hello, world!</CENTERx/B>\n" ) ;

?>
</BODY>
</HTML>

, . , ! Hello, world!,
( / / #).
/* , */ ,
, ,
.

. 1.8 ,
. , Hello, world!


1. first.php .
2. # / / print ( ) .
3. print ( ) 8, PHP- (<?) 6 /*.
4. print ( ) 8 ( ), - (?>) 10 */
( 1.7).
5. ,
(. 1.9).
1.7
/ * * / , , , # / /
(. 1.8 1.9).
1 . <HTML>
<HEAD>
<TITLE>First PHP Script</TITLE>
</HEAD>
<BODY>
6. <?PHP
7. /*
8. print ( " <BxCENTER>Hello, world!</CENTERx/B\n"
9. */
10. ?>
11. </BODY>

2.
3.
4.
5.

12 . <HTML>

/* */
( ), , // # - .
-. . , JavaScript,
, // /**/.
Perl #.
I* ;. l>-ro.to .*/

. 1.9 ,
, - : / / # - , / * * / -
. (, , !)


,
HTML (<! -- >).
, HTML ( ).
.
(. 1.10),
, .
, BBEdit, (. 1.11). .

>

</<>

</.>

. 1.10 , (. 1.7), ,
PHP- . < ! > HTML-
,

. Ed adT.Jfcy .

u Cf U

-*-1,,

iS 'i j

<HTML>
<MEAD>
<TITLE>F1r3t PHP
</HEAD>
<BODY>
<?PHP
/"

print C'-'BxCENTR>Mello, vorld! </CENTERX/B>\n");

Jli.

* t

. 1.11
,
.
, , ,


HTML- Web-, .
: ,
print ( )
Web-.

Web- Web- . . , JavaScript, Java, Perl
.
.
. , , . , , 4-6
, .


- . ( , ), , Web-,
, .. ( , Web-,
print, .)
: ,
( ),

, , .
- , ,
, .
, ,
( . ).


: ($),
. (A-Z, a-z),
(_). ,
, .
.
.
, .
$variable $Variable - , .
,
( 2.1).
- . , $FirstName - , $FN.
2.1 , , - , .
1.
2.
3.
4.
5.
6.

<HTML>
<HEAD>
<TITLE>First PHP Script</TITLE>
</HEAD>
<BODY>
<?PHP

8.
9.
10.
11.

print ("Hello, world!")


?>
</BODY>
</HTML>

7. /* . */

,
. , $f irst_name - , $FirstName, ,
. , , , .

, ( . ), / , .
, .


: , .
: ( , ).
.
,
.
- ,
, .
, ,
, - , .

-
- . , . ( 1.0) .
, - . , 1 1/4 1.25.
:
1
1972
-1

:
1.0
19.72
-1.0

,
.
:
11/4
1972
02.23.72
.
. .
.
.
.
: (/). , .
, . ,
. - (
) ,
.

(string), ( , , ),


. ,
.
:
"Hello, world!"
"Hello,. $FirstName!"
"1 1/4"
"Hello/ world! How are you today?"
"02.23.72-"
1972"
,
, . 1972, 1972. .
:
Hello, world!
"I said, "How are you?""
, .
. ,
, , , .
, ?
1, print ()
HTML , . " I said, \ " How are you? \ " " , ,
. , , . ( ' ) , (\) ($).
:
. , 'Hello, $FirstName!'; Hello, $FirstName! , , Hello, Larry! (
$FirstName Larry).
(print "Hello, \$FirstName!",-),
, (Hello, $FirstName!).
1 , \.
, . , "\" , " \ " - , a " \ t " - .

6, , , .
,

. . , / . !
, , Perl . , Perl ,
. - - .


, . ?
(=). , , .
.
:
$ = 1;
$floating_number = 1.2;
$string = "Hello, World! ", ,
( , JavaScript):
$variable = 1;
$variable = "Greetings";
, , Greetings.
6.
( - , ,
). :
$number = (integer) 5;
$string = (string) "Hello, World!";
, . , , .


: -,
, -, , , , .
- ,
Web- (, Apache),


Web- (Unix Windows NT), .
.
. test.php (. 1) , (, 2.1).
: $HOSTNAME (
) $OSTYPE ( ).
Apache: $DOCUMENT_ROOT -
, $HTTP_USER_AGENT, , .
PHP - $PHP__SELF, . . 2.1 $PHP_SELF ,
test.php.
, ,
.
. , test.php (. 2.1),

.

Environmtnt

PwD
HOSTNAME
CONSOLE

MEVUVEL

HELL
HOSTTYPE
OSTYPE

ItftUwjmi

HOME

TERM

liltbt

PATH
RtWLEYEL

IWT_ViftSiON

. 2,1 test.php , ,

HTML- PHP

- HTML.
, , ..
HTML.
CGI- Perl
, . CGI- ( ,
, ) ' HTML-.
.
HTML- PHP-. , ,
, Web-, HTML-.


HTML- , , ,
.
.

HTML-
1. .
<HTMLxHEADxTITLE>HTML Form</TITLEx/HEAD><BODYx/BODY></HTML>


2. ( 3.1).
<FORM ACTION="HandleForm.php"> </FORM>.

<FORM> .
. ACTION , ( ) .
3.1 HTML-
<FORM> </FORM>. He . , ACTION.
1. <HTML>
2. <HEAD>

3. <TITLE>HTML Form</TITLE>
4.
5.
6.
7.
8.
9.

</HEAD>
<BODY>
<PORM ACTION = "HandlePorm.php">
</PORM>
</BODY>
</HTML>

3. form.html.
4. <FORM> Enter .
5. :
First Name <INPUT TYPE=TEXT NAME="FirstName" SIZE=20xBR>


. , (_). .
Last Name <INPUT TYPE=TEXT NAME="LastName" SI2E=40xBR>

<BR>, .
E-mail Address <INPUT TYPE=TEXT NAME="Email" SIZE=60xBR>
Comments <TEXTAREA NAME ="Comments" ROWS=5 COLS=40x/TEXTAREAxBR>

, . ,
. ,
, .
6. .
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">

SUBMIT - . Go! Enter.

3 HTML-

*'
Pint Name |
Last Name j
E-mal Address
Comments

. 3.1 ,
. Submit

7. ( 3.2), (. 3.1). , PHP-, ,


.
3.2
, , <FORM>,
. .
1. <HTML>
2. <HEAD>
3. <TITLE>HTML Fbrm</TITLE>
4. </HEAD>
5. <BODY>
6. <FORM ACTION="HandleForm.php">
'

7. First Name <INPDT TYPE=TEXT NAME="FirstNaae" SIZE=20xBR>


8. Last Name <INPUT TYPE=TEXT NAME="LastName" SIZE=40xBR>
9. E-mail Address <INPTJT TYPE=TEXT NAME="Email" SIZE=60xBR>
10. Comments <TEXTAREA NAME= "Comments" ROWS=5 COLS=40x/TEXTAREAxBR>
11. <INPUT TYPE=SOBMIT NAME="SUBMIT" VALUE="Submit!">
12. </FORM>
13. </BODY>
14. </HTML>
, HTML-.
HTML-, Dreamweaver GoLive,
.
HTML (.html), HTML-. .php , . , -
, PHP- <?php ?>, HTML

Get Post
, , , Reset.
:
<INPUT TYPE=RESET NAME=RESET VALUE="RESET">

, ACTION , . ,
HandleForm.php form.html.

Get Post
, - <FORM>, METHOD. ,
.
, .
METHOD : GET POST. ,
HTML
, . ,
, ,
.
GET POST , . GET
URL. POST , . , GET, URL :
http://www.DMCinsights.com/php/HandleForm.php?FirstName=Larry&LasName=Ullman.
POST : http://www.DMCinsights.com/php/HandleForm.php.
:
> GET ;
> GET , .
, , , ;
> , GET,
, POST - .
POST. , GET
Web-,
(. ). , ,

3 HTML- PHP

, .


1. form.html .
2. <FORM> METHOD=POST ( 6, 3.3).
3.3 , - GET POST - . , . , , , , .
1. <HTML>
2. <HEAD>
3. <TITLE:>HTML Form</TITLE>
4.
</HEAD>
5. <BODY>
6. <FORM ACTION-"HandleForm.php" METHODPOST>
7. First Name <INPUT TYPE=TEXT NAME="FirstName" SIZE=20xBR>
8. Last Name <INPUT TYPE=TEXT NAME="LastName" SIZE=40xBR>
9. E-mail Address <INPUT TYPE=TEXT NAME="Email" SIZE=60xBR>
10. Comments <TEXTAREA NAME="Comments" ROWS=S COLS=40x/TEXTAREAxBR>
11. <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
12. </FORM>
13. </BODY>
14. </HTML>

3. .
4. , (. 3.2).

'4 * ?
. 3.2 HTML- ,
, .
,


. HandleForm.php,
, form.html. .

HandleForm.php
1. .
<HTMLxHEADxTITLE>Form Results</TITLEx/HEADxBODY>
<?php /* ,
- " f o r m . h t m l " . */?></BODYx/HTML>.

2. PHP-.
. form.html , ( ACTION), ,
. ,
PHP-. :
print
print
print
print

("Your
("Your
("Your
("This

first name is $FirstName.<BR>\n");


last name is $LastName.<BR>\n");
E-mail address is $Email.<BR>\n");
is what you had to say:<BR>\n $Comments<BR>\n");

3. HandleForm.php.
4. ( 3.4) ,
form.html.
5. Web- (. 3.3 3.4).
3.4 NAME = "Name" HTML- $, , ,
.
HTML, TEXT, TEXTAREA SELECT, , HTML. : CGI- .
1.
2.
3.
4.
5.

<HTML>
<HEAD>
<TITLE>Form Results</TITLEx/HEAD>
<BODY>
<?php

7.
8.
9.
10.

print
print
print
print

6. /* ,
"form.html".*/
("Your first ie $FirstHame.<BR>\n");
("Your last name is $LaetName.<BR>\n");
("Your E-inail address is $Email.<BR>\n") ;
("This is what you had to say:<BR>\n $CommentB<BR>\n");

11. ?>
12. </BODY>
13. </HTML>

3 HTML-

First Name I *"


Last Name pu
E-mail Address
JphpeDHCinsights.cO!
Comments I eun tfestino the HTHL or. Values I
: sent
lorip.php'

jjjj

. 3.3 , HTML-,
HandleForm.php
(. . 3.4)

Si*. S

<*!*|*

Your first name is Ljffry.


Your last name is UUman
Your E-mail address is php@DMCinsights.com.
Hus is what you had to say:
I am testing the HTML form Values I enter into the form here wifl be sent to, and
processed by, Handleform php!

kKtag.auvu.-t
, 3.4 print. Web-.
, ,

. , ,
HTML- -. PHP-
, $FirstName , First Name ( HTML, $ ). , GCI
.
HTML-
,
. , I thought


" f o r m . h t m l " was too simple!, $Comments I thought
\ " form. html \ " was too simple!, (. 3.5).
, HIDDEN HTML-. , <INPUT
= HIDDEN NAME = "ThisPage" VALUE = " form.html ">,
FORM, $ThisPage
" f o r m . h t m l " . , print ("<INPUT
TYPE=HIDDENNAME=\ "FirstNameX " VALUE=\ " $FirstName\ " > " ) ; ,
$FirstName,
.
, , . ,
HandleForm.php.

Your first name is Larry.


Your last name is Ullman.
Your E-mail address is p
Ibis is what you had to say:
I thought "form html" WAS too simple!

"K3StSS
. 3.5 , HTML.


HTML-, . ,
, ,
.
, , print .
PHP-, .

3 HTML-

-,

1. .
<HTMLxHEADxTITLE>Using Variables</TITLEx/HEADxBODYx?php
/* print. */
, .
print ("<H2xCENTERxB>Hello, $FirstName.</Bx/CENTERx/H2xBR>\n") ;
/*
print. */
?> </BODYx/HTML>
2. ( 3.5) hetlo.php
.
3.5 , Hello, World! Hello, Larry!, , - , ,
.
1.
2.
3.
4.
5.
6.
7.
8.-

<HTML>
<HEAD>
<TITLE>Using Variables</TITLEx/HEAD>
<BODY>
<?php
/* . print. */
print ("<H2xCENTER><B>Hello, $FirstName.</Bx/CENTERx/H2xBR>\n") ;
/*
print. */

9. ?>

10. </BODY>
11. </HTML>
,
"Hello, . " , $FirstName .
, . - , GET .

HTML-
1. hello.php Web-, URL ( http://www.DMCinsights.com/
php/hello.php (. 3.6)).
2. URL ?FirstName = Larry ( ,
, ). ( ),
URL ( GET HTML-), www.url.com/script.php?variable=value.
3. URL (.3.7).

, , .
" ?",
. , FirstName
(, f irstname - ).
- .

Hello,.

. 3.6 $FirstName ,

Hello, Larry.

"
. 3.7 $FirstName
Larry , ,


1. hello.php .
2. print $FirstName =" Jude" ,( 3.6).
3.6 $FirstName = "Jude"; "Jude" "FirstName" .
1.
2.
3.
4.

<HTML>
<HEAD>
<TITLE>Using Variables</TITLEx/HEAD>
<BODY>

3 HTML-

<?php
$FiretName -, "Jude";

/* print. */
print ("<H2xCENTERxB>Hello, $FirstName</Bx/CENTERx/H2xBR>\n") ;
/*
print.
10. ?>
11. </BODY>
12. </HTML>
3. ,
(. 3.8).
4. URL,
(http://www.DMCinsights.com/
php/hello.php?FirstName=Larry^ - . 3.9.

Hello, Jude.

. 3.8 , Jude $FirstName,


print : print ("<H2xCENTER>
<>Hello, Jude.</Bx/CENTERx/H2xBR>\n") ;.Bce

Hello, Jude.

*m*bf,~,,^.w

. 3.9 , "Jude" $FirstName,


, URL,
Jude

, , :
hello .php. , - !

. , .
, URL,
( hello.php). , Web- , . , Web-
, < HREF = "hello.php?FirstName=Larry">hello.php</A>.
GET , , variable=value (,
FirstName=Larry) (&). URL
hello.php?FirstName=Larry&LastName=Ullman.
, URL,
(+). 5 , URL.
- -
,

. 11 ,

, .

, . , - . .

>

, ,
, :
, , .
PHP-, .
shopping cart ( ).


1. ( 4.1).
<HTMLxHEADxTITLE>Using Numbers</TITLEx/HEADxBODYx?php?>
-</BODYx/HTML>

2. PHP- :
$Cost = 2 0 0 0 . 0 0 ; $ = 0 . 0 6 ;

, $2,000.00. , , . (6%).
0.06, . .

, ,
$TotalCost = $Cost * $Quantity;
(*). $Quantity ,
shopping cart Web-. , 3, ,
URL.
4.1. ,
, . HTML, , (
) .
1
2

<HTML>
<HEAD>

<TITLE>Using Nurnbers</TITLE>

4
5
6

</HEAD>
<BODY>
<?php

/* $Quantity .
$Discount . */

$Cost = 2000.00;

$ = 0.06;

10
11
12
13
14

$TotalCoet = $Cost * $Quantity;


$ = $ + 1; // ($) 1.06.
$TotalCost = $TotalCost - $Diecount;
$TotalCost = $TotalCost * $Tax;
$Payments = $TotalCost /12;

15 .// .
16 print ("You requested to purchase $Quantity widget(s) at \$$Cost
each.\n<P>");
17 print ("The total with tax, minus your \$$Discount, comes to $");
18 print (" \n<P>You may purchase the widget(s) in 12 monthly
installments of \$$Payments each.\n<P>");
19 ?>
20 </BODY>
21 </HTML>
$Tax = $Tax + 1; // ($) 1.06.

(+). ,
, , . ( , , -
, ). :
- .

$TotalCost = $TotalCost - $Discount;


, (-), , , URL .
$TotalCost = $TotalCost * $Tax;

( ), , . $TotalCost ,
$TotalCost $.
$Payments = $TotalCost / 1 2 ;
, ,
. ,
, 12 .
// .
.
print ( " Y o u requested to purchase $Quantity w i d g e t ( s ) at \$$Cost
each.\n<P>");
print ("The total with tax, minus your \$$Discount, comes to $ " ) ;
print ( " \n<P>You may purchase the w i d g e t ( s ) in 12 monthly installments
of \$$Payments e a c h . \ n < P > " ) ;
3. numbers.php .
4. Web-,
(. 4.1).
, , . 4.2, , .
, , (. . 4.1). .
__
] ^"

. 4.1 .
URL
,
, . 4.2


8
.*'&MCiri:igi-it

' Whit 1 Rehtel

You requested to purchase widget(s) at $2000 each.


The total wtfhtax, minus your $, tollies tc SO
You may purchase the widget(s) in 12 monthly instaljmentE of $0 each.

-P SL
. 4.2

, . , print () , $TotalCost . , (, $TotalWithTax $TotalLessDiscount).
, $2000.00. - , . -
. , .
$$Variable, $$ ,
.


, .
-
$521.16666666667, . print f ( ) , , .
print f ( ) ,
. , ( 1.02) :
print f ( " % 0 1 . - 2 f " , $Amount);

" % 0 1 . 2 f " $Amount


,
- . print f ( )
, .

printf
1. numbers.php .
2. 17 :
print ("The total with tax, minus your \$$Discount, comes to $");
printf ( " % 0 1 . 2 f " , $TotalCost};
printf ( )
print ( ) , .
3. 18 :
print ( " . \n<P>You may purchase the widget(s) in 12 monthly
installments of $ " ) ;
printf ( " % 0 1 . 2 f " , $Payments);
print (" each.\n<P>");
, 17. , .
4. ( 4.2),
(. 4.3).
4.2 print ( ) , .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

<HTML>
<HEAD>
<TITLE>Using Numbers</TITLE>
</HEAD>
<BODY>
<?php
/* $Quantity .
.$Discount . */
$Cost = 2000.00;
$ = 0.05;
$TotalCost = $Cost * $Quantity;
$ = $ + 1; // ($) 1.06.
$TotalCost = $TotalCost - $Discount;
$TotalCost = $TotalCost * $Tax;
$Payments = $TotalCost / 12;
// .

16 print ("You requested to purchase $Quantity widget(s) at \$$Cost


each.\n<P>");
17 print ("The total with tax, minus your \$$Discount, comes to $");
18 printf ("%01.2f", $TotalCost);
19 print (" \n<P>You may purchase the widget(s) in 12 monthly
installments of $");
20 printf ("%01.2f", $Payments);
21 print (" each.\n<P>");
22 ?>
23 </BODY>
24 </HTML>


sprint f ( ) print f ( ) . ,
, sprint f () , :
$Amount = sprintf ( " % 0 1 . 2 f " , $Amount);

fc * f" 5?

& tocaiiore|http /t**tw DMCinsights com/php/numbs phpTQuarrt*ir3fcOtscoufH.lCO 00

You requested to purchase 3 widget(s) at 2000 each


111! total wift las, minus your $100 00, comes to 16254 00
You may purchase the widget(s) in 12 montMy instalments of $521 17each,

C3

. 4.3 print f ()
(.4.1)


, Perl , , , $ = $ + 1,-. () (),
++ -- .


1. numbers.php_B .
2. 10 4.2 :
$++;

3. ( 4.3), (. 4.4).
4.3. (++)
, - .
1
2
3
4
5
6
7

<HTML>
<HEAD>
<TITLE>Using Numbers</TITLE>
</HEAD>
<BODY>
<?php
/* $Quantity .
$Discount . */

4
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24

$Cost - 2000.00; '


$ = 0.05;
$TotalCost = $Cost * $Quantity;
$++; // ($) 1.06.
$TotalCost = $TotalCost - $Discount;
$TotalCost = $TotalCost * $Tax;
$Payments = $TotalCost / 12;
// .
print ("You requested to purchase $Quantity widget(s) at \$$Cost
each.\n<P>");
print ("The total with tax, minus your \$$Discount, comes to $");
printf ("%01.2f", $TotalCost);
print (".\n<P>You may purchase the widget(s) in 12 monthly
installments of $");
printf ("%01.2f", $Payments);
print (" each.\n<P>");
?>
</BODY>
</HTML>

I* "> 6

locatiwx jhttp

You requested to purchase 3 widget(s) at $2000 each.


The total with tax, rrunus your $100 00, comes to $6254.00
You may purchase the widget(s) in 12 monthly installments of J521.17 each

. 4.4 ,
- ( 4.2 4.3)
, $ =
$ + 1; $++, , , .
6 , .

( ): $Number.



- .
, :
$Number = 1 0 - 4 / 2 ;


3 ( , ) 8 ( , )? - 8,
.
( ).
, :
$Number = ( 1 0 - 4 ) / 2;
$Number = 10 - (4 / 2 ) ;

3, - 8. , .
, ,
.
4.4 ,
, . , .
1
2
3
4
5
6
7

<HTML>
<HEAD>
<TITLE>Using Numbers</TITLE>
</HEAD>
<BODY>
<?php
/* $Quantity .
$Discount . */
8
$Cost = 2000.00;
9
$ = 0.06;
10 $++; // ($) 1.06.
11 $TotalCost = (($Cost * $Quantity) - $Discount) * $Tax;

12 $Payments = $TotalCost /12;


13 // .
14 print ("You requested to purchase $Quantity widget(s)at \$$Cost
each. \rxP>") ;
15 . print ("The total with tax, minus your \$$Discount, comes to $");
16 printf ("%01.2f", $TotalCost);
17 print (" \n<P>You may purchase the widget(s) in 12 monthly
installments of $");
18 printf ("%01.2f", $Payments);
19 print (" each.\n<P>");
20 ?>
21 </BODY>
22 </HTML>


1. numbers.php .
2. 13 ( 4.4):
STotalCost =

( ( $ C o s t * $Quantity)

-. $Discount)

* $Tax;

, . - , .
3. 10 12. ,
.
4. ,
(. 4.5).
(
).

Bj

You requested to purchase 3 widget(s) at $2000 each.


The total with tax, minus your $100.00, comes to $6254,00.
You may purchase the widget(s)m 12 monthly installments of $521 17 each.

. 4.5 , .
,



.
numbers.php,
.
, , - round (}. ,
: 0,5 , 0,5 -
. , , ( , 2 2). :
$Number = r o u n d ( 2 3 . 3 0 9 ) ; // $Number 23.
SNumber = round(23.51); // $Number 24.

4.0 ,
:
$Number = r o u n d ( 2 3 . 5 1 , 1); // $Number 2 3 . 5 .

round ( ) . , ceil ( ) , , , floor ( ) , - .


, , abs ( ) .
:
$Number = a b s ( - 2 3 ) ; // $Number 23.
$Number = a b s ( 2 3 ) ; // $Number 23.

-
.
, , - srand ()
rand ( ) . , - , rand ( ) . srand ( ) rand ( ) . :
srand ((double) microtimeO * 1000000);
$RandomNumber = rand();

,
, , 4.0 ,
.
rand ( ) ,
, .
$RandomNumber = rand ( 0 , 10);

numbers.php
- abs ( ) round ( ) - .


1. numbers.php .
2. 9 ( 4.5) :
$Quantity = abs($Quantity);
$Discount = abs($Discount);

, , ,
abs ( ) .
$ Quantity, . ,
, abs ( ) $Payments.
4.5 round ( ) abs
.

4 v

, round ( ) , - abs ( ) .
1
2
3
4
5
6
7
8
9
10
11
12
13

<HTML>
<HEAD>
<TITLE>Using Numbers</TITLE>
</HEAD>
<BODY>
<?php .
/* $Quantity .
$Discount . */
$Cost = 2000.00;
$ =0.06;
$Quantity = abs($Quantity) ;
$Discount = aba($Discount) ;
'$Tax++; // ($) 1.06.
$TotalCost = (($Cost * $Quantity) - $Discount) * $Tax;

14 $Payments = round ($TotalCost, 2) / 12;


15 // .
16 print ("You requested to purchase $Quantity widget (s) at \$$Cost
each. \n<P>" ) ;

17 print ("The total with tax, minus your \$$Discount, comes to $");

18 printf ("%01.2f", $TotalCost);

19 print (".\n<P>You may purchase the widget (s) in 12 monthly


installments of $");
20 printf ("%01.2f", $Payments);
21 print (" each. \n<P>") ;
22 ?>
23 </BODY>
24 </HTML>

3. 14, $ Payments,
:
SPayments = round ($TotalCost, 2) / 12;
, ( $TotalCost ).
4. , ,
(. 4.6).
fc.i* s -** *

U^to)hp//.DMCre^ipx^p^/nijnbetiphp^]uanl<>.3)iicoijnl.1onOO

jj fj'WM'lBafalKt

You requested to purchase 3 widget(s) at $2000 each.


The total with tax, minus your $100, comes to 562.
You may purchase the wi<!get(s) in 12 monthly mstajlmcnb of $521 17

. 4.6 round () abs ()


,

2, -
(strings), ,
.
, , , ,
( ). - .
, , , HTML- PHP-.
form.html HandleForm.php
3.

, .
: ,
, . .


- , - HTML- - . , . .

. , Web-, , , , cookie-

. ,
, .
trim ( )
( ). t r i m ( ) :
$String = " extra space b e f o r e and a f t e r t e x t " ;
SString = t r i m ( $ S t r i n g ) ;
// $String "extra space before and after t e x t " .

HandleForm.php 3 .


1 . HandleForm.php ( 5.1).
5.1 HandleForm.php ,

.
1
2
3
4
5
6'

<HTML>
<HEAD>
<TITLE>Form Results</TITLEx/HEAD>
<BODY>
<?php
/* - ,
"form.html". */
7
print ("Your first name is $FirstName. <BR>\n" ) ;
8
print ("Your last name is $LastName.<BR>\n" ) ;
print ("Your E-mail address is $Email .<BR>\n" ) ;
9
10 print ( " T h i s is what you had to say:<BR>\n $Comments<BR>\n" )
11
12

?>

</BODY>
13 </HTML>
fe Vv So

Tour Erst name is Larry


Your last name is UHman
Your E-mail address is
Tnis is what you had to say:
Comments with extra spaces

'insights com

-P

. 5.1 , . . . 5.2, HTML,

2. 5.1 6 () :
SFirstName = t r i m ( $ F i r s t N a m e ) ;

$FirstName, "Your f i r s t name is _Larry_", (. 5.1-5.2).


3. $ L a s t N a m e = t r i m ( $ L a s t N a m e ) ;
$Email = t r i m ( $ E m a i l ) ;

,
.
$CommentS = t r i m ( $ C o m m e n t s ) ;

t r i m ( ) , : ( $FirstName $ Email),
HTML .
4. ( 5.2) HandleForm.php, (. 5.3-5.5).
5.2. , , .
1

<HTML>

<HEAD>

3
4
5
6

<TITLE>Form Results/Using Strings</TITLEx/HEAD>


.<BODY>
<?php
/* ,
"form.html." */
$FirstName = trim($FirstName);
$LastName = trim($LastName);
$Email = trim($Email);
$Comments = trim($Comments);
print "Your first name is $FirstName.<BR>\n";
print "Your last name is $LastName.<BR>\n";
print "Your E-mail address is $Email.<BR>\n";
print "This is what you had to say:<BR>\n $Comments<BR>\n";
?>
</BODY>

' '
</HTML>

7
8
9
10
11
12
13
14
15
16
17

Itrirnf) rtrim() . , trim ( ) :


$String = r t r i m ( $ S t r i n g ) ;
$String = l t r i m ( $ S t r i n g ) ;

<H1ML>
<
Resulca</TITUE>
Your last name is UUmen .<BR>
Your E-mail address Is phpGDKClnsights.com.<BR>
Tftis 1 whet you had to 8a?:<8R>
,

. 5.2 HTML
, . , HTML

te 6 fio jjelp
First Name

Lacry

Last Name

Ullnan

E-rnail Add
J

Comments
_SubrnrliJ

tfj^r"

Document Done '

"

;jj.

-W ^^* |

\^.

. 5.3 . ,

fid

ommunica<

Yoiir fa ft name is Larry.


Your last name is Ullman.
Your E-mail address is php@DMCinsights com.
This is what you had to say:
Comments with extra spaces

a- a

. 5.4
, . ,

<HEAJ
<TITI.E>Foina ResulCs</fITLE>
Your last name is Ullman.<BR>
This is ht you had

y:<BR>
.<BH>

</BODY>

. 5.5 HTML-, . 5.3, , . 5.2,


trirnf}

(, )
, , , -
, . . ( . ) , :
$NewString = $aString . $bString;

.
, :
$NewStrir>g = $aString . SbString . $cNumber;
, , ,
,
. ScTIumber
$NewString.
HandkTonn.php , .
, . ,
. .


1. Han.dleForm.php ( 5.2).
2. 11 :
, ( 11 12. 5.2),
no:-rvoM v .

S
t r i m ( ) ,
. ,
.
3. 12 :
print -("Your name is $ N a m e . < B R > \ n " ) ;

4. ( 5.3), (. 5.6 5.7).


5.3. -
. .
1
2
3
4

<HTML>
<HEAD>
<TITLE>Form Results/Using Strings</TITLEx/HEAD>
<BODY>

5
6

<?php
/* .,
"form.html". */

,$FirstName = trim($FirstName);

8 $LastName = trim(SLastName);
9 $Email = trim($Email);
10 SComments = trim($Comments);
11 $Name = $FirstName . " " . $LaetName;

12 print ("Your name is $Name.<BR>\n");


13 print ("Your E-mail address is SEmail.<BR>\n");

14 print ("This is what you had to say:<BR>\n $Cominents<BR>\n") ;


15 ?>
16 </BODY>
17 </HTML>

Edit * Conmuncetor

'

'

First Name Larry


Last Name Ullman
E-mail Address jphpgDJtClnsiOhts.ru

Comments
Sub mill . |

. 5.6 HTML- ,
HandleForm .php
, (. . 5.7)

$Name = "$FirstName $LastName";. , , .

fe *
Your name is Larry
Your E-mail address is php@DMCinsights ru.
This is what you had to say.
Here is an example of concatenation!

. 5.7
-

,
( " ).
$FirstName = $FirstName . " " . SLastName;,
. -,
$FirstName . -, FirstName
. , .


3 , GET , URL- .
, . 4.
, ?
urlencode ( ) . , (encode) , URL. , urlencode ()
( + ) , , URL . :
$String = urlencode($String);

$Name , .

urlencode
1. HandleForm.php (.
5.3).

2. 14 :
$Name = urlencode($Name);
print ("<P>Click <A HREF=\"welcome.php?Name=$Name\"> here</A> to see
your personalized g r e e t i n g ! \ n " ) ;

3. welcome.php.
, , 5.5.
$Name HandleForm.php. , ,
, ( form.html HandleForm.php
welcome.php).
4. ( 5.4), (. 5.8-5.14).
5.4 : -, HREF - HTML, ,
print ( ) , -, SName
(. . 5.10).
1

<HTML>

2 <HEAD>
3 <TITLE>Form Results/Using Strings</TITLEx/HEAD>
4 <BODY>
5 <?php
6 /* ,
"form.html". */
7 $FirstName = trim($FirstName);
8 $LastName = trim($LastName);
9 $Email = trim($Email);
10 $Comments = trimf$Comments);
11 $Name = $FirstName " " . $LastName;
12 print ("Your name is $Name.<BR>\n");
13 print ("Your E-mail address is $Email.<BR>\n");
14 print ("This is what you had to say:<BR>\n $Comments<BR>\n");
15 $Name = urlencode($Name);
16 print ("<P>Click <A HREF=\"welcome.php?Name=$Name\"> here</A> to see
your personalized greeting!\n");
17 ?>
18 </BODY>
19 </HTML>

5.5 Hello, world! (. 1), welcome.php ,


(. 5.11). .
1 <HTML>
2 <HEAD>
3 <TITLE>Welcome!</TITLEx/HEAD>
4 <BODY>
5 <?php
6 print ("<BxCENTER>Hello, $Name . </CENTERx/B>\n") ;
7 ?>
8
</BODY>
9 </HTML>

fe

View o

Your name is Larry UUman


Your E-mail address is php@DMCinsiglits.ru.
This is what you had to say
LetVs encode our name and pass it to a TJRL--a very handy technique to know1
Click hrre to see your personalized greeting!

. 5.8 HREF,

<TITLE>rorin Resultg/Usi&g Strings</TITLE>


^
'
<BOY>
Your name is Leer? Ullroan.<BR>
Your E-maii etctdress is phpBDRCin9lghta.ru.<Bll>
' This la bat you had s*y;<BR>
Let's encode out name end p*ss it to a URLa very-handy technique to')cnovKBIt>

. 5.9 HTML-, .
.
url encode ( ) , ,
. 5.12

* jo
Hello, LwivUttman

a1 13
. 5.10 PHP- , PHP-.

S * ctpoic

*
Your name is Larry Tlllman.
Tour E-mail address is php@DMCinsights.ru.
Tbs is what you had to say.
What happens if the name is not encoded?
Click hire to see your personalized greeting!

. 5.11 , , . HTML (. 5.12) welcome, php (. 5.13)

<.>
< ,

<TITLE>Far Resulcs/Osino; String9</tITLE>


<>7>
Tour name IS Larry- 01iasan,<BR> ,
Tour E-mail address 13 php9DNCin3iabt9.cu.<BR>
.This is hac you ^ say:<BH>
JThat happens it the ane is not eacoded?<Bfl>

. 5.12 ,
. URL

Hdlo, Larry

. 5.13 PHP- , ,

n Results/Using StringsK/TITLE>

Tour E-mail address is phpeDHCinaights.cu.<BR>


This is what you had to say:<BR>
Let's see how urlencodet) bandies apostrophes.

. 5.14 ,
urlencode ( ) , - . ASCII- - %27
urldecode ( ) , urlencode ( ) :
URL
.'
, , , URL .
urlencode ( ) , .
11 ,
napcmyurlencode ( ) - addslashes () stripslashes ( ) . , ( , ). , .
:
$Data = a d d s l a s h e s ( $ D a t a ) ;
$Data = s t r i p s l a s h e s ( $ D a t a ) ;

urlencode ( ) , . .


,
, . - ,
, , , . ,
.
, ,
.

, , .
. Web-. -, ,
. -, ,

PHP- . , , .
.
. .
- crypt (.) - , .
,
.
.
, Web- . , , , . :
$Data = c r y p t ( $ D a t a ) ;

, , - encrypt ( ) decrypt () ( ,
crypt ( ) encrypt ( ) - ).
PHP- . , .
, . , encrypt ( ) decrypt ( )
. crypt ( ) . ,
.

crypt
1. HandleForm.php ( 5.4).
2. 15 16, welcome.php urlencode ( ) , :
SCryptName = crypt($Name);
print ( " < P > T h i s is the c r y p t { ) version of your name: $ C r y n t N a m e \ n " ! ;

URL-
, .

3. ( 5.6), (. 5.15).
5.6 crypt ( ) . , , .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

<HTML>
<HEAD>
<TITLE>Form Results/Using Strings</TITLEx/HEAD>
<BODY>
<?php
/* ,
"form.html". */
$FirstName = trimf$FirstName);
$LastName = trim($LastName). ;
$Email = trim($Email);
$Comments = trim($Comments);
$Name = $FirstName . " " . $LastName;
print ("Your name is $Name.<BR>\n");
print ("Your E-mail address is $Email.<BR>\n");
print ("This is what you had to say:<BR>\n $Comments<BR>\n");
$CryptName = crypt($Name);
print ("<P>This is the crypt() version of your name: $CryptName\n");
?>
</BODY>
</HTML>
crypt ( ) md5 ( ) ,
. md5 ( ) , encrypt ( ) decrypt ( ) .
, ,
. ,
(. 5.16). .
, , ( ) , , . 5.16.

Your najne is Lany Ul'man.


Your E-majl address is php@DMCinsights com
This is what you had to say
Encryption in action1
This is the cryptQ version of your name. g9bVslb78ZgSM

. 5.15 crypt ( ) 12- ,

Your name is Larry UUman


Your -matl address is php@DMCinsights.com.
TTiis is what you had to say:
Encryption in action!
Fatal error: Caiito undefined function: encryptQ in ,-php.'HaiuS?Form php on line 15

. 5.16 HandleForm.php, encrypt ( ) ,


. ,
. . ,
URL.


,
. . , . , .
strtok ( ) , ,
( ). , ,
, :
$FirstName = strtok($Name, " " ) ;

$Name - ,
. $Name
. ,
, :
$LastName = strtok($Name, " , " ) ;

, ,
.
- ,
. , , - . ,
, .


"Larry" :
L 0, - 1, - 2, - 3, - 4. " Larry" ,
0 4. ,
substr ( ) :
$SubString = substr(SString,0,10);

-, ( $String), . -,
( , ,
). , (10). , 10, .
s t r l e n f ) .
, :
$StringLength = strlen(SString);
, ,
$StringLength-l!
substr ( ) , strlen ( ) md5 ( )
. , , , .
, . ,
. , .


1. PHP- :
<HTMLxHEADxTITLE>Password Generator</TITLEx/HEADxBODYx?php
$String = "This is the text which will be encrypted so that we may
create random and move secure passwords!";

.
. , .
$Length = 8;
, . 32 , , md5 ( ) .
SString = md5(SString);

md5 ( ) crypt ( ) , 32 . md5 ( ) , .

S
$StringLength = s t r l e n ( $ S t r i n g ) ;

, .
strlen ( ) ,
. , md5 ( )
32 ,
strlen ( ) . , (, encrypt ( ) md5 ( ) ) , .
srand ((double) microtimeO * 1000000);
$Begin = r a n d ( 0 , ( $ S t r i n g L e n g t h - $ L e n g t h - l ) ) ;

s u b s t r f ) . ' rand () ( 0) . srand ( ) , rand ( ) .


. : 32 , - , s u b s t r ( )
24- , , 0,
23.
, rand () .
- substr ( )
, .
$Password = substr($String, $Begin, $Length);

, $Password , $string, $Begin


$Length .
print ("Your recommended password is:<P><BIG>$Password</BIG>\n");
.
2. :
?></BODYx/HTML>

3. passwords.php ( 5.7), (. 5.17 5.18).


5.7 v passwords.php ,
. 16 !
1
2
3
4
5
6

<HTML>
<HEAD>
<TITLE>Password Generator</TITLEx/HEAD>
<BODY>
<?php
$String = "This is the text which will be encrypted so that we may
create random and secure passwords!";


7
8
9
1011
12
13
14
15
16

$Length = 8 ; // , .
32 - .
$String = md5($String);
$StringLength = strlen($String);
srand ((double) microtimeO * 1000000);
$Begin = rand(0,($StringLength-$Length-l)); //
.
$Password = substr($String, $Begin, $Length);
print ("Your recommended password is:<PxBIG>$Password</BIG>\n");
?>
</BODY>
</HTML>
Be in So
Your recommended password is
4SbS5d07

,0oeurmnl

. 5.17 passwords.php

Ed $<iw fio *
Your recommended password is.
54885<1

,.

fa .

. 5.18 . ( md5 ( )
32 , ,
.)
$Length GET , ?Length=8 URL ( , ).
: YYYY-MM-DD.
, ,
substr ():

5
$Year = substr($Date,0,4);
$Month = substr($Date,5,2);
$Day = substr($Date,8,2);
strlen(). ,
$ pas-sword = strlen ($Password);, ,
, $ Pas sword.


( , 7), - : , , . , . , ,
.
- .
. Web- . ,
!, - ! - if switch. .
-
. .
, . (. 7). - while ( do...while) for.

if
- i f
( if-then, then ). :
if (condition) {
statement(s) ;

6 v

.
.
, ,
.. ( ) .
, .
i f , ,
.
, , , ,
.
, , (true) (false). , , . .
- ( 4) , . ,
Web-.

if
1. numbers.php ( 6.1) .
6.1 numbers.php , , $Quantity $Discount . , .
1
2

<HTML>
<HEAD>

4
5
6

</HEAD>
<BODY>
<?php

/* $Quantity .
$Discount . */

$Cost -= 2000.00;

9
10
11
12

$ =0.06;
$Quantity = abs($Quantity);
$Discount = abs($Discount);
$Tax++; // ($) 1.06.

<TITLE>Using Numbers</TITLE>

13 $TotalCost = (($Cost * $Quantity) - $Discount) * $Tax;

14 SPayments = round ($TotalCost, 2) / 12;


15 // .
16 print ("You requested to purchase $Quantity widget(s) at \$$Cost
each.\n<P>");

if
17 print ("The total with tax, minus your \$$Discount,' comes to $"J;
18 printf ("%01.2f", $TotalCost);

19 print (".\n<P>You may purchase the widget(s) in 12 monthly


installments of $");
20 printf ("%01.2f", $Payments);

21 print (" each.\n<P>");


22 ?>
23 </BODY>
24 </HTML>

2. ( 3) :
<TITLE>Conditionals</TITLE>

3. 10-23 , if.
if ($Quantity) {
$Quantity = abs($Quantity);
$DiscOunt = abs($Discount);
$Tax++; // $Tax 1.06.
$TotalCost = $Cost * $Quantity) - $Discount) * $Tax;
$Payments = round ($TotalCost, 2) / 1 2 ;
// .
print ( " Y o u requested to purchase $Quantity widget(s) at\$$Cost
each.\n<P>");
print ("The total with tax, minus your \$$Discount, comes to $ " ) ;
printf ( " % 0 1 . 2 f " , $TotalCost);
print (".\n<P>You may purchase the widget(s) in 12 monthly
installments of $ " ) ;
printf ( " % 0 1 . 2 f " , $Payments);
print ~(" each.\n<P>") ;
PHP (
$Quantity) $Quantity , , ,....
, ,
$Quantity .
4. ( 6.2), $ Quantity
(. 6.1 6.2 ).
6.2 i f ,
.
: $Quantity.
1
2
3

<HTML>
<HEAD>
<TITLE>Condltionals</TITLE>


</HEAD>
<BODY>
<?php

/* $Quantity .
$Discount . */

$Cost = 2000.00;
$ =0.06;
9
10 it ($Quantity) {
$Quantity'= abs($Quantity);
11
$Discount = abs($Discount);
12
$Tax++; // $Tax 1.06.
13
$TotalCost = (($Cost * $Quantity)
14
$Payments = round ($TotalCost, 2)
15
/7 .
16
print ("You requested to purchase
17

- $Discount) * $Tax;
/ 12;

$Quantity widget(s) at \$$Cost


each.\n<P>");
print ("The total with tax, minus your \$$Discount, comes to $");
printf ("%01.2f", $TotalCost);
print (".\n<P>You may purchase the widget(s) in 12 monthly
installments: of $");
.printf ("%0l!2f", $Payments);
print (" each.\n<P>");

18
19
20

21
22
23
24
25 </BODY>
26 </HTML>

,,

, :
if

(condition)

statement;

,
. , , .

You requested to purchase 3 widget(c) at S2000 each.


The total with tax. minus your SO, comes to $6360.00.
You may purchase the widget(s) in 12 monthly installments of $530.00 each.

Par .

~*

. 6.1
$Quantity, ,

You requested to purchase 0 widget(s) at $2000 each.


Hie total with tax, minus your 0. comes to SO. 00.
You may purchase the widget(s) in 12 monthly installments of SO. 00 each..

. 6.2 i f
, . ,
.
, ,
. , , .
, ,
isset (). , ,
isset () , :

$Quantity = 0;
if ($Quantityl { ... // FALSE
if (isset ($Quantity)) { ... // TRUE


, , . (+)-, (-), (*) . (/), (+ + ) ()
. (=), .
(.), .
,
, .
.


2 ( ).
, .

6
SVariable = 5; , SVariable 5, ,
5,
, (,
), (
). (==), .
SVariable = 5;
SVariable == 5;

SVariable 5, , , , SVariable 5. ,
.
(! =). , . SVariable , SVariable , , ! SVariable SVariable ,
.
: (<)', (>), (<=), (>=).
, nunlbers.php , $50.


1. numbers.php ( 6.2) .
2. , $50, 8.
SCost = 2 0 . 0 0 ;

3. 13 STotalCost :
STotalCost = (SCost * SQuantity);,
$50,
.
4. , , $50.
if (STotalCost >= 50) {
STotalCost = STotalCost - SDiscount;

, , , $TotalCost $50 ( ). ,
.
5. .
$TotalCost = $TotalCost * $Tax,6. ,
.
7. ( 6.3), $Quantity
(. 6.3 6.4).
6.3 , (<=),
.
1
<HTML>
2
<HEAD>
3 ,, <TITLE>Conditionals</TITLE>
4
</HEAD>
5
<BODY>
6
<?php

/* $Quantity .
$Discount . */

8
9

$Cost = 20,00;
$ = 0.06;

10 if ($Quantity) {
11
SQuantity = abs($Quantity);
12
$Discount = abs($Discount);

'

13

$Tax++; // $Tax 1.06.

14
15

$TotalCost = ($Cost * $Quantity);


if ($TotalCost >= 50) {

16
17
18
19
20
21

$TotalCost = $TotalCost - $Disoount;


}
$TotalCost = $TotalCost * $Tax;
$Payments = round ($TotalCost, 2) / 1 2 ;
// .
print ("You requested to purchase $Quantity widget(s) at \$$Cost
each.\n<P>");
print ("The total with tax, minus your \$$Discount, comes to $");
prlntf ("%01.2f", $TotalCost);
print (".\n<P>You may purchase the widget(s) in 12 monthly
installments of $");
printf ("%01.2f", $Payments);
print (" each.\n<P>");

22
23
24
25
26
27
28
29
30

}
?>
</BODY>
</HTML>

6 v

UMlioit|mp//mw.OMCrafi,eomWnumten|70<^2||1-1500

You requested to purchase widget(s) at $20 each.


The tola! with tax, minus your l 5. comes to $42 40.
You may purchase die widget(s) in 12 monthly installments of S3.53 each.

. 6.3 , $50. , . 6.4

^iaertlMt)bttp//v^wDMCno^scoWp^numbeisphp?Quar^-3^counl-1500
You requested to purchase 3 widgetfs) at $20 each.
The total with tax, minus $15, coiries to IH7.70
You may purchase the widget(s) in 12 monthly installments of $3 98 each.

. 6.4 $50,

if
$Variable == 5 $Variable = 5, . , $Variable == 5 , $Variable = 5 ,
.


- ,
, . , ,
, :
$Variable = 5 ;
if ($Variable) { ...


, :
if (5>=3-) { ...
, . , :
if (5<=3)

{ ...


: (AND &&);
(OR I I - ); (NOT ! - ); (XOR). (AND, OR NOT),
(. ).

i f .
AND . OR
, . :
if ( ( 5 <= 3) OR (5 >=3 )) { ...
if ( (5 > 3) AND (5 < 10) ) { ...

, , :
if ( (5 != 5) AND (5 > 3 ) ) { . . .
if ( ( 5 != 5) OR (5 < 3 { ...

, : -,
, ; -, , .
,
numbers.php. ,
.


1. numbers.php ( 6.3).
2. $TotalCost ( 6.3,
14), if ($TotalCost >= 50),
:
if ( ($TotalCost < 50) AND ($Discount) ) {
print ("Your \$$Discoupt will not apply because the total value of
the sale is under $50!\n<P>");
: -,
$TotalCost $50, -,

6
. , .
, (
AND) .
3. , ( 6.4),
(. 6.5 6.6).
6.4 AND
, . AND, ,
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

<HTML>
<HEAD>
<TITLE>Conditionals</TITLE>
</HEAD>
<BODY>
<?php
/* $Quantity .
$Discount . */
$Cost = 20.00;
$ =0.06;
if ($Quantity) {
$Quantity = abs($Quantity);
$Discount = abs($Discount);
$Tax++; // $Tax 1.06.
$TotalCost"= ($Cost * $Quantity);
if ( ($TotalCoet < 50) AND ($Discount) ) {

16

print ("Your \$$Discount will not apply because the total value
of the sale is under $50!\n<P>");

17
18
19
20
21
22
23
.24

}
if ($TotalCost >= 50) {
$TotalCost = $TotalCost - $Discount;
}
$TotalCost .= $TotalCost * $Tax;
$Payments = round ($TotalCost, 2) / 12;
// .
print ("You requested to purchase $Quantity widget(s) at \$$Cost
each.\n<P>"};
print ("The total with tax, minus your \$$Discount, comes to $");
printf ("%01.2f", $TotalCost);
print (".\n<P>You may purchase the widget(s) in 12 monthly
installments of $");
printf ("%01.2f", $Payments);
print (" each.\n<P>");
-

25
26
27
28
29
30
31
32
33

}
?>
</BODY>
</HTML>

ff-else
-
TRUE () FALSE () .
, , . - (,
, ), .

..-.v..bwl . . . '

*f 4, Loc6oa fWtp //www DMCrisigWs conv^nurtto

'

'..

5 CO

Your $13 will not apply because the total value of the sale is under $50!
You requested to purchase 2 widget(s) at $20 each.
The total with tax, minus your $15, comes to $42.40.
You may purchase the widget(s) in 1 2 monthly installments of $3.53 each.

-;? .

. 6.5 ,
.

Fte

if. fio

4 Lcrsliw jh'tp '^-jvs'UMr>.igtif con- ohp'nurober


You requested to puichase 3 widget(s) at $20 each
Tbe total with tax, minus your $0. comes to $63.60.
You may purchase the widget(s)in 12 monthly installments of $5.30 each

bocumcnt Dor

OP...

. 6.6 $50,
, SDiscount

if-else
- i f - e l s e , i f - t h e n else. , , - .
if (condition) {
statement(s);

} else {
statement(s)2;
, if else. , else
, i f - . numbers.php, else.

else
1. numbers.php ( 6.4).
2. if
( 30), :
} else { print ("Please make sure that you have entered both
a quantity and an applicable discount and .then r e s u b m i t . \ n " ) ; }

, ,
.
3. ( 6.5), (. 6.7).
6.5 if-else if, - ., .
1
2
3
4
5
6

<HTML>
<HEAD>
<TITLE>Conditionals</TITLE>
</HEAD>
<BODY>
<?php

/* $Quantity .
$Discount . */

'8
9

$Cost =20.00;
$ = 0.06;

10 if ($Quantity) {
11
SQuantity = abs($Quantity);
12
$Discount = abs($Discount);
13
$Tax++; // $Tax 1.06.
14
$TotalCost = ($Cost * $Quantity);
15
if ( ($TotalCost < 50) AND ($Discount) ) {
16
print ("Your A$$Discount will not apply because the total value
of the sale is under $50!\n<P>");
17

18

if ($TotalCost >= 50) {

19
20

21
22

$TotalCost = $TotalCost * $Tax,$Payments = round ($TotalCost, 2) / 12;

$TotalCost = $TotalCost - $Discount;

if-elseif
23
24
25
26
-27
28
29
30
31
32
33
34
35

// .
print ("You requested to purchase SQuantity widget(s) at \$$Cost
each.\n<P>") ;
print ("The total with tax, minus your \$$Discount, comes to $");
printf ("%01.2f", $TotalCost);
print (".\n<P>You may purchase the widget(s) in 12 monthly
installments of $");
printf ("%01.2f, $Payments);
print (" each.\n<P>");
} else {
print ("Please make sure that you have entered both a quantity and
an applicable discount and then resubmit.\n"); }
?>
'

</BODY>
</HTML>
if-else
numbers.php, , . if-else (widget) (widgets)
.
,
*'
DMun^^coft^y/numbtft php
Please mike sure that you have entered botfa a quintity and an applicable discount and then resubimt

. 6.7 :

. ,

if-elseif
if-elseif ( if-elseif-else) if ( if-else). , i f ,
,
:
if (conditional) {
statement(s);


} elseif (conditional) {
statement(s)2;
:
if (conditional) {
statement(s) ;
} elseif (conditional) {
statement(s)2;
} else {
statement(s)3;
hello.php, 3.
if-elseif date () .

elseif
1. PHP- .
2. HTML- PHP- .
<HTMLxHEADxTITLE>If-elseif Conditionals</TITLExBODYx?php
3. if.
if ($Username) {
, .
4. print ("Good " ) ;

. ,
, .
5. if ( d a t e ( " " ) -== "AM") {
date() ( , ..) .
date ( " " ) "AM" ( ) "" ( ). date () 13.
6. print ("morning, " ) ;
} elseif ( ( datef'H") >= 12 ) and ( d a t e ( " H " ) < 18 ) ) {
date ( " H " ) /.
18:00 .
7. print ("afternoon, " ) ;
} else {
.
print ("evening, " ) ;

if-elseif
, , . else, .
' 8. } / / if ,
print ("$Username");
print ( " ! \ n " ) ;
} else {
'

print ("Please log i n . \ n " ) ;


, , .
9. } // if .

, .
10. hello.php ( 6.6),
(. 6.8 6.9).

* " ^
J Localcn [hiip Mwiw DHCmqhlt

"3 jflTWNOIMW

Good evening, Lairy!

. 6.8 , - 18:00

Good afternoon, Larryl

. 6.9 , , -
18:00

6.6 if-elseif-else if-else.


, , ( ).
1
2

<HTML>
<HEAD>

3
4
5

<TITLE>If-elseif C'onditionals</TITLE>
<BODY>
<?php

6
7
8
9
10
11
12
13
14

15
16
17

if ($Username) {
print ("Good ");
if (date("A") == "AM") {

print ("morning, ");


} elseif (.( date("H") >= 12-) and ( date("H") < 18 ) ) {
print ("afternoon, ");
} else {
print ("evening, ");
} // if .

print ("$Username");
print ("!\n");
} else {

18
print ("Please log in.\n"J;
19 } // if
20 ?>
21 </BODY>
22 </HTML>
else , else ,
.
if, elseif
.
elseif , :

if (condition) {
statement(s);
} else if (condition2) {
statement(s)2;
date () , , ,
. , ,
date () .

switch
, i f - e l s e i f - e l s e , switch.

switch
. switch . :
switch ($Variable) {
case "valuel":
statement(s)1;
break;
case "valuel":
statement(s)2;
break;
default:
statement(s)3;
break;
, switch. PHP , , , . , switch
( ) break,
switch. , ( ) break.
switch , , :
' if ($Variable == "valuel") {
statement(s)1;
} elseif ($Variable == "value2") {
statement(s)2;
} else {
statement(s)3;
}
switch. -, : . -,
break
. , , default:.
switch
HTML-, .
, switch, , , HTML-.

switch
1. HTML- .
2. HTML-.
<HTMLxHEADxTITLE>HTML Contact Form</TITLEx/HEADxBODY>

3. , .
<FORM ACT10N="HandleContact.php" METHOD=POST>
First Name <INPUT TYPE=TEXT NAME="FirstName" SIZE=20xBR>
Last Name <INPUT TYPE=TEXT NAME="LastName" SIZE=20xBR>
How would you prefer to be contacted: <SELECT NAME="ContactHow">
<OPTION VALUE="">Select One:</OPTION>
<OPTION VALUE="Telephone">Telephone</OPTION>
<OPTION VALUE="Mail">Mail</OPTION>
<OPTION VALUE="E-Mail">E-Mail</OPTION>
<OPTION VALUE="Fax">Fax</OPTION>
</SELECTxBR>

Web-. .
.
4. , HTML.
Comments <TEXTAREA NAME= "Comments" ROWS = 5 COLS=40x/TEXTAREAxBR>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</FORMx/BODYx/HTML>

5. contact.html ( 6.7) .
6.7 HTML- .
1
2
34
5
6
7
8
9
10
11
12
13
14
15
16

<HTML>
<HEAD>
<TITLE>HTML Contact Form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="HandleContact.php" METHOD=POST>
First Name <INPUT TYPE-TEXT NAME="FirstName" SIZE=20xBR>Last Name <INPUT TYPE=TEXT NAME="LastName" SIZE=20xBR>
How would you prefer to be contacted: <SELECT NAME="ContactHow">
<OPTION VALUE="">Select One:</OPTION>
<OPTION VALUE="Telephone">Telephone</OPTION>
<OPTION VALUE"Mail">Mail</OPTION>
<OPTION VAI,DE="E-Mail">E-Mall</OPTION>
<OPTION VALUE*"Fax">Fax</OPTION>
</SELECTxBR>
Comments <TEXTAREA NAME= "Comments" ROWS=5 COLS=40x/TEXTAREAxBR>

switch
17
18
19
20

<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">


</FORM>
</BODY>
</HTML>

6. ,
contact.html.
7. PHP- .
8. HTML-.
<HTMLxHEADxTITLE>Contact Information Request</TITLEx/HEADxBODY>

9. HTML- .
<FORM ACTION="HandleContact2.php" METHOD=POSTx?php

, .
10. contact.html
.

print '("<INPUT TYPE=HIDDEN NAME=\"FirstName\"


-VALUE=\"$FirstName\">\n");
print ("<INPUT TYPE=HIDDEN NAME=\ "LastNameV
-VALUE=\"$LastName\">\n");
print ("<INPUT TYPE=HIDDEN NAME= \," Comments \ "
-VALUE=\"$Comments\">\n");
print ("<INPUT TYPE=HIDDEN NAME=\"ContactHow\"
-VALUE=\"$ContactHow\">\n");

,
HIDDEN (). , contact.html, ,
- HandleContact2.php.
11. switch,
contact.html -.
switch (SContactHow) {
case "Telephone":
print("<B>Please enter a daytime phone number where you can be
reached:</BxBR>\n");
print ("<INPUT TYPE=TEXT NAME=\"TelephoneV SIZE=10xBR>") ;
print ("xINPUT TYPE=SUBMIT'NAME=SUBMIT V A L U E = \ " C o n t i n u e \ " > \ n " ) ;
break;
case " M a i l " :

print ("<B>Please enter your complete mailing address:

</BxBR>\n") ;
print ("<TEXTAREA NAME=\"MailAddressX" ROWS=5 COLS=40>
-<TEXTAREAxBR>\n"} ;
print ("<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=\"Continue\">\n");
break;
case "E-Mail":
print("<B>Please enter your E-Mail address:</BxBR>\n");

6
print ("<INPUT TYPE=TEXT NAME=\"E-Mail\" SIZE=40xBR>\n") ;
print ("<INPUT TYPE=SUBMIT NAME=SUBMIT V A L U E = \ " C o n t i n u e \ " > \ n " ) ;
break;
case "Fax":

print("<B>Please enter your Fax number:</BxBR>\n");

print ("<INPUT TYPE=TEXT NAME=\"Fax\" SIZE=10xBR>\n");

print ("<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=\"Continue\">\n");


break;
default:
print("<B>Please go back and select how you would prefer to be
-contacted4.</BxBR>\n") ;
break;
switch ,
$ContactHow. , , e-mail . $ContactHow ,
contact.html
.
12. , HTML-.
?></FORMx/BODYx/HTML>

13. HandleContact.php ( 6.8),


contact.html
(. 6.10-6.14).
6.8 switch
SContactHow. ,
: , ,
.
.
I
' ' 2

3
4

5
6
7
8

<HTML>
<HEAD>

<TITLE>Contact Information Request</TITLEx/HEAD>


<BODY>

<FORM ACTION="HandleContact2.php" METHOD=POST>


<?php
// INPUT HIDDEN.
print ("<INPUT TYPE=HIDDEN NAME=\"FirstName\n ,
VALUE=\"$FirstName\">\n");
9 print ("<INPUT TYPE=HIDDEN NAME=\"LastName\"
VALUE=\"$LastNaroe\">\n");
10 print ("<INPUT TYPE=HIDDEN NAME=\"Corranents\" VALUE=\"$Comments\">\n");
II print ("<INPUT TYPE=HIDDEN NAME=\"ContactHowV"
VALUE=\"$ContactHow\">\n");

switch

12
13 switch ($ContactHow) {
14
case "Telephone":
15
print("<>1 enter a daytime phone number where you can be
reached: </BxBR>\n");
16
print ("<INPUT TYPE-TEXT NAME=\"Telephone\" SXZE=10xBR>v");
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
41

print ("<INPUT TYPE=SUBM1T NAME=SUBMIT VALUE=\"Continue\">\n");


break;
caae "Mail":
print ("<B>Please enter your complete mailing address:</>
<BR>\n");
print ('4TEXTAREA NAME*\"MailAddress\" ROWS=5 COLS=40>
<TEXTAREAxBR>\n");
print ("<IKPUT TYPE=SUBMIT NAME=SUBMIT VALUE=\"Continue\">\n");
break;
case "E-Mail":
print("<B>Please enter your E-Mail address:</BxBR>\n");
print ("<INPOT TYPE=TEXT NAME=\"E-Mail\" SIZE=40xBR>\n");
print ("<INPXJT TYPESUBMIT MAME=SUBMIT VALUE=\"Continue\">\n");
break;
case "Fax":

print("<B>Pleaae enter your Fax number:</BxBR>\n");


print ("<INPUT TYPE=TEXT NAME=\"Fax\" SIZE=10xBR>\n");
print ("<INPDT TYPE=SUBMIT =1 VALOE=\"Continue\">\n");
break;
default:
print("<B>Pleaae go back and select how you would prefer to be
contacted! </BxBR>\n") ;
break;
}
?>
</FORM>
</BODY>
</HTML>

E*
First Name |
Last Name |"lln
How would you prefer to be contacted: [E-Mail
I'm using the switch conditional
help handle an HTHL form.

. 6,10 HTML-, contact.html.

,0 *

{*1 H*

P1nse enter your E-Mail address;

. 6.11
(. . 6.10), HandleContact.php
,

"*

<IlffiUT TXPB-HII>D
<IMPUt TYPB-HJI'DEK KAME-"L?i?t;N[" VJU.UE-F'Uilnir.">
<IHPIFT -1 HAME-"Conatifincs" VALUE- " I\ ' m 1
lielp liaume KTHL ^EW.' : >
<11' TYPE-HIDI'KN HAME-"CT-llT*ctH^B" VALUE- "K-K-S1 1"

the switch conditional

. 6.12 HTML- ,
. 6.11. ,
,
HandleContact2.php

enter your complete mailing address.

-7)

.-a.
. 6.13 ,

while

le
Please go buck nd select how you would prefer to be contacted1

. 6.14 ,
HandleContact2.php, HandleContact.php ( , ). ,
HandleContact.php , -, .
switch ( , ,
). ,
, .
switch , , Value value.

while
, . , ( 1 31). . .
- while - , .
.
, .
while (condition) {
statement (s) ;
whi le , (, , ) HTML-.

6
, ,
HTML-.

while
1. PHP- .
<HTMLxHEADxTITLE>Select Menu</TITLEx/HEADxBODYx?php
2. date ( ) .
$Year = date ( " Y " ) ;
date ( ) " Y " . . .
3. HTML-, .
print
print
print
print
print
print
print
print
print
print
print
print
print
print
print

("<FORM ACTION=\"$PHP_SELF\" METHOD=POST>\n");


("Select a month: <BR>\n" ),("<SELECT NAME=MonthxOPTION>Choose Qne</OPTION>\n");
("<OPTION VALUE=January>January</OPTION>\n");
("<OPTION VALUE=February>February</OPTION>\n");
("<OPTION VALUE=March>March</OPTIONS\n");
("<OPTION VALUE=April>April</OPTION>\n"); '
("<OPTION VALUE=May>May</OPTION>\n");
("<OPTION VALUE=June>June</OPTION>\n");
("DPTION VALUE=July>July</OPTION>\n");
("<OPTION VALUE=August>August</OPTION>\n");
("<OPTION VALUE=September>September</OPTION>\n");
(VOPTION VALUE=October>October</OPTION>\n");
("<OPTION VALUE=November>November</OPTION>\n");
("<OPTION VAL0E=December>December</OPTION>\n");

4. while .
print ("<P>Select a day:<BR>\n");
print ("<SELECT NAME=DayxOPTION>Choose One</OPTION>\n");
$Day = 1;
while ($Day <= 31} {
print ("<OPT10N VALUE=$Day>$Day</OPTION>\h");

$Day++;

print ( " < / S E L E C T > \ n " ) ;


$Day 1.
.
, $Day 31 . , $Day .
, $Day 1.
, 32.
.

while

^ffiT

5. while .
print ("<P>Select a year:<BR>\n");
print ("<SELECT NAME=YearxOPTION>Choose One</OPTION>\n");
$EndYear = $Year + 10;
while ($Year <= $EndYear ) {
print ("<OPTION VALUE=$Year>$Year</OPTION>\n");
$Year++;
}
'
print ( " < / S E L E C T > \ n " ) ;

. $Year . ,
$EndYear, $Year (
5 15 ). , , SYear $EndYear, SYear .
6. Submit, , HTML.
print ("<PxINPUT TYPE=SUBMIT NAME=SDBMIT V A L U E = \ " G o ! \ " >
-</FORM>\n") ; ?></BODYx/HTML>

HTML ,
. Submit.
7. select.php ( 6.9),
(. 6.15 6.16).
6.9 while
(. . 6.16). date ( ) .
.
1
2

<HTML>
<HEAD>

<BODY>

5
6
7

<?php
$Year = date ("Y");
// .

print ("<FORM ACTION=\"$PHP_SELF\" METHOD=POST>\n");

10
11
12
13
14
15

print
print
print
print
print
print

<TITLE>Select Menu</TITLEx/HEAD>

// .

("Select a month:<BR>\n");
("<SELECT NAME=MonthxOPTION>Choose One</OPTION>\n");
("<OPTION VALUE=January>January</OPTION>\n");
("<OPTION VALUE=February>February</OPTION>\n");
("<OPTION VALUE=March>March</OPTION>\n");
(VOPTION VALUE=April>April</OPTIGN>\n");

16 print ("<OPTION VALUE=May>May</OPTION>\n");


17 print ("<OPTION VALUE=June>June</OPTION>\n");
18 print ("<OPTION VALUE=July>July</OPTION>\n");

6
19 print ("DPTION VALUE=August>August</OPTION>\n");

20 print ("DPTION VALUE=September>September</OPTION>\n");


21 print ("DPTION VALUE=October>October</OPTION>\n");
22 print ("<OPTION VALUE=November>November</OPTION>\n");

23 print ("<OPTION VALUE=Deceinber>December</OPTION>\n") ;


24 print ("</SELECT>\n");

25 // . .
26 print ("<P>Select a day:<BR>\n");

27 print ("<SELECT NAME=DayxOPTION>Choose Qne</OPTION>\n");


28 $Day = 1;

29 while ($Day <= 31) {


30
print ("<OPTION VALOE=$Day>$Day</OPTIOM>\n");
31
$Day++;
32 }
33 print ("</SELECT>\n");

34 // . .
35 print ("<P>Select a year:<BR>\n");
36 print ("<SELECT NAME=YearxOPTION>Choose One</OPTION>\n");

37 $EndYear = $Year + 10;


38
while ($Year <= $EndYear ) {
39
print ("<OPTION VALOE=$Year>$Year</OPTION>\n");
40
$Year++;
41 }
42 print ("</SELECT>\n");

43 print ("<PxINPUT TYPE=SUBMIT NAME=SUBMIT V A L U E = \ " G o ! \ " > < / F O R M > \ n " ) ;
44 ?>
45 </BODY>
46 </HTML>
do...while, , while:

do {

statement(s);
} while (condition);

Select a month
[Choose One ^j
Select a day:
] Choose One j*j
Select a year:

2001
2002
2003
.-2004
12005
2006
2007
2006
2009
2010
,2011

. 6.15 select.php ,
, .
HTML-

while
, ,
. SDay
$Year (, 31).
<SELECT> .

<SSUCT
<OPT

IOH> ^

<UPTIOH VALUE-KQ
<OPTIOH VALUE-Ju
<WWeS VALUE-Juiy>July</BPTIOH>

<OPTIO
< OP I OH VALUE-Novenfcec>Noverrtoer</aPTIOH>

< SELECT
<OPTZOH
<(
<OPTIOH
<OPTIOB
<OPTIOK

-^10> On*</OPlIOH>
VALUE- 1>U/OPTIOH>
" s> "
VALUE-2>2</l)PTIOH>
* ,
S
VALUE-3>3</OPTIOH>
-'',
' v >
VALUE-4>4</OI>rillH>
***?* -. -,,.'-'
t
VALUE5>5</OPTIOH>

* '; ,

<OPTIOH

vju.ui:-6>6</opf IOH>

<OPTIOK
<OPTIQ1I
<(TII)H
<OPTIOH
<OP1IOH
<OPTI08
<OPTIOM
<OPTIOH
<OPTIOH
<OPTIOM
<OPTIOH

VALUE-=7>7</OPTIOH>
VALUE- e>8</OPTIOH>

<OPTIOT

'

'

'
.

'

. *-

'

VALUE- 10>10</OPTIOH>
VALUE- >1K/OPTIOK>
VAHnE- l2>12</OPTIO>
VALUE- 13>13</OPTIOH>
VAHTE- 14>14</OFTHIH>
VALUE- 15>15</OPtIOH>
VALUE- 1?>17</OPTIOH>

H
<OPTIDH
<OPTIOH
<OPTIOH
<0*
<OPTIOH
<OPTIOH
<OPTTOM
<OPTIDH
<OPTIOH
<OPTZOH
<OPTIDM
<OPTIOH

VALUb-l?>19</OPTIOH>
VALUE-20>2CK/OPTIQH>
VALE-;2>22</OPTIOH>
VALUE-^J>23</OPTIO>I>
VALUI24>24</OPIIQH>
VALUE-S>2S</OPirOH>
VALUI,^:6>26</t)PTIOH>
VALUE*3" 3 >27</tfPTIOH>
VALUE-i8>26</OPTIHH>
VALUE-; S>>29</OPTIDH>
VALUE-?0>30</OeTIOM>
VALUE-3 i>3K/OPT'IOH>

<SELKCT
<OPT10H
<OPTIOH
<QP. : riOM

MA|tt-ra.$eXO?T!OHx;toQ3e
VALUE-?.C'0.l>2001</HPTIBM>
VALUE-:CD;>2Q02</OPriOK>
VALUE-JL)03>2003</OI'il(IH>

<OPTIOH
<I)PTIBK
<OPTIDB
<OPTIOH
<OPTIOH

VALUE-20Q7>2007</OPTIOff>
VALUE-3:fXi3>200e</PTIOH>
VALUE-:009>2009</OPTIOH>
VALUE-2QlCi>20lQ</OPTIOT>
VALUE-D11>201K/QPTIOH>

:otr>

. 6.1 , . 6.15.
, 6.9 ( while) 40-50 HTML
( )

6
, if, while , . .

for
for ( while, , ). ,
. for ,
while. ,
, - .
for ( ; ; ) {
statement(s);
}

- . . , . ,
, , .
:
for ($n = 0; $n < count($Array); $n++) {
print ("$Array[$n]<BR>\n");
}

,
. for
while $Day 6.9 for.
:
$ = 1;
while ($Day <= 31) {
print ("<OPTION VALUE=$Day>$Day</OPTION>\n");
$Day++;

$Day,
($Day <= 31). , print ( ) $Day .
for :
for ($Day = 1; $Day <= 31; $Day++;) {
print ("<OPTION VALUE=$Day>$Day</OPTION>\n");
'

for
for -
1 1000.

for
1. PHP- .
<HTMLxHEADxTITLE>Prime Numbers</TITLEx/HEADxBODY><?php

2. for.
for

($n = 1;

$n <= 1000;

$n++)

'

for $ . 1. , $:
1000. , 1000 . ,
($ <= 1000) , , $
.
3. .
if ( ($n - = = 1) OR ($n == 2) OR ($n == 3) OR ($n == 5 ) ) {

print("$ri<BR>\n");
} elseif (($n % 2 != 0) AND ($n % 3 != 0) AND($n % 5-!= 0)) {
print("$n<BR>\n") ;

,
. , - , , . , 4 , , 7
2, 3 5, . , 1, 2, 3
5 - , , $
, . ,
OR, , ,
$ .
$ 1, 2, 3 5, ,
, . 2, 3 5 ,
. , ,
, (%). . , . 3 ,
,
.
$ 2, 3 5 ,
, , , .

, AND. ,
, - .
4. , HTML.

</BODY>
</HTML>

5. primes.php
( 6.10), (. 6.17).
6.10 - for,
1000 .
1
2
3
4

<HTML>
<HEAD>
<TITLE>Prime Numbers</TITLEx/HEAD>
<BODY>

5
6

<?php
//
, .

7
8

for ($n =1; $ <= 1000,- $++) {


if ( ($n == 1) OR ($n 2) OR ($n == 3)OR ($n = = 5 {
9
print("$n<BR>\n");
10
} elseif (($n 2 1- 0) AND ($n % 3 != 0)
AND ($n 5 1= 0)) {
11
print("$n<BR>\n");

. 6.17
,
for. 16 6.10 300
HTML

12
} // IF.
13 } // FOR.
14 ?>

15 </BODY>
16 </HTML>
,
for, while, ,
. while (. 11), for - (
7).
, 6.10, (49, ). , , $ .

- . ( , ,
, .)
, . ,
. /
(/ ),
, . ,
( ) . ,
, :
$Iteml = "apples"
$Item2 = "bananas"
$Item3 = "oranges"

, .
, (, SItems).
, ,
.. .
- -
(, $FirstName, "Larry"). ,
( , ,
, ), .
- , , ( ). .

- ,
.
.
( ),
- . , (. 7.1 7.2).
, , ([ ] ) . , $ ,
$ [ 0 ] . ( , 5.
, ,
.)
.
.
7.1 - .
, , ()

Index or Key

Value

Getting Started with PHP

Variables

HTML Forms and PHP

Using Numbers

Using Strings

Control Structures
Using Arrays

7.2 ( ) ,

Index or Key

Value

ChapterJ

Getting Started with PHP

Chapter_2

Variables

Chapter_3

HTML Forms and PHP

Chapter_4
Chapters

Using Numbers
.

Using Strings

Chapter_6

Control Structures

Chapter_7

Using Arrays


- array ( ) :
$List = array ( " a p p l e s " , " b a n a n a s " , " o r a n g e s " ) ;


( ) , , 0, - 1, - 2-
,
array ( ) :
$List = array ( l = > " a p p l e s " , 2 = > " b a n a n a s " , 3 = > " o r a n g e s " ) ;

,
. .
, .


1. PHP- .
2. HTML-.
<HTMLxHEADxTITLE>Using Arrays</TITLEx/HEAD><BODY>

3. PHP- array ( )
.
<?php
$Soups = arrayf
"Monday"=>"Clam Chowder",
"Tuesday"=>"White Chicken Chili",
"Wednesday"=>"Vegetarian"
);

( )
.
4. Web-.
print ("$Soups<P>\n");
5. HTML.
?></BODYx/HTML>

6. soups.php ( 7.1), (. 7.1).

1. *

&>*. -*

Array

7.1 ( ) .
1
2
3
4
5
6
7
8
9

<>
<HEAD>
<TITLE>Using Arrays</TITLEx/HEAD>
<BODY>
<?php
$Soups = array(
"Monday"=>"Clam Chowder",
"Tuesday"=>"White Chicken Chili",
"Wednesday"=>"Vegetarian");

. 7.1 ,
Array. He , (
),

10 print ("$Soups<P>\n");
11 ?>
12 </BODY>
13 </HTML>
, . ,
. -, . -, ,
. . ,
.


, .
( )
, . , .
$List, :
$List[] = "pears";
$List[] = "tomatoes";

, .
,
1, 2 3, (pears) 4, (tomatoes) - 5.
, , :
$ L i s t [ 3 ] = "pears";
$ L i s t [ 4 ] = "tomatoes";

4 - , (oranges) . , , ,
- . , , , .
,
soups.php. , -
, .
(
) strlen ( ) , count ( ) :
$HowMany = count($Array);


1. soups.php .
2. array ( ) :
$HowMany = count($Soups);
print ("The array contains $HowMany elements.<P>\n");

count ( ) , $ Soups. , .
3. .
$Soups["Thursday"] = "Chicken Noodle";
$Soups["Friday"] = "Tomato";
$Soups["Saturday"] = "Cream of Broccoli";
4. .
$HowManyNow = count($Soups);
print ("The array now contains $HowManyNow e l e m e n t s . < P > \ n " ) ;

5. ( 7.2), (. 7.2).
7.2 ,
. count ( ) , .
1
2
3
4
5

<HTML>
<HEAD>
<TITLE>Using Arrays</TITLEx/HEAD>
<BODY>
<?php

6
7
8
9

$Soups = array(
"Monday"=>"Clam Chowder",
"Tuesday"=>"White Chicken Chili",
"Wednesday"=>"Vegetarian");

10 $HowMany = count($Soups);
11 print ("The array contains $HowMany
elements.<P>\n");
12 $Soups["Thursday"] = "Chicken Noodle";
13 $Soups["Friday"] = "Tomato";
14 $Soups["Saturday"] = "Cream of
Broccoli";
15 $HowManyNow = count($Soups);
16 print ("The array now contains
$HowManyNow elemente.<P>\n");
17 ?>
18 </BODY>
19 </HTML>

The atray contains 3 elements


The array now contains elements.

. 7.2 Y ,
,

TTfF

4.0 ,
. . array_merge ( ) :
$NewArray = array_merge ($OneArray, $TwoArray);

soups.php ,
, 4.0.


1. soups.php , .
2. $Soups .
$HowMany = count($Soups);
print ("The \$Soups array contains $HowMany elements.<P>\n");

3. ,
.
$Soups2 = array(
"Thursday"=>"Chicken Noodle",
"Friday"=>"Tomato",
"Saturday"=>"Cream of Broccoli");
$HowMany2 = count($Soups2);
print ("The \$Soups2 array contains $HowMany2 elements.<P>\n");
4. .
$TheSoups = array_merge ($Soups, $Soups2);

,
($Soups, $Soups2),
- , .
5. .
$HowMany3 = count($TheSoups);
print ("The \$TheSoups array contains
$HowMany3 elements.<P>\n");
6. HTML-.
?></BODYx/HTML>

7. ( 7.3),

(. 7.3).
7.3 Array_merge ( ) . 4.0,
. , .
1
2

<HTML>
<HEAD>

the SSoups atray contains 3 elements.


The $8|:2 array contains 3 elements,
tbe STbeSoups airay contains 6 elements.

. 7.3 count () ,


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

^ty

<TITLE>Using Arrays</TITLEx/HEAD>
<BODY>
<?php
$Soups = array!
"Monday"=>"Clam Chowder", "Tuesday"=>"White Chicken Chili",
"Wednesday"=>"Vegetarian"
);
$HowMany = count($Soups);
print ("The \$Soups array contains $HowMany elements.<P>\n");
$Soups2 = array(
"Thursday"=>"Chicken Noodle",
"Friday"=>"Tomato",
"Saturday"=>"Cream of Broccoli"
);
.
$HowMany2 = count($Soups2);
print ("The \$Soups2 array contains $HowMany2 elements.<P>\n");
$TbeSoupe = array_merge ($Soups, $Soups2);
$HowMany3 = count ($TheSoups) ;
print ("The \$TheSoups array contains .$HowMany3 elements.<P>\n");
?>
'
</BODY>
</HTML>
.
: $Ar ray [] = "Add This"; $[1] = "Add This";, - : $ = " Add This";. ,
,
.
4.0 . . , .
, 4.0, 3.x.


, ., (, ) - . -
:
$Total = $Array[l];

" , , :
.print ("The total of your "order comes to $Array [ T o t a l ] " ) ;

, , print ( ) . :
print ("The total of your order comes to $ A r r a y [ " T o t a l " ] " } ;
, :
$Array["Name"] = t r i m ( $ A r r a y [ " N a m e " ] ) ;

, , , -
, . , .
$ Soups,
$ Soups [ 1 ] . ,
, $ Soups [ "monday" ] ,
Clam Chowder : $Soups [ "Monday"].
,
: each ( ) .
. each ( ) , ,
:
for ($n = 0; $n < count{$Array); $n++) {
$Line = each ($Array);
print ("Key.is equal to $Line[key].<BR>Value is equal
to $ L i n e [ v a l u e ] . " ) ;
each ( ) ,
$Line, $ . ,
. each ( )
$. each ( )
, $Line [key] (
$Line [0]) $Line [value] ( , $Line [1]) . . each ( ) ..
each ( ) for ( ) ,
.
soups.php, . .


1. PHP- .
2. HTML- ( 7.4).
<HTMLxHEADxTITLE>Using Arrays</TITLEx/HEADxBODY>.


7.4 -
. each ( )
, .

I
2
3
4
5

<HTML>
<HEAD>
<TITLE>Using Arrays</TITLEx/HEAD>
<BODY>
<?php

6 $Soups = array(
7
"Monday"=>"Clam Chowder",
8
"Tuesday"=>"White Chicken Chili",
9
"Wednesday"=>"Vegetarian",
10
"Thursday"=>"Chicken Noodle",
II
"Friday"=>"Tomato",
12
"Saturday"=>"Cream of Broccoli"
13 );
14 for ($n = 0; $n < count($Soups); $n++) {

15
$Line = each ($Soups);
16
print ("$Line[key]'s soup is $Line[value].<P>\n");
17 }
18 ?>
19 </BODY>
20 </HTML>

3. PHP- $Soups.
<?php
$Soups = array(

"Monday"=>"Clarn Chowder",
"Tuesday"=>"White Chicken Chili",
"Wednesday"=>"Vegetarian",
"Thursday"=>"Chicken Noodle",

"Friday"=>"Tomato",
"Saturday"=>"Cream of Broccoli"
4. for .
for ($n = 0; $n < count ($Soups) ; $+.+ ) {

0 $.
$. , ,
$ .
5. each ) , .
SLine = each ($Soups);
print ( " $ L i n e [ k e y ] ' s soup is S L i n e [ v a l u e ] . < P > \ n " ) ;
$Soups $Line each ( ) . .
6. , HTML.
}?></BODYx/HTML>

7. soups.php, (. 7.4).
count ($Array) for ( ) . .

Monday's soup is Clara Chowder.


Tuesday's soup is White Chicken Chik
Wednesday's soup is Vegetation
Thursday's soup is Chicken Noodle.
Friday's soup is Tomato.
Saturday's soup is Cream of Broccoli.

. 7.4 ^

. each ()

,


( ).
, . . .

sort ( ) . rsort ( ) . :
sort($Array);
rsort($Array);

$.
, . ,
count ($Array) -1, * . ,


,
. - , . , ,

. .
, ,, asort ( ) arsort ( ) . ,
,
.

ksort ( ) . krsort ( ) .
s h u f f l e () , , , .
, , , .


1. -.
2. HTML .
<HTMLxHEADxTITLE>Sorting Arrays</TITLEx/HEADxBODYx?php
3. .
$Grades = array(
"Richard"=>"95",
"Sherwood"= >"8 2 " ,
"Toni"=>"98",
"Franz"=>"87",
"Melissa"=>"75",
"Roddy"=>"85"
4. , .
print ("Originally, the array looks like this:<BR>");
for ($n = 0; $n < count($Grades); $n++) {
$Line = each ($Grades);
print ( " $ L i n e [ k e y ] ' s grade is $ L i n e [ v a l u e ] . < B R > \ n " ) ;

5. . , .
arsort($Grades);

, , asort ( ) arsort (-). , 75, 82, 85 .., 98, 95, 87,...


arsort ( ) , rsort ( ) , . rsort ( )
, .
, rsort ( ) .
6.
reset().
reset($Grades);

reset () $Grade,
. , .
7. ( ) .
print ("<P>After sorting the array by key using a r s o r t ( ) ,
the array looks like this:<BR>");
for ($n = 0; $n < count($Grades); $n++) {
$Line= each ($Grades);
print ("$Line[key]'s grade is $Line[value].<BR>\n"};
}
8. .
ksort($Grades);
reset($Grades);
ksort ( ) ( - ), .
9. .
print ("<P>After. sorting the array by key using ksort ( ) ,
the array looks like this:<BR>");
for ($n = 0;' $n < count ($Grades) ; $n+ + ) {
$Line= each ($Grades);
print ("$Line[key]'s grade is $Line[value].<BR>\n");
}
'
10. HTML.
?></BODYx/HTML>

11. sort.php ( 7.5),


(. 7.5).
7.5
, arsort ( ) ksort ( ) .
1

<HTML>

<HEAD>

3
4
5
6
7
8
9
10
11
12
13
14

<TITLE>Sorting Arrays</TITLE>
<BODY>
<?php
$Grades = array(
"Richard."=>"95",
"Sherwood"=>"82",
"Toni"=>"98",
"Franz"=>"87",
"Melissa"=>"75",
"Roddy"=>"85"

print ("Originally, the array looks like


this:<BR>i);
15 for ($n = 0; $n < count($Grades); $n++) {
16
$Line = each ($Grades);
17
print ("$Line[key]'s grade is
$Line [value] .<BR>\n") ;'
18 } '

19 arsort($Grades) ;
20 reset($Grades);

21 print ("<P>After sorting the array by


value using arsortO, the array looks
like this:<BR>");
22 for ($n= 0; $n < count($Grades); $n++)
23
$Line = each ($Grades);
24
print ("$1[1]'s grade is
$Line[value].<BR>\n");
25 }

Originally, the array looks like this:


Richard's grade is 95.
Sherwood's grade is 82.
Toni's grade is 98.
Franz's grade is 87.
Melissa's grade is 75.
Roddy's grade is 85.
After sorting the array by value using arsortQ, the
array looks like this:
Toni's grade it 98.
Richard's grade is 95.
Franz's grade is 87.
Roddy's grade is 85,
Sherwood's grade is 82.
Melissa's grade is 75.
After sorting the array by key using ksortQ, the atray
looks like this:
Franz's grade is 87.
Melissa's grade is 75.
Richard's grade is 95.
Roddy's grade is 85.
Sherwood's grade is 82.
Toni's grade is 98.

. 7.5
,
.
,

26 ksort($Gradee);
27 reset($Grades);

28 print ("<P>After sorting the array by key using ksortI


looks like this:<BR>");
29 for ($n = 0; $n < count($Grades); $n++) {
$Line= each ($Grades);
30
31
print "$Line[key] 's grade is $Line [value] .<BR>\n" )
32 }
33 ?>
34 </BODY>
35 </HTML>

the array


, , , . , implode ( ) , . , explode ( ) , , .
:
> URL ( );
> , ;

7
> , (, ) .
explode ( ) :
$Array = explode ($Sepa'rator, $String) ;
$Separator - , . , ,
. . :
$Array = explode ( " , " , $Strihg);
:
$Array = explode. (" ", $String) ;
, :
$String = implode($Glue, .$Array) ;
$String = implode(",", $Array);
:
$String = implode(" ", $Array);
explode () implode ( ) ,
HTML-, , . PHP- , . ,
, .


1. HTML- .
2. HTML-.
<HTMLxHEADxTITLE>HTML Form</TITLEx/HEADxBODY>

3. HTML- .
<FORM ACTION="HandleList.php" METHOD=POST>
Enter the words you want alphabetized with each
individual word separated by a space:<BR>
<INPUT TYPE=TEXT NAME="List" SIZE=80xBR>
,
. ,
, ( ).

4. Submit, HTML-.
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</FORMx/BODYx/HTML>

5. list.html (. 7.6) .
7.6 HTML-,
. -
Web-.
1
2
3
4
5
6

<HTML>
<HEAD>
<TITLE>HTML Form</TITLE>
</HEAD>
<BODY>
<PORM ACTION="HandleList.php" METHOD=POST>

Enter the words you want alphabetized with each individual word
separated by a space:<BR>

8
9
10
11
12

<INPUT TYPE=TEXT NAME="Hst" SIZE=80xBR>


<INPtJT TYPE=SUBMIT NAME="SDBMIT" VALOE="Submit 1">
</FORM>
</BODY>
</HTML>

HandleList.php, , list.html.
6. HTML- .
7. HTML- PHP- .
<HTMLxHEADxTITLE>Alphabetizing Example</TITLEx/HEADxBODYx?php

8.
$List .
$Array = explode (" " , $ L i s t ) ;

$ $List. $List
. , $ [ 0 ],
$List, $ [ 1 ],
.
9. .
sort ($Array);


$, sort ( ) asort ( ) , .
- sort ( ) .
10. .
$NewList = implode ("<BR>", $Array);

. ,
, , $ $NewList.
$ [ 0 ], HTML <BR>, $ [1], <BR> ..
.
11. .
print ("An alphabetized version of your list is:<BR>$NewList");
12. PHP- HTML-.
?></BODYx/HTML>

13. HandleList.php, list.html (. 7.7)


(. 7.6 7.7).
7.7 , explode () implode ()
.
1
2
3
4
5

<HTML>
<HEAD>'
<TITLE>Alphabetizing 1</1/>
<BODY>
< ?php

/* ,
"list.html". */
$Array = explode (" ", $List);

sort ($Array);

9 $NewList = implode ("<BR>", $Array);


10 print ("An alphabetized Aversion of your list is:<BR>$NewList");
11 ?>
12 </BODY>
13 </HTML>

**
Enter the words you want alphabetized with each individual word separated by a space:
JHichael Liz Jude Bruce Nicole Hike Benate Adam Ben Haija John Rebecca
SgbraW I

...W jig. JOB....

. 7.6 HTML- , HandleList.php (. 7.7)

. 7.7 , . ,
j oin ( ) , , implode ().
, -. , .


-.
PHP-
HTML-. ,
. 3,
.

HTML-
1. HTML- .
2. HTML-.
<HTMLxHEADxTITLE>HTML Form</TITLEx/HEADxBODY>
3. HTML-.
<FORM-ACTIQN="HandleForm.php" METHOD=POST>

4. .
First Name <INPUT TYPE=TEXT NAME="Array[FirstName]" SIZE=20xBR>
Last Name <INPUT TYPE=TEXT NAME="Array[LastName]" SIZE=40xBR>
' ' E-mail Address <INPUT TYPE=TEXT NAME="Array[Email]" SIZE=60xBR>

, , HandleForm.php
$FirstName $LastName. $Array [$FirstName],

$Array [$LastName] ..,


.
( $ Array [" $LastName" ]),
.
5. .
Comments <TEXTAREA NAME="Array[Comments]" ROWS=5 COLS=40>
-</TEXTAREAxBR>

6. form.html ( 7.8) .
7.8 * HTML- . , Array [ ], Array [ 0 ], Array [ 1 ], - Array [2 ] Array [3].
1 <HTML>
2
<HEAD>
3
<TITLE>HTML Form</TITLE>
4
</HEAD>
5 <BODY>
6 <FORM ACTION="HandleForm,php" METHOD=POST>
7 First Name <INPUT TYPE=TEXT NAME="Array[FiratName] SIZE=20xBR>
8
Last Name <INPUT TYPE=TEXT NAME="Array[LastName]" SIZE=40xBR>
9
E-mail Address <INPUT TYPE=TEXT NAME="Array[Email]" SIZE=60xBR>
10 Comments <TEXTAREA NAME="Array[Conments]" ROWS=5 COLS=40>
</TEXTAREA><BR>
11 <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
12 </FORM>
13 </BODY>
14 </HTML>

HandleForm.php
, form.html.
7. PHP- .
8. HTML-, -.
<HTMLxHEADxTITLE>Form Results/Using

Arrays</TITLEx/HEADxBODYx?php

9.
.
$Array["Name"] = $Array["FirstName"] . " " . $Array["LastName"];

, - .
10. ,
.
print

( " Y o u r f u l l name is $ A r r a y [ N a m e ] . < B R > \ n " ) ;

11. HandleForm.php ( 7.9),


form.html (. 7.8-7.10).
7.9 , HTML-
, .
, .
1
2

<HTML>
<HEAD>

4
5

<BODY> .
<?php

<TITLE>Form Results/Using Arrays</TITLEx/HEAD>

/* ,
"form.html". */
7 $Array["Name"] = $Array["FiretName"] . " " . $Array["lAstName"] ;
8 print ("Your full name is $Array[Name].<BR>\n");
9 ?>
10 </BODY>
11 </HTML>

. 7.8 form.html,

LMtNme|ii
E-mauAddren
|phJ>8DHCinsi!!ht..
Nov I ' m ualna arrty* foe tarn input

. 7.9 ,
,
. , ,

'

Your { name is Lany UDmaa

. 7.10 (. 7.9)
, HandleForm.php
HTML- ,
.


. , , , .
, .
, . :
$Arrayl = array("apples", "bananas", "oranges");
$Array2 = array("steaks", "hamburgers", "pork chops");
$List = array("fruits"=>$Arrayl, "meats"=>$Array2,
-*"other"=>"peanuts", "cash" => 3 0 . 0 0 ) ;
$List (peanuts), (30.00) (fruits meats).
,
. . bananas :
$ L i s t [ " f r u i t s " ] [1].

'

( $Arrayl) $List [" fruits" ]. . , , [1].



array ( ) . ,

, .
,
, .
. . 4.0 :
print ( " T h e value I want to print is { $ A r r a y [ i n d e x l ] [ i n d e x 2 ] } . " ) ; .
,
print ("The value I-want to print is $ A r r a y [ i n d e x l ] [ i n d e x 2 ] . " ) ;
.

, : -,
, -, ,
. ,
, . , .
, ^ , .


, ,
, . ,
. .

. ,
( ).
, , - . , .

.
, .
,
BBEdit Macintosh, TextPad Windows
Emacs UNIX,

(. 8.1). ,
, ,
.
,
,
Perl.
Perl, , .

. 8.1 Find

( ), Use Grep.
BBEdit
. ,


,
, . .
Perl, Java. , .
, , , . , , . , .

, - .
, , . ,
, ab - ab ..
, , , (

, . 5).
, (. ).

, , . , . ,
, , (.), (, 1, % ..). ,
: , , print ( ) .
, , ( ), \ ..
, : * (, ,
..); + (, , ..,
); ? . . , , . (*, +, ?)
, -.

({}), , , . , {3}
; {3 ,} - , .. ( ); {3 , 5} - ,
( ).
( , , 6) ,
. ,
.
($) ,
.
, .

( ) ,
, Enter. ,
. , , .$ - , . , ~$
, .

(|)
. , I b
, gre I ay
(- grey, gray ).
.
, . , .
: {3} { 3 , } - { , 3 } .
(". [ ] $ ( ) I * ? {} \)
.
( ).

(\), (\t) . ,
.
. .2 ( ) , .


, : ( ) eregi ( ) . , ( ) , a eregi () - ,
.' ,
eregi ( ) , (, , ).
, ,
.
:
ereg("pattern", " s t r i n g " ) ;

$Pattern = "pattern";
$String = " s t r i n g " ;
eregi($Pattern, $String);

, ,
.

HandleForm.php,
form.html ( 7). HandleForm.php ( 8.1).
8.1 form.html , , .
1
2
3
4
5
6
7
8
9
10
11
12
13
14

<HTML>
.
<HEAD>
<TITLE>HTML Form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="HandleForm.php" METHOD=POST>
First Name <INPUT TYPE=TEXT NAME="Array[FirstName]" SIZE=20xBR>
Last Name <INPUT TYPE=TEXT NAME= "Array [LastName] " SIZE=40xBR>
E-mail Address <INPUT TYPE=TEXT NAME="Array[Email]" SIZE=60xBR>
Comments <TEXTAREA NAME="Array[Comments]" ROWS=5 COLS=40>
</TEXTAREAxBR>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</FORM>
</BODY>
</HTML>


eregi
1. HandleForm.php .
2. HTML .
<HTML>
<HEAD>
<TITLE>Using Regular Expressions</TITLEx/HEAD>
<BODY>
<?php
/* ,
"form.html". */

'

3. .
if (($Array["FirstName"]) AND ($Array["LastName"])) {
$Array["Name"] = $Array["FirstName"] . " ". $Array["LastName"];
} else {
print ("Please.enter your f i r s t and last names.<BR>\n");

, , ,
" , . ,
, . , .
4. - .
SPattern = " . + @ . + \ . . + " ;


. , (,
).
, (.+) (@). , @,
. ,
.
, - , ( ).
5. .
if (eregi($Pattern, $ A r r a y [ " E m a i l " ] ) ) {
print ("Your information has been received!<BR>\n");
} else {
print ("Please enter a valid email a d d r e s s ! \ n " ) ;

eregi ( ) , , $ [" Emai 1" ] form.html. ,


. .
,
eregi ( ) , ereg ( ) .
6. ( 8.2), (. 8.2-8.4).
8.2 * , HTML-, .
1
2

<HTML>
<HEAD>

12
13
14
15
16
17
18
19
20

$Pattern = *.+.+\..+"j
if (eregi($Pattern, $Array["Email"])) {
print ("Your information has been received!<BR>\n");
} else {
print ("Please enter a valid email address!\n");
}
?>
</BODY>
</HTML>

3
4
5
6

<TITLE>Using Regular Expressions</TITLEx/HEAD>


<B0DY>
<?php
/* ,
"form.html". */
*
7 if <($Array["FirstName"]) AND ($Array["LastName"])) {
8
$Array["Name"] = $Array["FirstName"] . " ". $Array["LastName"];
9 } else {
10
print ("Please enter your first and last names.<BR>\n");
11 }

TMting rteular txpt**slon on

. 8.2 form.html HandleForm .php


(. 8.3)

Your a&raution hu been received!

. 8.3 HandleForm.php
,
. . 8.4

inter > ddrtiil

. 8.4 ,

php@DMCinsights



, ( ),
, .

eregi (). , , :
if (eregi ( " , + @ . + \ . . + ", $Array[ " E m a i l " ] ) ) {...
, , - JavaScript
. , .


, ,
, .

. : (abc) abc, (trout) - trout. , abc


abc. , , .
, - .
, - ,
, (abc) - , abc.
, , ( *
, ), , . , {3} , (abc) {3} abcabcabc.
: + ,
bon, (,
bonnet). ()+ ,
bon, bon (bonbon, ).
,
.
, yes Ino yeso
( s , ), (Yes) I (No)
.

, , .
, ,
? ( - ).
() ( [ ] ). , [ aeiou ] .
, : [a-z] -
, [A-Z] - , [A-Za-z] - , [ 0 - 9 ] - . ,

, , [a-z ] { 3 } 3
: abc, ..
,
, , ,
, . , . , [ ]
, , [ 0- ] . , : [ \ ] ?
, , .
, : [ [ : alpha : ] ] ( [A-Za-z ] ), [ [ : digit : ] ] - ( [0-9]), [[ :alnum: ] ] - (, [A-Za-zO-9]).
,
(. . . ), .


,
. , , .
, . ,
.
, , (
).
,
. ,

( 4 ,
). , , , .
:
([0-9-]+)(-[0-9a-z\.-_]+)@(-[0-9a-z\.-_]+)\.([0-9a-z]+)

eregi ( ) ,
, , .
( 8.2)
.
', ( 8.3) $Pattern
. , , .
8.3 HandleForm.php
.
1
2

<HTML>
<HEAD>

<TITLE>Using Regular Expressions</TITLEx/HEAD>

<BODY>

5
6

<?php
/* ,
generated by "form.html". */

if (($Array["FirstName"]) AND ($Array["LastName"])) {

$Array["Name"] = $Array["FirstName"] . " " .


SArray["LastName"];
9 } else {
10 .- print ("Please enter your first and last names.<BR>\n");
11 }
12
13 $Pattern = "A([0-9a-z]+)([ 0-9a-z\. -_]+)<? ([0-9a-z\.-_]+)\. ([0-9a-

14 if (eregi($Pattern, $Array["Email"])) {
15
print ("Your information has been received!<BR>\n"
16 } else {
17
print ("Please enter a valid email address!\n");
18 }
19 ?>
20 </BODY>
21 </HTML>


, , .

8 v


, : ( [ 0-9 ] { 5 } ) ( - [ 0 - 9 ] { 4 } ) .
.
,
(\\), . ,
94710-0001, \ \ 1 94710, \ \ 2
-0001 (, .
, , ). .


ereg ( ) eregi ( ) , , , .
:
ereg_replace("pattern", "replace", " s t r i n g " } ;
:
$Pattern = "pattern";
$Replace = "replace";
$String = " s t r i n g " ;
eregi_replace($Pattern, $Replace, $String);

,
(URL) HTML, < HREF=" URL" >< />. , form.html ( 8.1) HandleForm.php ( 8.3).


eregi_replace
1. form.html . form.html , URL .
2. 9 ( 8.4), ,
:
URL <INPUT TYPE=TEXT NAME="Array[URL]" SIZE=60xBR>

8.4 form.html,
URL, .
1
2

<HTML>
<HEAD>


3
<TITLE>HTML Form</TITLE>
4
</HEAD>
5
<BODY>
6 <FORM ACTION="HandleForm.php" METHOD=POST>
7 "First Name <INPUT TYPE=TEXT NAME="Array [FirstName] " SIZE,=20xBR>
8
Last Name <INPUT. TYPE=TEXT NAME="Array[LastName]" SIZE=40xBR>
9 TOL <INPTJT TYPE=TEXT NAME= "Array [URL] " SIZE=60xBR>
10 Description <TEXTAREA NAME="Array[Description]" ROWS=5 COLS=40></
TEXTAREAxBR>
11 <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
12 </FORM>
13 </BODY>

3. 10 :
Description <TEXTAREA NAME="Array[Description]" ROWS=5 COLS=40>
</TEXTAREAxBR>

4. .
HandleForm.php.
5. HandleForm.php ( 8.3).
6. 12 :
$Pattern = " ( h t t p : / / ) ? ( [ [ : : ] ] + ) ( [ [ : a l n u m : ] \ . , - _ ? / & = ] ) " ;

, URL. , , ,
URL .
: http://, URL
URL. URL http://, . http, .
, .
URL , : ,
, , , .. ,
- , .
URL .com/php/.
7. :
$Replace = "<a h r e f = \ " h t t p : / / \ \ 2 \ \ 3 \ " t a r g e t = \ " _ n e w \ " > \ \ 2 \ \ 3 < / a > " ;

. .
http:// , - ( ,
\\1 ) http://,

. < href=,
URL,
HTML- </>.
8. $Array["URL"] = eregi_replace($Pattern, $Replace, $Array["URL"]) ;

. ,
. URL ,
, . ,,
.
9. print "Your submission$Array[URL]-has been received!<BR>\n");
, if. , ( 8.5) (. 8.5-8.7).
,
URL, . Web-.
8.5 eregi_replace ( ) URL JB .
.
1
2

<HTML>
<HEAD>

<TITLE>Using Regular Expressions</TITLE'x/HEAD>

4
5

<BODY>
<?php

/* ,
"form.html". */
7 if (($Array["FirstName"]) AND ($Array["LastName"])) {
8
$Array["Name"]'= $Array["FirstName"] . " " . $Array["LastName"];
9 } else {
10
print ("Please enter your first and last names.<BR>\n");
11 }
12 $Pattern = "(http://)?([A[:space:]]+)([[:alnum:]\.,-_?/=])";
13 $Replace = "<a bref=\"http://\\2\\3\" target=\"_new\">\\2\\3</a>";
14 $Array["URL"] = eregi_replace($Pattern, $Replace, $ Array ["URL"]) ,

15 print ("Your submission-$Array[URL]-has been received!<BR>\n" );


16 ?>
17 </BODY>
18 </HTML>

UitNme|oun

DM.
|VW.DKClnaight9.can/php/
Deicription Tracing cegulr expressions on uftL's.

. 8.51 form.html
URL, (. 8.6)

Your mbiQtfnoo--www,DMCin3igh.com/phD/"hm been received!

. 8.6 eregi_replace ()
URL ( http:// )

Ion<* hra<''httr://v < n'.DHCin8igh<:9.c9tn/rhp/'' target-" nr<*">vvv.DKCin3ights.coin/php/</>has beea cceived!<BM>

. 8.7 HTML- < HREF>,


URL

, , . ,
(phpinf ( ) , count ( ) , eregi_replace ()), , .
. ,
, .
. , , Web-.
, .
, , .


, . , , .
,
, print ( ) .
:
function FunctionName ()
statement(s);

, , . $ .
, (, CreateHeader - , Functionl). , ,
5 , (
: Create_Header - ).
, ,
PHP-, . ,
.
, ,
. ,
. : function, , , .
, . , ( ), .
, , ,
. FunctionName ( ) ; .
( 5)
.


1. passwords.php ( 9.1).
9.1 ,
. , .
1
2
3
4
5

<HTML>
'
<HEAD>
<TITLE>Password Generator</TITLEx/HEAD>
<BODY>
<?php

$String = "This is the text which will be encrypted so that we may


create random and secure passwords!";
7 $Lerigth = 8; // , .
32 - .
8 $String = md5($String);
9 $StringLength = strlen($String);
10 srand ((double) microtimeO * 1000000);

9
11 $Begin = rand(0,($StringLength-$Length-l)); // Pick an arbitrary
starting point.
12 $Password = substr($String, $Begin, $Length);
13 print ("Your recommended password is:<PxBIG>$Password</BIG>\n");
14 ?>
15 </BODY>
16 </HTML>

2. HTML- <?php.
, ( 3.x), ,
HTML-.
3. function CreatePassword () {
CreatePassword. .
4. PHP- ( 6-13) passwords.php . , , ( 9.2).
$String = "This is the text which will be encrypted so
that we may create random and secure passwords!";
$Length = 8 ; - / / , .
32 - .
$String = md5($String);
$StringLength = strlen($String);
srand ((double) microtimeO * 1000000);
$Begin = rand(0,($StringLength-$Length-l)); // Pick an
".
$Password = substr($String, $Begin, $Length);
print ("Your recommended password is:
<PxBIG>$Password</BIGxP> \n") ;
5. (}).
- , .
6. PHP- ?>.
PHP- , HTML-.

print ( ) . .
7. HTML-.
<HTMLxHEADxTITLE>Password Generator within a Function</TITLEx/HEAD>
-<BODY> -


8. PHP- <?php.
HTML- PHP-, .
9. CreatePasswordO ;
, ( ). .
10. ?></BODYx/HTML>
PHP- .
11. , ( 9.2)
(. 9.1).
9.2 ' -
. .
.
1 <?php
2 function Creatsword () {
3
$String = "This is the text which will be encrypted so that we may
create random and secure passwords!";
4
$Length = 8 ; // ,
. 32 - .
5
$String = md5($String);
6
$StringLength = strlen($String);
7
srand ((double) microtimeO * 1000000);
8
$Begin rand(0,($StringLength-$Length-l)); // Pick an arbitrary
starting point.
9
$Password = substr($String, $Begin, $Length) /
10
print ("Your recommended password is: <P><BIG>$Password</BIGxP>
\n") ;
11 } // CreatePassword.
12 ?>

13
14
15
16
17'
18

<HTML>
<HEAD>
<TITLE>Password Generator within a Function</TITLEx/HEAD>
<BODY>

<?php
CreatePasswordO; / .

19 ?>

20 </BODY>
21 </HTML>
PHP 3.x, , . 4.0 , . .

Your recommended password is:

. 9.1 password. , , . , ,

, ,
. ,
createpassword CreatePassword.

,

, , , ,
, - . , , . ,
, .
: print () ,
.
-, , :
function FunctionName ($Argumentl, $Argument2 . . )
statement(s);
}

,
, , . ,
-, , . , . :
FunctionName ($Variablel, $Variable2 . ) ;
:
FunctionName ( " V a l u e l " , "Value2" . ) ;

:
FunctionName ($Variablel, "Value2" . ) ;
:
,
, - .. .
, .
, , null. , , . ,
, - .
, ,
hello.php ( 6). ,
, - .


1. hello.php ( 9.3).
9.3 hello.php
.
1
2
3
4

<HTML>
<HEAD>
<TITLE>If-elseif Conditionals</TITLEx/HEAD>
<BODY> '

5 <?php
6 if ($Username) {
7
print ("Good ");
8
if (date("A") == "AM") {
9
print ("morning, ") ;
10
} elseif ( ( dateC'H") >= 12 ) and ( date("H") < 18 ) ) {
11

print ("afternoon, ");

12
13
14

} else {
print ("evening, ");
} // if .

15
16

print ("$Username");
print ("!\n");

17 } else {
18
print ("Please log in.\n");
19 } // if .

20 ?>

21 </BODY>
22 </HTML>

2. PHP- <?php, 7-16


( 9.3) .
function GreetUser ($TheUser) {
print ("Good " ) ;

9 *
if (date("A") == "AM") {
print ("morning, ");
} elseif ((date("H")>12) and (date("H")<18)) {
print ("morning, ") ;
} else {
print ("evening, " ) ;
} // if ,
print ("$TheUser");
print ( " ! \ n " ) ;
} // GreetUser.

. ,
. $TheUser $Username,
(. 21 9.4).
3. PHP- HTML-.
?xHTMLxHEADxTITLE>The GreetUser Function-:/TITLEx/HEADxBODY>
4. PHP- i f else, .
<?php
if ($Username) {
GreetUser ($Username); // .
} else {
print ("Please log i n . \ n " ) ;
} // if .,
if ($Username) ,
, , $Username.
5. HTML.
?></BODYx/HTML>
6. ( 9.4), (. 9.2). , URL HTML-. , ,
. 9.3.
9.4 , , . ,
$Username .
1
2
3
4
5
6

<?php
function GreetUser ($TheUser) {
print ("Good ");
i'f (date("A") == "AM") {
print ("morning, ") ,} elseif ((date("H")>12) and (datef"H")<18)) {

,
7
print ("morning, ");
8
} else {
9
print ("evening, ");
10
} // if .
11
print ("$TheUser");
12 - print ("!\n");
13 } // GreetUser.

14 ?>
15
,16
17
18
19
20
21
22
23
24

<HTML>
<HEAD> '
<TITLE>The GreetUser Function</TITLEx/HEAD>
<BODY>
'

.
<?php
if ($Username) {
. GreetOeer ($Useniame); // .
} else {
print ("Please log in.\n");
} // if .

25 ?>
26 </BODY>
27 </HTML>
13 ,
( ).
- , GreetUser.
.
,
, . ,
.

Good morang. Linyt *

. 9.2
, hello.php,

jfc LocetiotJhltp:Mww.DMCmi8M*.com/p*ip/heio p^
Please lo{

. 9.3 , .
,
hello.php ( . 9.2)

,

, .
- , . : -,
return; -, -
. , ,
, .
, :
function FunctionName ($Argument) {
statement(s);
return $Vaiue;
}
:
$Value = FunctionName($Variable);

, . numbers.php ( 4, - 6).


1. numbers.php ( 9.5).
9.5 numbers.php ( 6).
, .
1

<HTML>

<HEAD>

<TITLE>Conditionals</TITLE>

4
5

</HEAD>
<BODY>

6
7

<?php

/* $Quantity .
$Discount . */

$Cost =20.00;

$ = 0.06;

10 if ($Quantity) {
11
$Quantity = abs($Quantity);
12
$Discount = abs($Discount);
13
Tax++; // $Tax 1.06.
14
$TotalCost = ($Cost * $Quantity);
15
if ( ($TotalCost < 50) AND ($Discount) ) {
16
print ("Your \$$Discount will not apply because the total value
of the sale is under $50!\n<P>");
17
}

,
18. . if ($TotalCost >= 50) {
19
$TotalCost = $TotalCost - $Discount;
20
}
21
$TotalCost = $TotalCost * $Tax;
22
$Payments = round ($TotalCost, 2) / 12;
23
// .
24
print ("You requested to purchase $Quantity widget(s) at \$$Cost
each.\n<P>");
25
print ("The total with tax, minus your \$$Discount, comes to $");
26
printf ("%01.2f", $TotalCost);
27
print (".\n<P>You may purchase the widget(s) in 12 monthly
installments of $");
28
printf ("%01.2f", $Payments);
29
print (" each.\n<P>");
30 } else {
31
print ("Please make sure that you have entered both a quantity and
an applicable discount and then resubmit.\n");}
32 ?>
33 </BODY>
34 </HTML>

2. PHP- CalculateTotal ( ) ,
14-21 .
<?php
function CalculateTotal ($HowMany, $Price, $TaxRate, $Savings) {
$TaxRate++; // $TaxRate is now worth 1.06.
$TheCost = ($Price * $HowMany) ;
if ( ($TheCost < 50) AND ($Savings) ) {
print ("Your \$$Savings will not apply because the total value
-of the sale is under $50!\n<P>");
if ($TheCost >= 50) {
$TheCost = $TheCost - $Savings;
$TheCost = $TheCost * $TaxRate;
return $TheCost;

^^

( (), , ), .
3. .
function CalculatePayments ($Amount, $NumberPayments) {
$Payments = round($Amount, 1} I $NumberPayments;
$Payments = sprintf ("%01.2f", $Payraents);
return $Payments;
}
CalculatePayments ( ) -
- . ,
numbers.php.
sprintf ( )
$Payments. 4, ,
print f ( ) , ,
, . , sprintf ( ) $Payments.
: -, ,
, - ; -, ,
.
4. PHP- HTML-.
?><HTMLxHEADxTITLE>Calculation Functions</TITLEx/HEADxBODY>

5. PHP- .
<?php
$Cost = 20.00;
$ = 0.06;

$Cost,
,
$.
6. -.
if ($Quantity) {
$Quantity = abs($Quantity),-.
$Discount = abs($Discount);
$TotalCost = CalculateTotal ($Quantity, $Cost,$Tax, $Discount);
// .
print ("You requested to purchase $Quantity widget(s)
'-at \$$Cost each.\n<P>");
print ("The total with tax, minus your \$$Discount, comes to $");

,
printf ("%01.2f", $TotalCost) ;
print (".\n<P>You may purchase the widget (s) in 12
monthly installments of $");
print (CalculatePayroents($TotalCpst, "12"));
print (" each.\n<P>") ;
} else {
.
print ("Please make sure that you have entered both a
quantity and an applicable discount and then resubmit . \n" ) ;
}

v ,


, 6. , . , .
31 , CalculateTotal ( ) , 37
CalculatePayments ( ) .
7, PHP- HTML.
?></BODYx/HTML>

8. ( 9.6) , (. 9.4). ( , ), URL


HTML-. , Please make sure,
40. .
9.6 .
CalculateTotal ( ) . CalculatePayments ( )
.
2
3
4
5
6
7
8
9
10

function CalculateTotal ($HowMany, $Price, $TaxRate, $Savings) {


$TaxRate++; // $TaxRate is now worth 1.06.
$TheCost = ($Price * $HowMany) ;
if ( ($TheCost < 50) AND ($Savings) ) {
print ("Your \$$Savings will not apply because the total value
of the sale is under $50 ! \n<P>" ) ;
}
if ($TheCost >= 50) {
$TheCost = $TheCost - $Savings;
}

11

$TheCost = $TheCost * $TaxRate;

12

return $TheCost;

16
17

$Paymente = eprintf ("%01.2f", $Payments) ;


return $Paymente;

13 } // CalculateTotal.
14 function CalculatePayments (SAmount, $Number Payments) {
15
$Payments = round<$Amount , 2) / $Number Payments;
18 } // CalculatePayments.

19 ?>
20 <HTML>
21 <HEAD>

22 <TITLE>Calculation Functions</TITLE>
23
24
25
26
27

</HEAD>
<BODY>
<?php
$Cost = 20.00;
$Tax = 0.06;

28 if ($Quantity) {
29
$Quantity = abs($Quantity);
30
$Discount = abs($Discount);
31
$TotalCoet = CalculateTotal ($Quantity, $Coet, $Tax, $Diecount);
32
// .
33
print ("You requested to purchase $Quantity widget(s) at \$$Cost
each.\n<P>");
.
34
print ("The total with tax, minus your \$$Discount, comes to $");
35

printf ("%01.2f", $TotalCost);

36

print (".\n<P>You may purchase the widget(s) in 12 monthly


installments of $");
print (CalculatePayments($TotalCoet, "12"));
print (" each.\n<P>");

37
38

39 } else {

40

print ("Please make sure that you have entered both a quantity and
an applicable discount and then resubmit.\n");
41 } .
42 ?>
43 </BODY>
44 </HTML>

CalculatePayments () sprintf ()
printf (), return, .
, , .

You requested to purchase ^ widget(s) at S20 each.


The total with tax. minus your $10, comes to $74 20.
You may purchase the widget(s) in 12 monthly installments of $6.18 each.

. 9.4 ,
,
.
,


return ,
return. , ,
. :
if () {
return TRUE;
} else {
return FALSE;

, , , .
return . . ,
, .


2 ,
. ,
.



, , , .. ,
. global. , . - ,
. , , , . , ( SOSTYPE) .
, . - , , - . , .
, global. : , ,
. ,

.
, ( , ), return.
global :
function FunctionName (SArgument) {
global $Variable;
statement(s);
, . , ,
(, , ). FunctionName ($Valuel) ,-,
FunctionName ($Argumentl).
$Argumentl $Valuel,
.
$Argumentl , $Valuel.
, :
. - , - . , ,
.
,
.
( ),
, . ,
, . :
. ,
global, , .

global
1. numbers.php ( 9.6).
2. $Price $TaxRate CalculateTotal, 2 :
function CalculateTotal ($HowMany, $SavingsT {
$Price $TaxRate $Cost $
global,
.
3. .
global $Cost;
global $Tax;

$Cost $,
.
4. , $Price
$Cost, $TaxRate $, a $TheCost $TotalCost.
$++; // $ 1.06.
*
$TotalCost ~ ($Cost * $HowMany);
if ( ($TotalCost < 50) AND ($Savings) ) {
print ("Your \$$Savings will not apply because
the total value of the sale is under $50!\n<P>");
}
if ($TotalCost >= 50) {
$TotalCost = $TotalCost - $Savings;
}.
$TotalCost = $TotalCost * $Tax;
return $TotalCost;
, .
, $TheCost
$TotalCost. , $TotalCost - , , .
5. , $ = 0.06; ( 29),
.
.
print ("The tax value is currently \$$Tax .\n<P>");

, global
,
$ .
6. CalculateTotal ( ) ,
$ $Cost .
$TotalCost = CalculateTotal ($Quantity, $Discount);

- ,
.
7. $.
print ( " A f t e r calling the function,
-is now \$$Tax .\n<P>");

the tax value

global, ,
, . , $
, .
8. ( 9.7), (. 9.5). ( , ), URL
HTML-.

9
9.7 CalculateTotal $Cost $,
global. , -
.
1
2
3
4

<?php
function CalculateTotal ($HowMany, $Savings) {
global $Cost;
global $Tax;

$Tax++; // $Tax 1.06.

$TotalCost = ($Cost * $HowMany);

7
8
9
10
11
12
13
14
15
16
17
18
/19
20

if ( ($TotalCost < 50) AND ($Savings) ) {


print ("Your \$$Savings will not apply because the total value
of the sale is under $50! \n<P>" ) ;
}
if ($TotalCost >= 50) {
$TotalCost = $TotalCost - $Savings;
}
.
.
$TotalCost = $TotalCost * $Tax;
return $TotalCost;
} // CalculateTotal.
function CalculatePayments ($Amount, $NumberPayments) {
$ Payments = round ($ Amount , 2) / $Number Payments;
$Payraents = sprintf ("%01.2f", $Payrnents);
return $Payments;
} // CalculatePayments.

21 ?>
22 <HTML>
23 <HEAD>

24 <TITLE>Calculation Functions</TITLE>
25
26
27
28
29
30

</HEAD>
<BODY>
<?php
$Cost = 20.00;
$Tax = 0.06;
print ("The tax value IB currently \$$Tax . \n<P>n);

31 if ($Quantity) {
32
33

$Quantity = abs ($Quantifey) ;


$Discount = abs($Discount) ;

34

$TotalCost = CalculateTotal ($Quantity, $Discount);

35

print ("After calling the function, the tax value is now \$$Tax

36
37
38

// .
print ("You requested to purchase $Quantity widget (s) at \$$Cost
each.\n<P>") ;
print ("The total with tax, minus your \$$Discount, comes to $");

39

printf ("%01.2f", $TotalCost);

40

print (".\n<P>You may purchase the widget (s) in 12 monthly


installments of $");
41
print (CalculatePayments ($TotalCost, "12"));
42
print (" each.\n<P>") ;
43 } else {


44

print ("Please make sure that you have entered both a


and an applicable discount and then r e s u b m i t . \ n " ) ;

quantity

45 }
46 ?>

47 </BODY>
48 </HTML>

The tax value ii currently $0.06


After calling the function, the tax value is now 51.06 .
You requested to purchase A widget(s) at $20 each.
The total with tax, minus your $10, comes to $74.20.
You may purchase the widget(s)in 12 monthly installments of $6.18 each.

. 9.5 $ - , $ ( global),


.
, ,

. ,
, .
CalculatePayments ( ) ( 9.7).
12 , :
function CalculatePayments ($Amount, $NumberPayments = " 1 2 " ) {

CalculatePayments ($Amounts) ; , CalculatePayments ($Amounts, " 2 4 " ) ; $NumberPayments , 12, , 24.


,
, . ,
(
). , . ,

( , , , ). ,
. ,
:
function CalculateTotal ($HowMany, $Price = "20.00", $TaxRate = " 0 . 0 6 " ) {
:
CalculateTotal (3, "0.07");
$HowMany 3, $ Price 20.00 $TaxRate
0.07. , . $HowMany 3, $Price - 0.07, a $TaxRate 0.06. ,
.
:
CalculateTotal (3, "20.00", "0.07");
, , numbers.php ( 9.7).

,

1. numbers.php ( 9.7).
2. $ Savings
CalculateTotal ( ) .
function CalculateTotal ($HowMany, SSavings = "0") {
3. 0 $Savings. , , . , 12 $NumberPayments.
function CalculatePayments ($Amount, $NumberPayments = "12") {
CalculatePayments (( ,
$NumberPayments .
4. *
$. .
5. CalculatePayments ( ) ,
.
print (CalculatePayments($TotalCost));
CalculatePayments
$TotalCost , $NumberPayments .


$NumberPayments, , .
6. ( 9.8), (. 9.6). ( , ), URL
HTML-.
9.8 numbers.php.
.
1 <?php
2 function CalculateTotal ($HowMany, $Savinge = "0") {
3
global $Cost;
.4
global $Tax;
5
$Tax++; // $Tax 1.06.
6
$TotalCost = ($Cost * $HowMany);
7
if ( ($TotalCost < 50) AND ($Savings) ) {
8
print ("Your \$$Savings will not apply because the
value of the sale is under $50!\n<P>");
9 ' }
10
if ($TotalCost >= 50) {
11
$TotalCost = $TotalCost - $Savings;
12
}
13
$TotalCost = $TotalCost * $Tax;
14

total

return $TotalCost;

15 } // CalculateTotal.
16 function CalculatePayments ($Amount, $NumberPayments = "12") {
17

18
19
20
21
22
23
24
25
26
27

$Payments = round($Amount, 2) / $NumberPayments;

$Payments = sprintf ("%01.2f", $Payments);


return $Payments;
} // CalculatePayments.
?>
<HTML>
<HEAD>
<TITLE>Calculation Functions</TITLE>
</HEAD>
<BODY>
<?php

28 $Cost = 20.00;
29 $Tax =0.06;

30 if ($Quantity) {
31
$Quantity = abs($Quantity);
32

$Discount = abs($Discount);

33
34
35

$TotalCost = CalculateTotal ($Quantity, $Discount);


// .
print ("You requested to purchase SQuantity widget(s) at \$$Cost
each.\n<P>");
print ("The total with tax, minus your \$$Discount, comes to $");

36
37

38,
39

printf ("%01.2f", $TotalCost);

print (".\n<P>You may purchase the widget(s) in 12 monthly


installments of $");
print (CalculatePayments($TotalCost));

9
40
print (" each.\n<P>");
41 } else {
42
print ('"Please make sure that you have entered both a quantity
and an applicable discount and then resubmit.\n");

43 }
44 ?>

45 </BODY>
46 </HTML>

You requested to purchue 4 widget(s) at $20 each.


Tne total with tax. iraius your , conies to 74.20.
You may purchase the widget(s) in 12 monthly installments of $6.18 each.

. 9.6 ,
,
, , ,
( . 9.4),

.
, ,
. , , ,
, . .
. , , , , . ,
. ,
f,
$fHowMany SfTaxRate. $gVariable. , .

Web- ,
.
: ( )
. , - .
, , .
: -,
( ), -, ,
- . , ,
, , , ,
.
, , , ,
HTML- (, ..).


. ,
, . , . ,
, .
,
. , : , , (

10

, , ). ,
, , ,
, ( ),
.

, - . - , , , (
Perl , , ).
,
.
,
data.txt, .
(, )
.
, , (. 10.1).
data.txt.
!*.*" 5 &*
Warning: fopen("data ba'.V) - permission denied
/php/clO/Han<UtFonn.ph]> online 5
Your submission was not processed due to a systerQ error)

. 10.1 ... , .
f open ( ) ,

data.txt
:
1. .
2. data.txt, .
3. .
. , , , . , Web- .

. -

data.txt ( ).
, . ,
:
> Web. ,
;
> , Telnet , data.txt,
chmod ( UNIX)
(. 10.2);
> -
(. 10.3);
> Windows NT, , , , .
* clwod 8666 data.txt
* Is -I

-rw-rw-rw- ul Inan 37S

data.txt

. 10.2 chmod
0666 data, txt Telnet
,
data.txt, . ,
Is -1. , * ,
- ullman, - 375

. 10.3
Windows Commander

chmod, , 0666 (. 10.2). ,


. - , , (4)
(2). - , - , . : 0777 (4), (2) (1). UNIX (Linux, Solaris).


, .
: ,
, . ,
:
$FileName = " d a t a . t x t " ;

$FilePointer = fopen ($FileName, "mode");

10
fwrite ($FilePointer, "data to be w r i t t e n " ) ;
fclose ($FilePointer);

, ,
. ,
(, files, , : files/data.txt).
, $FilePointer .
( mode). ,
. - +.
. , , .
. .4 ( ) .
fwrite () ,
, . .
, , .
,
URL .


1. form.html ( 8) ( 10.1).
10.1 form.html. , (. 10.2).
1
2

<HTML>
<HEAD>

<TITLE>HTML Form</TITLE>

4
</HEAD>
5
<BODY>
6
<FORM ACTION="HandleForm.php" METHOD=POST>
7
First Name <INPUT TYPE=TEXT NAME="Array[FirstName]" SIZE=20xBR>
8 Last Name <INPUT TYPE=TEXT NAME="Array[LastName]" SIZE=40xBR>
9
URL <INPUT TYPE=TEXT NAME="Array[URL]" SIZE=60xBR>
10 Description <TEXTAREA NAME="Array[Description]" ROWS=5 COLS=40>
</TEXTAREAxBR>
"
"
11 <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Sutomit!">
12 </FORM>
13 </BODY>
14 </HTML>

,
, .
2. ( 10.2).


10.2
form.html, . ,
, - Array [URL]
Array [Description] .
1
2
3
4
5
6
7
8
9

<HTML>
<HEAD>
<TITLE>HTML Form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="HandleForm.php" METHOD=POST>
URL <INPUT TYPE=TEXT NAME="Array[URL]" SIZE=60xBR>
Description <TEXTAREA NAME="Array[Description]"ROWS=5 COLS=40>
</TEXTAREA><BR>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!"> .

10 </FORM>
11 </BODY>
12 </HTML>

3. .
HandleForm.php.- ,
form.html.
4. PHP- .
5. .
<?
function WriteToFile ($URL, $Description) {
WriteToFile ( ) ( URL ) , form.html.
6. .
$TheFile = "data.txt";
$0pen = fopen ($TheFile, " a " ) ;

( , ,
). data.txt
(. ), .
7. fopen ( ) .
if ($0pen) {
fwrite ($0pen, "$URL\t$Description\n");
fclose ($0pen);
$Worked = TRUE;
} else {
$Worked = FALSE;
, . : URL, (
" t - \t), (
\). .

10

8. $worked .
return

$Worked,-

} / / WriteToFile.
, $Worked , .
9. PHP- HTML-.
<HTMLxHEADxTlTLE>Using Files</TITLEx/HEADxBODY>

10. -.
<?php

11. :
$Pattern = " ( h t t p : / / ) ? ( [ A [ : s p a c e : ] ] + ) ( [ [ : a l n u m : ] \ . , - _ ? / & = ] ) " ;

URL, .
12. .
if (eregi($Pattern, $Array["URL"])) {
$Replace = "<a h r e f = \ " h t t p : / / \ \ 2 \ \ 3 \ "
-target=\"_new\">\\2\\3</a>";
$Array["URL"] = eregi_replace($Pattern,
-$Replace, $Array["URL"]);
$CallFunction = WriteToFile ($Array["URL"],
$Array["Description"]);
URL ,
eregi_replace ( ) . WriteToFile ( ) .
13. .
if ($CallFunction) {
print ("Your submission-$Array[URL]-has
been received!<BR>\n");
} else {
print ("Your submission was not processed
due to a system error!<BR>\n");
$callFunction
$Worked. , $Worked , ,
$CallFunction, , - .
.

WMf

14. , HTML.
} else {

print ("Please enter a valid Web address !\n") ;

</BODYx/HTML>

15. HandleForm.php ( 10.3),


( form.html data.txt)
(. 10.4-10.6).
10.3 , .
. . -
.
1 <?php
2 function WriteToFile ($0RL, $Deecription) {
, 3 /* WriteToFile URL ,
. */
4
$TheFile . "data.txt";
5
$0pen - fopen ($TheFile, "a");
6
if ($0pen) {
7
fwrite ($0pen, "$URL\t$Deecription\n");
8
f close ($0pen);
9
$Horked - TRUE;
10
} else {
11
$Worked - FALSE;
12
}
13
return $ Worked;
14 } // WriteToFile.
15 ?>
16 <HTML>
17 <HEAD>
18 <TITLE>Using Files</TITLEx/HEAD>
19 <BODY>
20 <?php
.
.
21 /* ,
"form.html" . */
22 $Pattern = " (http: //)?( [ :space: ]]+)([[ :alnum: ] \ .,-_?/&=])";
23 if (eregi($Pattern, $Array ["URL"] ) ) {
24
$Replace = "<a href =\ "http: //\\2\\3\" target=\"_new\">\\2\\3</
a>";
25
$Array["URL"] = eregi_replace($Pattern, $Replace, $Array ["URL" ] ) ;
26
$CallPunction WriteToFile ($Array["URL"l ,
$Array [ "Description" ] ) ;
27
if ($CallFunction) {
28
print ("Your submission-$Array [URL]-has been received!<BR>\n" ) ;
29
} else {
30
print ("Your submission was not processeddue to a system
error ! <BR>\n" );

10

31
}
32 } else {
print ("Please enter a valid Web address! \n" ) ;
33
34 }
35 ?>
36 </BODY>
37 </HTML>

-has been received!

".

. 10.4 ,
Web-

: firef""http://www. PHP.net target- _new >www.PHP.net</a>


PHP home page the first site PHP programmers should bookmark"

128 byte> 1 tnes, UNIX

. 10.5
form.html HandleForm.php
data.txt
. , HTML HREF, eregi_replace ( ) ,

is_writeable ( ) .
, , . is_writeable ( ) ( ):
STheFile = " d a t a . t x t " ;
if (is_writeable ( $ T h e F i l e ) ) {
$0pen = fopen ($TheFile, " a " ) ;
Windows,
. (/). ,

c:\\php\\data.txt c:/php/data.txt, c:\php\data.txt, - . UNIX, .

< hrer-"nttp:/A*w.PHP.ner' target""_new">www.PHP.net</a>


PHP hone page the first site PHP programmers should bookmark!
<a href-"nttp://wwv.2end.com" target"_new">ww.2end.com</a>
The
Zend home page a good resource for Information on PHP4.

. 10.6 form.html
data.txt


, , ,
, . ,
. : ,
, .
$FileName = " d a t a . t x t " ;
$FilePointer = fopen ($FileName, " m o d e " ) ;
$Array = f i l e ($FileName);
fclose (SFilePointer);

f ile ( ) - PHP. . ,
. data.txt , ( 10.6,
-
), .
data.txt, - .
, .
, URL.

10


1. .
2. HTML-.
<HTMLxHEAD>

<TITLE>Storing URLs in an External File</TITLE>


</HEADxBODY>

, -.
, .
3. PHP- WriteToFile ( )
HandleForm.php ( 10.3).
<?php
function WriteToFile ($URL, $Description) {
/* WriteToFile URL ,
. */
.
'
$TheFile = " d a t a . t x t " ;
$0pen = fopen ($TheFile-, " a " ) ;
if ($0pen) {
fwrite ($0pen, "$URL\t$Description\n");
fclose ($0pen);
$Worked = TRUE;
- } else {
SWorked = FALSE;
}
.
return $Worked;
} / / WriteToFile.
- . !
4. , .
function ReadFromFile () {
/* ReadFromFile ,
-- . */
$TheFile = "data.txt";
$0pen = fopen ($TheFile, "r");
if ($0pen) {
print ("URLs currently listed in the data file:<P>\n");
$Data =. file ($TheFile);
for ($n = 0; $n < count($Data); $n++) {
$GetLine = explode!"\t", $Data[$n]);
print ("$GetLine[0]<BR>\n$GetLine[l]<P>\n");
}
fclose ($0pen),\
print ("<HRxP>\n") ;
} else {
'
print ("Unable to read from-data.txt!<BR>\n");
}
} // ReadFromFile.

, , .
, .
', SData.
- ( : URL, , ,
).
$GetLine , $Data -. explode ( )
SGetLine. ,
. ,
.
, , HTML . . , ,
.
5. ,
HTML-.
function CreateForm ( ) {
/* CreateForm , */
print ("Add a URL to the data f i l e : \ n " ) ;
print ("<FORM ACTION=\"urls.php\" METHOD=POST>\n");
print ("URL <INPUT TYPE=TEXT NAME=\"Array[URL]\"
-SIZE=60xBR>\n");

print ("Description <TEXTAREA NAME=\"Array[Description]\"


-ROWS=5 COLS=40x/TEXTAREAxBR>\n") ;

print ("<INPUT TYPE=HIDDEN NAME=\"BeenSubmitted\"


-VALUE=\"TRUE\">\n") ;

'

print ("<INPUT TYPE=SUBMIT NAME=\"SUBMIT\"


-VALUE=\"Submit! \"></FORM>\n").;
} // CreateForm.

form.html, . , ACTION urls.php. , , $BeenSubmitted


. , .
6. , ,
function HandleForm () {
global $Array;
HandleForm.php.
- $,
, global.
7. HandleForm.php
( 10.4).
$Pattern = " ( h t t p - . / / ) ? ( [ [:space:]]+) ( [ [ : a l n u m : ] \ . , - _ ? / & = ] ) " ;
if (eregi($Pattern,- $Array ["URL" ] ) ) {
$Replace = "<a h r e f = \ " h t t p : / / \ \ 2 \ \ 3 \ "

10
target=\"_new\">\\2\\3</a>";
$Array["URL"] = eregi_replace($Pattern, $Replace,
$Array["URL"]);
$CallFunction = WriteToFile ($Array["URL"],
$Array["Description"]);

if ($CallFunction) {

print ("Your submission-$Array[URL]-has


been received! <PxHRxP>\n");
} else {
print ("Your submission was not processed
due to a system error!<BR>\n");

} else {
print ("Please enter a valid Web address!\n");
} // HandleForm.
. URL, . ,
$CallFunction .
8. , , .
if ($BeenSubmitted) {
HandleForm();
ReadFromFileO ;
CreateFormO;
$BeenSubmitted (
), .
$BeenSubmitted ( , , ), HandleForm ( ) .
,
URL,
.
9. . HTML.
?></BODYx/HTML>

10. urls.php ( 10.4),


(. 10.7-10.9).
10.4 ,
: , , ( ).
, .
1
2

<HTML>
<HEAD>


3
4
5
6
7
8

<TITLE>Storing URLs in an External.File</TITLE>


</HEAD>
<BODY>
<?php
function WriteToFile ($ORL, $Deecription) {
/* WriteToFile URL ,
. */
$TheFile = "data.txt";
$0pen = fopen ($TheFile, "a");
if ($0pen) {
fwrite ($0pen, "$URL\t$Description\n");
fclose ($0pen);
$Worked = TRUE;
} else {
$Worked = FALSE;
}
return $Worked;
} // WriteToFile.

9
10
11
12
13
14
15
16
17
18
19
20
21 function ReadFromFile () {
22 /* ReadFromFile ,
. */
23
$TheFile = "data.txt";
24
$0 fopen ($TheFile, "r");
25
if ($0pen) {
26
print ("URLs currently listed in the data file:<P>\n");
27

28
29
30

$Data = file ($TheFile);

for ($n = 0; $n < count($Data); $n++) {


$GetIiine = explode ("\t" , $Data[$n]);
print ("$(3etLine[0]<BR>\n$GetLine[l]<P>\n") ;

31
}
32
fclose ($0pen);
33
print ("<HRxP>\n");
34
} else {
35
print ("Unable to read from data.txt!<BR>\n");
36
}
37 } // ReadFromFile.
38
39 function CreateForm () {
40 /* CreateForm . */
41
print ("Add a URL to the data file:\n");
42
print ("<FORM ACTION=\"urls.php\" METHOD=POST>\n");.
43
print ("URL <INPUT TYPE=TEXT NAME=\"Array[URL]\" SIZE=60xBR>\n");
44
print ("Description <TEXTAREA NAME=\"Array[Description] \" ROWS=.5
COLS=40x/TEXTAREAxBR>\n") ;
45
print ("<INPUT TYPE=HIDDEN NAME=\"BeenSubmitted\"
VALUE=\"TRUE\">\n");
46
print ("<INPUT TYPE=SUBMIT NAME=\"SUBMIT\" VALUE=\"Submit!\">
</FORM>\n");
47 } // CreateFortn.
48.
49 function HandleForm () {
50
global $Array;

10
51
52
53
54
55
56
57
58
59
60
61
62
63
64

65

$Pattern = "(http://)?(r[:space:]] + !([


if (eregi($Pattern, $Array["URL"])) {
$Replace = "<a href=\"http://\\2\\3\" target=\"_new\">\\2\\3
</a>";
$Array[*URL"] = eregi_replace($Pattern, $Replace,
$Array["URL"]);
$CallFunction = WriteToFile ($Array["URL"],
$Array["Description"I);
if ($CallFunction) {
print ("Your submission-$Array[URL]-has been
received!<P><HR><P>\n") ;
} else {
print ("Your submission was not processed due to a system
error!<BR>\n");
}
} else {
print ("Please enter a valid Web address!\n") ;
} // HandleForm.

66 /* ,
, $BeenSubmitted
TRUE. */

67
68
69
70
71
72
73
74

if ($BeeaSubMitted) {
HandleFormf);
}
ReadProaFileO;
CreatePoraiO ;
?>
</BODY>
</HTML>

TOLi cartndy lilted h Ike * Be:

.'.
PHP home page -- the fire ate PHP Aould bookmaricl

Tbe Zendbomt ftgt goodmourn for mformlion on

Deicnpnon

. 10.7
, $BeenSubmi 11 ed , HandleForm () (. 10.4). , , (. 10.8)

Your submJHJonwww DMCinsJato.fcomfotoV-has been received!

.URLs currently listed in the data file:

The PHP home page -- the first site PHP programmers should bookmark!

Zend home page - a good resource for information on PHP4.

A home page mat accompanies tins text

Add a UKL to the data file:

UKL

Description

. 10.8 , uris.php ,

URLfl in fm txrnel
tout
URLe

ia cie flat*
3P.net'' tare
che first
*. Zend.conK/eXBR>

the Zad Jasne


page
<>
Add * USL the dec* file;

mhi taent.
'

<IHPT TXPE-HIDEEN !

. 10.9 uris.php HTML- , . , URL , .

10

- . . - ,
. . Web-
,
, , ..
mkdir ("path", "permissions") ;
, ( , chmod: 0,
, 0666). ,
, .


1.
.
HTML-.
<HTMLxHEADxTITLE>Registration Form</TITLEx/HEADxBODY>

2. HandleNewUser.php
ACTION POST.
<FORM ACTION="HandleNewUser.php" METHOD=POST>

,
POST, GET, .
3. , .
Username <INPUT TYPE=TEXT NAME="Array[Username]" SIZE=15xBR>
Password <INPUT TYPE=PASSWORD NAME="Array[Password]"SIZE=15xBR>

He PASSWORD ,
(. 10.10).
4. Submit, HTML-.
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</FORMx/BODYx/HTML>

5. NewUser.html ( 10.5) .
10.5 .
, , ,
.
1
2
3

<HTML>
<HEAD>
<T3TLE>Registration Form</TITLE>


4
5
6
7
8
. 9
10
11
12

</HEAD>
<BODY>
<FORM ACTION"HandleNewUser.php" METHOD=POST>
Osername <INPUT TYPE=TEXT NAME="Array[Username]" SIZE=15xBR>
Password <INPOT TYPE-PASSWORD NAME"Array[Password]" SIZE=15xBR>
<INPUT TYPE=SUBMIT NAME="SUBMIT"VALUE="Submit!">
</FORM>
</BODY>
</HTML>
.

6.
.
7. users.txt
NewUser.html.
8. ,
users.txt .
- ,

.

. 10.10 .

9. FTP Telnet ( Web-, ) users NewUser.html


users.txt.
10. ,
users, ( - 0777).
HandleNewUser.php, .
11. -.
12. PHP- .
<?php
function MakeDirectoryName ($Username) {
/* MakeDirectoryName
, . */
srand ((double) m i c r o t i m e ( ) * 1000000);
$Name = rand() . $Username;
return $Name;
} // End of MakeDirectoryName Function.

$Username
. srand() , .
$Username ,
.

10 v
13. ^11() 10,4 :
function WriteToFile ($Username, $Password) {
$TheFile'= 'users.txt*;
$0pen = fopen ($TheFile, " a " ) ;
if ($0pen) {
$Password = md5 ($Password);
( users.txt)
. .
14. .
$Directory = "users/" . MakeDirectoryNaiae. <$Username) ;
MakeDirectoryName ( ) , users.
15. .
fwrite ($0pen, "$Usernarne\t$Password\t$Directory\n") ;
fclose ($0pen);
16. .
if (! (mkdir ,($Directory, " 0 7 7 7 " ) ) ) {
^Directory = FALSE;
} else {
$Directory = FALSE;
return $Directory;
} // WriteToFile.
$Directory ,
.
, -$Directory .
, . ,
, - FALSE.
17. PHP- HTML-.
'?><HTMLxHEADxTITLE>Using Directories</TITLEx/HEADxBODY>
18. PHP- .
if (($Array[Username]) && ($Array[Password])) {
$Check = WriteToFile ($Array[Username], $Array[Password]);
if.($Check) {
print ( " Y o u r request-was successfully processed!<BR>\n");
} else {
print ("Your request was not processed due to
a system e r r o r ! < B R > \ n " ) ;
} else {
print ("Please enter a Username and Password!/n");

. ,
. , . .
19. PHP- HTML-.
?></BODYx/HTML>

20. HandleNewUser.php ( 10.6),


~( , users, users.txt
NewUser.html) (. 10.11 10.12).
10.6 ,
, .
mkdir () WriteToFile().
1
2
3

<?php
function MakeDirectoryName (SUaernane) {
/* MakeDirectoryName
, . */
4
rand ((double) microtiaeO * 1000000);
5
$ rand . $Ueername;
6

return $Na*a;

7 } // MakeDirectoryName.
8
9 function WriteToFile ($086, $PaeewoJTd) {
10 /* KriteToPile ,
. */
11
$TheFile * "ueere.txt";
12
$0 = fopen ($TheFile, ""),'
13
if ($0pn> {
14
$Paeword > md5 ($Paseworct) ;
15
$0irectory > "ueere/" . MakeDirectoryHame ($TJeername);
16
fwrite ($Open, $Username\t$Pa8eword\t$Directory\n");
17
fclose ($0pea);
18
if (MBkdir ($M.reetory, -0777"))) {
19
$Directory * FALSE;
20
}
21
} else {
22
$Directory > FALSE;
23
}
24
return $Bir*ctory;
'
25 } // WriteToFile.
26 ?>
27 <HTML>
28 <HEAD>

29 <TITLE>Using Direetories</TITLEx/HEAD>
30 <BODY>
31 <?php

32 /.* ,
"NewUser.html". */
33

10
34 if (($Array[Username]).&& ($Array[Password])) {
$Check = WriteToFile ($Array[Username], $Array[Password]);
35
if ($Check) {
36
print ("Your request was successfully processed!<BR>\n")
37
38
} else {
print ("Your request was not processed due to a system
39
error ! <BR> \n " )
40
else {
41
print ("Please enter a Username and Password ! \n" );
42
43
44
45 </BODY>

46 </HTML>

, users
FTP Telnet , .
- , . :
, , . , . .

Your request wu successfully processed)

. 10.11 , ,

. 10.12 users.txt : ,


, , HTML-, .
, .
HTML- .
, HTML-. -,
- ENCTYPE= "multipart/form-data", , . -,
<INPUT TYPE=FILE NAME=NAME>
, .
INPUT TYPE=FILE , .
, .
. - .
( ) :
("SourceName", "DestinationName");

unlink ( ) .
, '
users. , urls.php, HTML-
.


1. PHP- .
2. HTML-.
<HTMLxHEADxTITLE>Handling File Uploads</TITLEx/HEADxBODY>

3. PHP- ,
, .
<?php
if ( $ F i l e )

$File.
( ), .
4. .
print ( " F i l e name: $File_name<P>\n");
print ( " F i l e size: $ F i l e _ s i z e < P > \ n " ) ;

, . ( $File)
_name _size, .

10
5. users
.
if (copy ($File, "users/$File_name")) {
print ("Your file was successfully uploaded!<P>\n");
} else {
print (''Your f i l e could not be copied.<P>\n");
copy - , . $File, (, c : / p h p /
data. txt), (, "php/data. txt").
, users, .
6. .
unlink ($File);
, .

. unlink ( ) .
7. HTML- .
print ("Upload a f i l e to the server:\n");
print ("<FORM ACTION=\"FileUpload.php\" METHOD=POST
-ENCTYPE=\"multipart/form-data\">\n");
print ("File <INPUT TYPE=FILE-NAME=\"File\" SIZE=20xBR>\n");
print ("<INPUT TYPE=SUBMIT NAME=\"SUBMIT\"
-VALUE=\"Submit!\ n x/FORM>\n") ;

He ENCTYPE .
INPUT TYPE=FILE .
8. HTML.
?></BODYx/HTML>

9. FileUpload.php ( 10.7),
( users) (. 10.13 10.4).
10.7 , HTML-. : HTML-, ( )
unlink().
.

<HTML>

<HEAD>

3
4

<TITLE>Handling File Uploads</TITLE>


</HEAD>


5
6
7

<BODY>

<?php
/* ,
, $File. */

8 if ($Fil*> {
9
print ("File namei $Pil*_nam*<P>\n");
10
print ("Pile sicei $Pil_lx*<P>\n");
11
if (copy ($Fil, "uMr/$Pil_nam*"))

12
13
14
15
16
17 }
18

{
print ("Your file was successfully uploaded!<P>\n");
} else {
print ("Your file could not be copied.<P>\n")j

unlink ($Fil);

19 print ("Upload a file to the server:\n");


20 print ("<PORM ACTION.\"Pil*Upload.php\" METHOD-POST
SNCTYPE\"Bulfciprt/form-<Ut*\">\n")
i
21 print ("Pile <INPOT TYPB-FILB NAMB-\"Pil\" SIZEm20xBR>\n");

22 print ("<INPUT TYPE=SUBMIT NAME=\"SUBMIT\" VALUE=\"Submit!\">


</FORM>\n");
23 ?>
24 </BODY>
25 </HTML>

users, ,
. , , , . 10.15.
. , , . -,
( php.ini).
-, , :
cINPUT TYPE=HIDDEN NAME="MAX_FILE_SIZE" VALUE="2048">
FILE .

Uplotd > Se to die temr:

He |1

. 10.13 FILE ,

.

10

File napij: i

Fde name: image.tif

File size: 3443

File sire: 3443

Your ffle was successfully uploaded!

Warning- XTaable to create 'irnage.tif. Permission denird


iphp/<10TUeUplod plip on line 11
Your could not be copied

Upload a file to the server:

Upload a file to the server:

Browse...

Browse...

. 10.14
.

. 10.15 , , . ,
,
.

, $File_type $File, - , MIME (


Internet). ,
. MIME image/jpeg text/html.



. ,
. ,
, .
rename ( ) :
rename (" "

, .
, , - f ilesize ( ) .
. .
$Number = filesize ("filename"
-
.
FTP . . ,

, . , , , .
$Handle = opendir ( " p a t h " ) ;
readdir ($Handle);
closedir ($Handle);
readdir { ) ,
:
while (readdir ($Handle)) {
statements;
,

.


1. -.
2. HTML-.
<HTMLxHEADxTITLE>Viewing Files in a Directory</TITLE>
-</HEADxBODY>

3. , -.

<TABLE BORDER=0 WIDTH="60%" CELLSPACING=2


-CELLPADDING=2 ALIGN=CENTER> .
<?php-

, .
4. , , . , $Delete ( )
$Rename ( )
. $Upload ( ), .
if ($Upload) .{ // .
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>Uploaded
f i l e name: $File_name</TDx/TR>\n") ;
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>Uploaded
- f i l e s i z e : $File_size</TDx/TR>\n") ;
if (copy ($File, "users/$File_name")) {
print ("<TRxTD COJjSPAN=4 ALIGN=CENTER>Your f i l e ,
SFile^name, was successfully uploaded!</TDx/TR>\n");
} else {

print ("<TRxTD COLSPAN=4 ALIGN=CENTER>Your file,


-$File_name, could not be copied.</TDx/TR>\n");

10
unlink ($File);
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>&nbsp;</TDx/TR>\n" ) ;
}.

$Upload ,
. , $Upload ,
, .
print, , , . Web- .
5. if ($Delete) { // Handle f i l e deletions.
for ($1 = 0; $1 < count ($Delete); $i++) {
if ( unlink Pusers/$Delete[$i]"-) ) {
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>Your file,
$Delete[$i] , was successfully deleted! </TDx/TR>\n" ) ;
} else {
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>Your file,
-$Delete[$i] ,. could not be deleted. </TDx/TR>\n" ) ;
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>&nbsp;</TDx/TR>\n" ) ;
}

$Delete ,
- . ,
. , -
.
6. if ($Rename) { // Handle file renaming.
for ($n - 0; $n < count ($Rename); $n+f) {
$01dFilename = $Rename[$n] ;
$01d = "users/$01dFilename" ;
$New = "users/$NewName[$01dFilename] " ;
if ( rename ($01d, $New) ) {
print 1"<TRxTD COLSPAN=4 ALIGN=CENTER>Your file,
$Rename[$n] , was successfully renamed!</TDx/TR>\n" ) ;
} else {
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>Your file,
$Rename[$n] , could not be renamed. < /TD>< /TR> \n ");
}
}
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>&nbsp;</TDx/TR>\n") ;
}


, . , rename ( ) , .
7. HTML-, ENCTYPE .


print ("<FORM ACTION=\"files.php\" METHOD=POST
-ENCTYPE=\"multipart/form-data\">\n");
8. .
print ("<TRxTDxB>File Name</Bx/TDxTD><B>File
Size</Bx/TDxTDxB>Delete</Bx/TDxTDxB>Rename</B>
Enter the New Name in the Box)</TDx/TR>\n") ;
9. , .
$0pen = opendir ("users");
while ($Files = readdir ($0pen)) {
$Filename = "users/" . $Files;
if (is_file ($Filename)) {
$Size = filesize ("users/$Files");
print ("<TRxTD>$Files</TDxTD>$Size</TDxTDxINPUT
-TYPE=CHECKBOX NAME=\"Delete[]\" VALUE=\"$Files\">
-</TDxTDxINPUT TYPE=CHECKBOX NAME= \"Rename [] \"
-VALUE=\"$Files\"xINPUT TYPE=TEXT NAME=
-\"NewName[$Files]\"x/TDx/TR>\n") ; closedir

($0pen);

( ), users. , . is_f ile ( ) ,


.
10. .
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>&nbsp;</TDx/TR>\n") ;
print ("<TRxTD COLSPAN=4 ALIGN=CENTER><INPUT TYPE=CHECKBOX
-NAME=\"Upload\" VALUE=\"Yes\">Upload a f i l e to theserver:<INPUT
-TYPE=FILE NAME=\"File\" SIZE=20x/TDx/TR>\n") ;
print ("<TRxTD COLSPAN=4 ALIGN=CENTERxINPUT TYPE=SUBMIT
-NAME=\"SUBMIT\" VALUE=\"Submitl\"x/FORMx/TDx/TR>\n");
11. PHP HTML.
?></TABLEx/BODYx/HTML>
12. files.php ( 10.8),
( users) (. 10.16
10.17).
10.8 , . ,
, , .
1
2
3

<HTML>
<HEAD>
<TITLE>Viewing Files in a Directory</TITLE>

10
4
5
6
7
8

</HEAD>
<BODY>
<TABLE BORDER=0 WIDTH='.'60%" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>
<?php
/*
, ' . */

9
10 if ($Upload) { // .
11
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>Uploaded file name:
$File_name</TDx/TR>\n") ;
12
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>Uploaded file size:
$File_size</TDx/TR>\n") ;
13
if (copy ($File, "users/.$File_name")) {
14
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>Your file, $File_name,
was successfully uploaded!</TDx/TR>\n");
15
} else {
16
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>Your file, $File_name,
could not be copied. </TDx/TR>\n") ;
17
} '
18
unlink ($File);
19
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>&nbsp;</TDx/TR>\n"') ;
20 }
21
22 if ($Delete) { // Handle file deletions.
23
for ($1 = 0; $1 < count ($Delete); $i++) {
24
if ( unlink ("users/$Delete[$i]") ) {
25
print ("<TR><TD COLSPAN4 ALIGN=CENTER>Your file,
$Delete[$i], was successfully deleted!</TDx/TR>\n");
26
} else {
27
print ("<TRXTD COLSPAN=4 ALIGN-CENTER>Your file,
$Delete[$i], could not be deleted.</TDx/TR>\n");
28
}
29
}
30

print ( n <TRxTD COLSPAN4 ALIGN=CENTER>Snbsp;</TDx/TR>\n") ;

31 }
32

33 if ($Rename) { // Handle file renaming.


34
for ($n = 0; $n < count ($Rename); $h++) {
35
$01dPilename = $P.ename[$n];
36
$01d = users/$01dFilename";
37
$New "users/$NewName[$01dPilename]";
38
if ( rename ($01d, $New) ) {
39
print ("<TRXTD COLSPAN=4 ALIGN=CENTER>Your file,
$Rename[$n], was successfully renamedI</TD></TR>\n");
40
} else {
-41
print (<TRxTD COLSPAN=4 ALIGN=CENTER>Your file,
$Rename[$n], could not be renamed.</TDx/TR>\n");
42
}
43
}
.
44
print ("<TRxTD COLSPAN-4 ALIGN=CENTER>Snbsp;</TDx/TR>\n") ;
45 }
46
47 // .
48 print ("<FORM ACTION=\"files.php\" METHOD=POST ENCTYPE=\"multipart/
form-data\">\n");

49

print ("<TRxTDxB>File Name</Bx/TDxTD><B>File Size</B>


</TD><TD><B>Delete</Bx/TD><TDxB>Rename</B> Enter the New Name in
the Box)</TDx/TR>\n") ;

50
51 // .
52 $0pen = opendir ("users");
53 while ($Files = readdir ($0pen)) {
54
$Pilename = "users/" . $Files;
55
if (is_file ($Filename)) {
56
57

58

59
60
61
62
63
64

65

66
67
68
69

$Size = filesize ("users/$Files");


print ("<TRxTD>$Files</TD><TD>$Size</TD><TDxINPUT
TYPE=CHECKBOX NAME=\"Delete[]\" VALUE=\"$Files\">
</TDxTDxINPUT TYPE=CHECKBOX NAME=\"Rename [] \ "
VALUE=\"$Files\"xINPUT TYPE=TEXT NAME= \"NewName[$Files]\"
</TDx/TR>\n") ;
}
}
closedir ($0pen);

'
// .
print ("<TRxTD COLSPAN=4 ALIGN=CENTER>&nbsp;</TDx/TR>\n"} ;
print ("<TRxTD COLSPAN=4 ALIGN=CENTERxINPUT TYPE=CHECKBOX
NAME=\"Upload\" V A L U E = \ " Y e s \ " > U p l o a d a f i l e to theserver:<INPUT
TYPE=FILE N A M E = \ " F i l e \ " S I Z E = 2 0 x / T D x / T R > \ n " ) ;
print ("<TRxTD COLSPAN=4 ALIGN=CENTER><INPUT TYPE=SUBMIT
NAME=\"SUBMIT\" VALUE=\ " Submit ! V " x / F O R M x / T D x / T R > \ n " ) ;

?>
</TABLE>
</BODY>
</HTML>

File Nam? ^ Del

Name in the Box)

3443

r|
r|
r|
r|

users.txt

399

r|

datata

248

r|

form.html

302

urlsphp

2409

jmage2.png 1350 ~
unage3.jpg 4239
imasel.tf

Upload a file to the server:


Browse...

Submit! |

J4"*",'

'

" DowSntR

. 10.16 ,
. ,

10

Uploaded file name: dmajpg


Uploaded ffle are: 137 37
Your 8e, dmdjpg, wu succesrfuDy uploadedl
Your file, Jmage2.png, wti successfully deleted!
Your file, datt.txt, wu luccewftifly renamed!

.Name the Box)


urt.php

2409

image3.jp4 39

r|

_<. 248

nn.gel.tf 3443

users.w

399

f>rm.html

302

dmdjpt

13737

Upload a Se to server.

. 10.17 , ,
. ,

NewUser.html HandleNewUser.php files.php ( )


.
,
.
, .

, Internet , , .
, .
() ^ ,
.
, .

(), . ( , - , .
. .)
Oracle. , Oracle ,
. Windows Windows NT SQL-
Access. , ,
.
MySQL (. 11.1).
MySQL . ,
, SQL-, . UNIX MySQL, , ,
Web-. , ,
( ). ,

11

fc

fie

Search:

I
Site Map
Order Support
Partners
Books
Jobs
Advertising
Contact
Join Mailing Lists

G^J^ An Introduction to
*uf :.
Extreme Programming
Latest News
2001/06.11

MOIAUM

SponsorHlnpirtby:
bring t to* jp/c*t
MySQL
PHP

Latest V*islone

Hl> MySQL . Tak Our Survey!


^.
MySQL AB needs your help to make MySQL even
betterl Please take 10 minutes to fill-out our - WVSQL-Md
We need this information to help us develop MySQL ^
to suit future needs. This information will arso help us
development work. You can provide this, so please ....,,,.
heln usl
'

- Help MySQL Take our Survey!

News
Articles
nformation
Documentation
Support
Training
Downloads
Development

ife
.,.,!

Profeedoii.il TiainiiKi Team Joins MvSOL


MySQL AB today announced that a professional
MySQL training team has joined the company. Mr

239
.2.9
1 75

-.cn^i
il.OU.J/

QEduSUDMft 9"<J
Commercial MvSQL
Licenses

President responsible for building and developing the Fill out our survey and
MySQL
training
proeram,
certification
and
ftW^e?
'
documentation. Arno and his crew join from Polycon
^^
AB, a company he co-founded in 1987 and that he ^41^. 3Paim
has been running sucessfully as CEO since then,
^T^^TI> 'Hccator
, f handheld
2001 '00.05 Blue World arid MvSOL AB to Deliver Embedded irW
f PDAs
Laeso MySQL Database
j^ff
f^
Web Data Engine[tm] and MySQL AB, developers of ^
/****
MySQL [tmj-the most widely used database on the ,3fam0lS jf
Internet today announced strategic relations and a MySQL,
f
licensing agreement for the distribution of MySQL books Oy ^L
embedded in editions of Lasso Professional 5. The pau!Du&ois \ /
embedded database tor Lasso Professional
5, e.g. Lasso MySQL, provides Lasso developers a
powerful SOL database server as an integral part of
- Lasso Professional 5.

^'--'

. 11.1 MySQL MySQL (www.MvSQL.com).


,

.MySQL (. www.MySOL.com , ).
, SQL ( ). SQL ,
, . ,
, .
,
. , SQL Web- (
),
.
, , .
, . . .
MySQL, MySQL. ,

MySQL mysql_connect ( ) . ( PostgreSQL) pg_connect ( ) .


, , , ,
( www.PHP.net)
.



( 10),
. . -
readdir ( ) .
. ( MySQL). . MySQL :
$Link=mysql_connect("host","user","password");

: ,
localhost, .
.
- , . , . ,
( ),

.
, .
- , - . , .
:
mysql_create_db("databasename",$Link);

, $Link
,
.
:
1

mysql_close($Link);

11

, . ,
,
, .

MySQL
1. PHP- .
2. HTML-.
<HTMLxHEADxTITLE>Creating a Database</TITLEx/HEADxBODY>

3. PHP- .
<?php
$Host = "localhost";

$User = "user";
$Password = "password";

$ DBNaiwe = " NewDa t aba s e";

,
. , . , .
4. .
$Link = mysql_connect ($Host, $User,$Password);

MySQL , .
,
.
5. .
if

(mysql_create_db ($DBName, $ L i n k ) ) {
print ("The database, $DBName, was successfully
created'! <BR>\n") ;
J'else {
print ("The database, $DBName, could not be created!<BR>\n");

, (. 11.2).
- , MySQL, !, (. 11.3).
6. MySQL, PHP- HTML.
mysql_close ( $ L i n k ) ;
?x/BODYx/HTML>

'"

Last Name |011


E-mail Address
Cinsight*.COM
Mow I ' m using database to score
information permanently.

Comments

. 11.2 HTML- .

Feedback NewDatabase

query is:
INSERT into Feedback values (1, l-any1. '',
"Now IVm using database to store information permanently.')
The query was success&Dy executedl

. 11.3 , . , .
, SQL ,
" Now I",

MySQL,
. - .
7. CreateDB.php ( 11.1),
.
11.1 : , mysql_create_db ( ) . - ,
, - , .
<HTML>
<HEAD>

11
3
4
5
6
7
8
9
10
11
12
13
14
15
16

<TITLE>Creating a Database</TITLEx/HEAD>
<BODY>
<?php
// .
$Host = "localhost";
$User = "user";
$Password = "password";
$DBName = "NewDatabase";
$Link = mysql_connect ($Host, $User,$Password);
if (myegl_create_db ($DBName, $Link)) {
print ("The database, $DBName,_was successfully created!<BR>\n");
} else {
print ("The database, $DBName, could not be created!<BR>\n");

17 }
18
19
20
21

mysql_close ($Link);
?>
</BODY>
</HTML>

'

PHP , dBase, FilePro, mSQL,


MySQL, Oracle, PostgreSQL SyBase. ' ,
(, Access MS SQL-), ODBC (
) ODBC- .
.
MySQL ,
, , MySQL: LAMP ( Linux, Apache,
MySQL, PHP) WAMP ( Windows, Apache,
MySQL, PHP).



. , .
, . SQL. SQL- :
$Query=" SQL";
mysql_db_query("DatabaseName",$Query,$Link);
SQL ,
:
$Query="CREATE table TABLENAME(columnl, column2 . . ) " ;

, ,
. - TEXT () INT ( ). , , .
:
$Query="CREATE table NewTable(id INT PRIMARY KEY, information TEXT)";

- , .
,
. ,
.
1, - 2 ..
( )
.
SQL MySQL (. 11.1).
.
, ,
HTML-. , .


?i

1. PHP- .
2 HTML'aooo.
<HTMLxHEADxTITLE>Creating a Table</TITLEx/HEADxBODY>

3. PHP-
.
<?php
$Host = "localhost";
$User = "user";
$Password = "password";
$DBName = "NewDatabase";
$TableName = "Feedback";
, 11.1
- $TableName. .
,
Feedback ( ). ! MySQL .
4. .
$Link = mysql_connect ($Host, $User, $Password);

11

5. .
$Query = "CREATE table $TableName (id INT UNSIGNED NOT
-NULL AUTO_INCREMENT PRIMARY KEY, FirstName TEXT, LastName
-TEXT, EmailAddress TEXT, Comments T E X T ) " ;

. , CREATE
table $TableName ( $TableName $TableName ).
, .
id.
( INT UNSIGNED , ). NOT NULL ,
. (AUTO_INCREMENT) .
: , - , - , - .
6.
.
if (mysql_db_query ($DBName, $Query, $Link)) {

print ("The query was successfully executed!<BR>\n");


} else {
print ("The query could not be executed!<BR>\n");
}

( ),
(. 11.4).
SQL, , . 11.5.
- , , . 11.3.
7. MySQL, PHP- HTML. mysql_close ($Link);
?></BODYx/HTML>
8. CreateTable.php ( 11.2),
.
11.2
mysql_db_query().
1
2
3
4
5

<HTML>
<HEAD>
<TITLE>Creating a Table</TITLEx/HEAD>
<BODY>
<?php

$Host = "localhost";

8
9

II .

$User = "user";
$Password = "password";


10 $DBName = "NewDatabase";
11 $ = "Feedback";

12
13 $Link = mysql_connect ($Host, $User-, $Password) ;
14 $Query = "CREATE table $TableName (id INT UNSIGNED NOT NOLL
AOTO_INCREMENT PRIMARY KEY, FiretName TEXT, LastName TEXT,
EmailAddress TEXT, Comments TEXT)";
15 if (myaql_db_query ($DBName, $Query, $Link)) {
16
print ("The query was successfully executed!<BR>\n");
17 } else {
18
print ("The query could not be executed!<BR>\n");

19 }
20 mysql_close ($Link);

21 ?>
22 </BODY>
23 </HTML>
SQL-, ,
. SQL
. ,
SQL- .
Je

''

The quety was successfully executed!

R gt. j

. 11.4 , . ,
, ,
SQL- (. 11.5)
.

<1.>1 Into Database


</TITLE>
'
<BODX>
.
' . '
**
1
The query is:<BR>INSERT into Feedback values Co , 'Leery, 'oilman', 'phpeDHCinsiBhts.com', 'No IVn using i
information Dernanently.')<P>
The query was successfully executed!<BR>
</BOD3>-

iacabase to score

. 11.5 SQL- HTML- ,


11


, .
: , , , .
: , SQL- .
$Query="INSERT into $TabName values ( ' v a l u e l ' , 'value2' , 'value3 ' , e t c . ) "-;
mysql_db_query("DatabaseName",$Query,$Link);

INSERT into $TabName values.


, .
, . MySQL mysql_db_query ( ) .
, , HTML-, , , . PHP-, , .

HTML-
1. HTML- .
2. HTML-:
<HTMLxHEADxTITLE>HTML Form</TITLEx/HEAD><BODY>

3. .
<FORM ACTION="HandleForm.php" METHOD=POST>

4. .
First Name <INPUT TYPE=TEXT NAME="Array[FirstName]" SIZE=20xBR>
Last Name <INPUT TYPE=TEXT 'NAME="Array [LastName] " SIZE=40xBR>
E-mail Address <INPUT. TYPE=TEXT NAME="Array[Email]" SIZE=60xBR>
Comments <TEXTAREA NAME='.'Array [Comments] " ROWS = 5 COLS=40>
</TEXTAREAxBR>

, , - - HandleForm.php.
5. Submit, HTML-.
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit ! " >
</FORMx/BODYx/HTML>

6. form.html ( 11.3) Web.


11.3 . HTML-, .
1
2
3
4
5
6
7
8
9
10
11
12
13
14

<HTML>
<HEAD>
<TITLE>HTML Form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="HandleForm.php" METHOD=POST>
First Name <INPUT TYPE=TEXT NAME="Array[FirstName]" SIZE=20xBR>
Last Name <INPUT TYPE=TEXT NAME*11 Array [LastName]" SIZE=40xBR>
E-mail Address <INPUT TYPE=TEXT NAME*"Array[Email]" SIZE=60xBR>
Comments <TEXTAREA NAME="Array[Comments]" ROWS=5 COLS=40>
</TEXTAREAxBR>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</FORM>
</BODY>
</HTML>

HandleForm.php, .
1. PHP- .
2. HTML-.

'

<HTMLxHEADxTITLE>Inserting Data into a Database</TITLEx/HEADxBODY>


3. PHP-
, .
<?php
$Array["FirstName"j = trim ($Array["FirstName"]);
$Array["LastName"] = trim ($Array["LastName"]);
$Array ["Email"] = trim ($Array ['"Email" ] ) ;
$Array["Comments"] = trim ($Array["Comments"]);
4. .
$Host = "localhost";
$User = "user";
$Password = "password";
$DBName = "NewDatabase";
$TableName = "Feedback";
5. MySQL, .
$Link = mysql_connect ($Host, $User, $Password);
SQuery = "INSERT into $TableName values ( " 0 " , "$Array[FirstName]",
"$Array[LastName]", " $ A r r a y [ E m a i l ] " , " $ A r r a y [ C o m m e n t s ] " ) " ;
INSERT into $TableName values.
( ),
.

11
id , 0. , , id
.
6. , , :
print ("The query is:<BR>$Query<P>\n");
- , . ,
,
.
7. , ,

. , , .
if (mysql_db_query ($DBName, $Query, $Link)) {
print ("The query was successfully executed!<BR>\n");
} else {
. .
print ("The query could not be executed!<BR>\n");
}
8. MySQL, PHP- HTML.
mysql_close ( $ L i n k ) ;
?></BODYx/HTML>
9. HandleForm.php ( 11.4),
form.html
(. 11.2 11.3).
11.4 . , .
1
2

3
4
5
6

<HTML>
<HEAD>

<TITLE>Inserting Data into a Database</TITLEx/HEAD>


<BODY>
.
.
<?php
/* ,
"form.html". */
7
// .
8 $Array["FirstName"] = trim ($Array["FirstName"]);
9 $Array["LastName"] = trim ($Array["LastName"]);
10 $Array[" Email"] = trim (-$Array[ "Email"] );
11 $Array["Comments"] = trim ($Array["Comments"]);
12
13 // .
14 $Host = "localhost";

'


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

$User = "user";
$Password = "password";
$DBName = "NewDatabase";
$TableName = "Feedback";
$Link = raysql_connect ($Host, SUser, $Password);
$Query = "INSERT into $TableName values ("0", "$Array[FirstName]",
"$Array[LastName]", "$Array[Email]", "$Array[Comments]")";
print ("The query is:<BR>$Query<P>\n");
if (mysql_db_query (SDBName, $Query, $Link)) {
print ("The query was successfully executed!<BR>\n");
} else {
print ("The query could not be executed!<BR>\n");
}
mysql_close ($Link);
?>

</BODY>
</HTML>
SQL ,
, : print ("<! --The query
is $Query>\n") ;. HTML-, , (. 11.4 11.5).



mysql_db_query ( ) , , .
.
:
$Query="SELECT * from $TableName";
(
$TableName).
.
, ,
SELECT FirstName, Comments from $TableName.
( ).
- - S.ELECT * from
$TableName where (FirstName= 'Larry').
, , Larry. , SQL
.
,
-. :
$Result=mysql_db_query($DBName, $Query, $Link);

11

, .
$Result , .
while($Row=mysql_fetch_array($Result)) {
statements;
}

( $Result) $Row.
, . - ,
Feedback (
form.html).


1. PHP- .
2. HTML-.
<HTMLxHEADxTITLE>Retrieving Data from a Database</TITLEx/HEADxBODY>

3. PHP-
.
<?php
// .
$Host = "localhost";
$User = "user";

$Password = "password";
$DBName = "NewDatabase";
$TableName = "Feedback";

4. , .
$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT * from $TableName";
$Result = mysql_db_query ($DBName, $Query, $Link);

. ,
, .
5. HTML- .
print ("<TABLE BORDER=1 WIDTH=\"75%\" ,CELLSPACING=2
~CELLPADDING=2 ALIGN=CENTER>\n");
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>Name</TD>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>Email Address</TD>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>Comments</TD>\n");
print ( " < / T R > \ n " ) ;

.

HTML, HTML-.
.
6. , , .
while ($Row = mysql_fetch_array ( $ R e s u l t ) ) {

$Row ,
$Result. ( 7). mysql_f etch_array ($Result) $Row . , .
7. HTML-.
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[FirstName]
-$Row[LastName]</TD>\n") ;
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[EmailAddress]</TD>\n");
print ("<TD ALIGN=CENTER VALIGN==TOP>$Row[Comments]</TD>\n"} ;
print ( " < / T R > \ n " ) ;

mysql_f etch_array ( ) ,
, . - ,
, , (, ).
8. HTML- while.
print ( " < / T R > \ n " ) ;
}

, ,
$Row, HTML-.
9. MySQL, HTML-, -
HTML-.
mysql_close ($Link);
print ( " < / T A B L E > \ n " ) ;
?></BODYx/HTML>

10. DisplayDB.php ( 11.5),


(. 11.6).
11.5 SQL-
, , * .
1
2

<HTML>
<HEAD>

11

4
5
6
7
8
9
10
11

<TITLE>Retrieving Data from a Database</TITLEx/HEAD>


<BODY>
<?php
// .
$Host = "localhost";

$User = "user";
$Password = "password";
$DBName = "NewDatabase";
$TableName = "Feedback";

12
13 $Link = mysql_connect ($Host, $User, $Password);
14
15 $Query . "SELECT * from $TableName";
16 $Result = myeql_db_query ($DBName, $Query, $Link);

17
18 // .
19 print ("<TABLE BORDER=1 WIDTH=\"75%\" CELLSPACING=2 CELLPADDING=2
20
21
22
23
24
25
26
27
28
29

ALIGN=CENTER>\n");
print ("<TR ALIGN=CENTER VALIGN=TOP>.\n") ;
print ("<TD ALIGN=CENTER VALIGN=TOP>Name</TD>\n");

print ("<TD ALIGN=CENTER VALIGN=TOP>Email Address</TD>\n');


print ("<TD ALIGN=CENTER VALIGN=TOP>Comments</TD>\n");
print ("</TR>\n");

// .
while ($Row = mysql_fetch_array ($Result)) {
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[FiretName]
$Row[LaetName]</TD>\n?);
30
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[EmailAddreee]</TD>\n")i
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[Commente]</TD>\n");
31
print ("</TR>\n");
32
33
34 mysql_close ($Link);
35 print ("</TABLE>\n");
36
37 </BODY>
38 </HTML>

Name

Email Address

Comments

Larry
i

php@JJMCinsigfrts. com

i Now using a
i database to store i
i
information
\
I permanently
;

\
I
Jane
Doe

:
|Jane_Doe@someaccowt.com i Just adding
!
I amother record ;
i
I to the database ;

. 11.6
Web-, HTML

cookie

ookie - Internet,
. ,
. cookie , . , ,
, ,
, , , .
, cookie, , cookie
(. 12.1).
, . cookie ,
, Hotmail, .
Cookie
. Web- -
. cookie
: ,
. cookie, , .
.
cookie , ,
. cookie

1
, . . cookie - , . - . . .

12 cookie

Appearance
fonts
Cotas
NevQator
Languages
Appfcalions
Smart Browsmg
MaH & Newsgroups
Roaming Access
Composer
Ofrbe

<& **, badinage


17 Enattejava

P nat*>Jav$C4JffcH<andNes

Cache
Proxies
SmartUpdate

. 12.1 Netscape Navigator cookie


Edit > Preferences > Advanced. Internet Explorer 5.0 ( Macintosh) , Edit >- Preferences > Cookies. -,
Windows Macintosh

, , , .
cookie.
, cookie, .
, .

cookie
, cookies, - ,
- . cookie , HTML-,
, cookie
(. 12.2).
.
Cookie setcookie ( ) :
setcookie("name","value");
cookie name value
(.12.3).
cookie
setcookie ( ) , Web- 20 cookie
:
setcookie("name2","value2");
setcookie("","value3");

cookie

-fie
?f*W n<3 fc* of (he cookie at*
Wanning: Oops. php3_SetCookie cafled after header has been sent in temp php
online S

Document: Done

. 12.2 ,
setcookie () , -,
, Web-

. 12.3 , cookie,

cookie , cookie ( , ), ,
HTML- . , cookie, setcookie ("UserName", "Larry") ;,
$UserName.
cookie ,
_ .

cookie
1. PHP- , -.
<?php
2. , cookie,
.
if ($BeenSubmitted)

, $BeenSubmitted , . , .
3. cookie, .
setcookie("BGColor", "$NewBGColor");
setcookie("TextColor", "$NewTextColor");
$BGColor = $NewBGColor;
$TextColor = $NewTextColor;

, cookie . (
BGColor TextColor) (NewBUColor NewTextColor), .
4. .
} else {
if (!$BGColor)

12 cookie
$BGColor = "WHITE";
if (!$TextColor) {
$TextColor = "BLACK";

, PHP
.
5. PHP- HTML-.

?>
<HEAD>

<TITLE>User Custom!zation</TITLE>
</HEAD>

6. PHP- <BODY> .
<?php
print ("<BODY BGCOLOR=$BGColpr TEXT=$TextColor>\n");
?>
7. , .
Currently your page looks like this!

8. HTML-, !
<FORM ACTION="cookies.php" METHOD=POST>

$PHP_SELF, .
9. , .
Select a new background color:
<SELECT NAME="NewBGColor">
<OPTION VALUE=WHITE>WHITE</OPTION>
DPTION VALUE=BLACK>BLACK</OPTION>
DPTION VALUE=BLUE>BLUE</OPTION>
<OPTION VALUE=RED>RED</OPTION>
<OPTION VALUE=GREEN>GREEN</OPTION>
</SELECT>
Select a new text color:
<SELECT NAME="NewTextColor">
<OPTION VALUE=WHITE>WHITE</OPTION>
<OPTION VALUE=BLACK>BLACK</OPTION>
<OPTION VALUE=BLUE>BLUE</OPTI0N>
<OPTION VALUE=RED>RED</OPTION>
<OPTION VALUE=GREEN>GREEN</OPTION>
</SELECT>

cookie
5 , .
. HTML.
10. , ,
.
<INPUT TYPE=HIDDEN NAME=BeenSubmitted VALUE=TRUE>
, .
11. Submit, HTML-.
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</FORM>
</BODY>
</HTML>

12. cookies.php ( 12.1), (. 12.4-12.8).


12.1 cookie . , .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

<?php
if ($BeenSubmitted) {
setcookie("BGColor", "$NewBGColor");
eetcookie("TextColor", "$NewTextColor");
$BGColor = $NewBGColor;
$TextColor = $NewTextColor;
} else {
if (!$BGColor) {
$BGColor = "WHITE";
}
if (!$TextColor) {
$TextColor = "BLACK";
}
}
?>
<HEAD>
<TITLE>User Customization</TITLE>
</HEAD>
<?php
print ("<BODY BGCOLOR=$BGColor TEXT=$TextColor>\n");
?>

22 Currently your page looks like this!

23 <FORM ACTION="cookies.php" METHOD=POST>

24 Select a new background color:


25 <SELECT NAME="NewBGColor">
26 <OPTION VALUE=WHITE>WHITE</OPTION>

12 cookie
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

<OPTION VALUE=BLACK^BLACK</OPTION>
DPTION VALUE=BLUE>BLUE</OPTION>
<OPTION VALUE=RED>RED</OPTION>
<OPTION VALUE=GREEN>GREEN</OPTION>
</SELECT>

Select a new text color:

<SELECT NAME="NewTextColor">
<OPTION VALUE=WHITE>WHITE</QPTION>
<OPTION VALUE=BLACK>BLACK</OPTION>
<OPTION VALUE=BLUE>BLUE</OPTION>
<OPTION VALUE=RED>RED</OPTION>
<OPTION VALUE=GREEN>GREEN</OPTION>
</SELECT>
<INPUT TYPE=HIDDEN NAME=BeenSubmitted VALUE=TRUE>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</FORM>
</BODY>
</HTML>
cookie urlencode ()
PHP-. , HTML-.

* flu
* "Okie H* Wl *** <
rtaitwMfv^M thtowkeare:
BGCdot- '

Currently your page looks like this I


Select a new background color: |WHITE

_f] Select a new text color: | WHITE

Do yw with to afcm fte eooMe to * (1

Submit! I

CO

. 12.4 cookies.php .
:

. 12.5
setcookie ( ) ,
cookie.
BLUE
BGColor

The pan and veiiib A (be eoofae *


TeCok.'*iHITE

. 12.
cookie TextColor WHITE. Preferences,

cookie

go

. 12.7 HTML-
cookies.php
cookie
,

</>
<80lt OLOR- BLUE -1>
Currently your page loofcs like this!
<TOW1 ACTJOHH"coofcias.pbp" MEIMBO-POST>
Select a tUfev beafcflCuund cOIOCs n

< OP I OH

<OFTtOH

a new text

. 12.8 ,

, cookie , . cookies.php, , , BGColor TextColor,


cookie .

cookie
setcookieO , . ,
- cookie:
setcookie("name","value","expiration","path","domain","secure");
expiration , cookie. , cookie ,
. cookie ,

12 cookie

. cookie
(60 60 ) :
setcookie)"name","value",time()+3600);

time ( )
3600, . (
time ( ) + 3600, ).
path domain cookie
. ,
cookie, , ,
:
setcookie("name","value",time()+3600,"/user/");

secure cookie HTTPS. ,


, , . .
s e t c o o k i e ( " n a m e " , " v a l u e " , t i m e ( ) + 3 6 0 0 , " " , " " , "1") ;

, , . ,
. , , ,
HTTPS.
cookies.php, .

cookie
1. cookies.php ( 12.1).
2. ,
:
setcookie("BGColor", "$NewBGColor", t i m e ( ) + " 1 0 0 0 0 0 0 0 " ) ;
setcookie(."TextColor", "$NewTextColor", t i m e ( ) + " 1 0 0 0 0 0 0 0 " ) ;

t i m e ( ) + " 1 0 0 0 0 0 0 0 " , cookie


116 (60 60 24 115 = 10000GOO).
3. ( 12.2),
(. 12.9 12.10).
12.2 cookies,
, Web
" ' "'
1
2

<?php
if ($BeenSubmitted)

. 12.9
-

cookie,

cookie
3
4
5

6
7
8

eetcookie("BGColor", "$NewBGColor", time() + "10000000");


eetcookieC'TextColor", "$NewTextColor", time()+ "10000000");
$BGColor = $NewBGColor;

$TextColor = $NewTextColor;
} else {
if (!$BGColor) {

$BGColor .= "WHITE";

10
11

}
if (!$TextColor) {

12
13

$TextColor = "BLACK";

14 }
15 ?>

'

16 <HEAD>

17 <TITLE>User Customization</TITLE>
18 </HEAD>
19 <?php
20 print ("<BODY BGCOLOR=$BGColor TEXT=$TextColor>\n");
21 ?>

22 Currently your page looks like this!


23

<FORM ACTION="cookies.php" METHOD=POST>

24 Select a new background color:


25
26
27
28
29
30
31

<SELECT NAME="NewBGColor">
<OPTION VALUE=WHITE>WHITE</OPTION>
<OPTION VALUE=BLACK>BLACK</OPTION>
<OPTION VALUE=BLUE>BLUE</OPTION>
<OPTION VALUE=RED>RED</OPTION>
<OPTION VALUE=GREEN>GREEN</OPTION>
</SELECT>

32 Select a new text color:


33
34
35
36
37
38
39
40
41
42
43
44

<SELECT NAME="NewTextColor">
<QPTION VALUE=WHITE>WHITE</OPTION>
<OPTION VALUE=BLACK>BLACK</OPTION>
<OPTION VALUE=BLUE>BLUE</OPTION>
<OPTION VALUE=RED>RED</OPTION>
<OPTION VALUE=GREEN>GREEN</OPTION>
</SELECT>
<INPUT TYPE^HIDDEN NAME=BeenSubmitted VALUE=TRUE>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</FORM>
</BODY>
</HTML>
Netscape Internet Explorer cookie, . , , ,
:

setcookie("BGColor", "$NewBGColor", t i m e ( ) + "10000000" , " " , " " , " " ) ;


cookie.
: cookie
, ; ,

Tj/

12 cookie

. 12.10 cookie, , ,
cookie, , ,
. cookies ,
, ,

cookie, ; cookie , , cookies , .
cookie
,
. , ,
,
.

cookie
cookie , , cookie . , , , cookie ,
.
setcookie ( ) , - cookie. cookie - , cookie . , cookie UserName
:
setcookie("UserName","Larry");

UserName :
setcookie("UserName","");

cookie

,
.
setcookie("UserName","",time()-60);

, "Reset
cookies.php. cookie ,
.


1. cookies.php
( 12.2).
2. if ($BeenSubmitted) ( 12.3, 3-8).
if ($Reset) {
setcookie("BGColor", "", time()- "100");
setcookie ("TextColor", "" , time()-"100");
$BGColor = -"WHITE";

$TextColor = "BLACK";
} else {

, PHP , $Reset.
cookies, cookie . .
3. if ($Reset).
setcookie("BGColor", "$NewBGColor", t i m e ( ) + "1000000");
setcookie ("TextColor", "$NewTextColor", t i m e ( ) + " 1 0 0 0 0 0 0 " ) ;
SBGColor = $NewBGColor;
$TextColor = $NewTextColor;

, $Reset , , 12.2.
4. HTML- , ( 12.3, 47).
<PxINPUT TYPE=Checkbox NAME=Reset VALUE=TRUE>Check this box to reset
the colors.<P>

, .
, HTML- .
5. ( 12.3), (. 12.11-12.13).

12 cookie
12.3
cookie . HTML- Reset.
1
I
3
4
5

<?php
if ($BeenSubmitted) {
if ($Reeet) {
setcookie("BGColor", "", time()- "100");
setcookie ("TextColor", "" , time()-"100");

$BGColor = "WHITE";

7
8
9
10
II
12

$TctColor = "BLACK";
} else {
setcookie("BGColor", "$NewBGColor", time()+ "1000000"];
setcookie ("TextColor", "$NewTextColor"., timed + "1000000");
$BGColor = $NewBGColor;
$TextColor = $NewTextColor;

13

>

14 } else {
15
if (!$BGColor) {
16
$BGColor = "WHITE";
17
}
18
if (!$TextColor) {
19
$TextColor = "BLACK";
20
}
21 }
22

?>

23
24
25
26
27

<HEAD>
<TITLE>User Customization</TITLE>
</HEAD>
<?php
print ("<BODY BGCOLOR=$BGColor TEXT=$TextColor>\n");

28

29
30
31
32
33
34
35
36
- 37
38
39
40
41
42
43
44
45
46

?>

Currently your page looks like this!


<FORM ACTION="cookies.php" METHOD=POST>
Select a new background color:
<SELECT NAME="NewBGColor">
<OPTION VALUE=WHITE>WHITE</OPTION>
<OPTION VALUE=BLACK>BLACK</OPTION>
<OPTION VALUE=BLUE>BLUE</OPTION>
<OPTION VALUE=RED>RED</OPTION>
<OPTION V ALUE=GREEN>GREEN</OPTION>
</SELECT>
Select a new text color":
<SELECT NAME-"NewTextColor">"
<OPTION VALUE=WHITE>WHITE</OPTION>
<OPTION VALUE=BLACK>BLACK</OPTION>
<OPTION VALUE=BLUE>BLUE</OPTION>
<OPTION VALUE=RED>RED</OPTION>
<OPTION VALUE=GREEN>GREEN</OPTION>
</SELECT>

47 <PxINPUT TYPE=Checkbox NAME=Reset VALDE=TRUE>Check thie box to reset


the colors.<P>

48 <INPUT TYPE=HIDDEN NAME=BeenSubmitted VALUE=TRUE>

cookie
49
50
51
52

<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">


</FORM>
</BODY>
</HTML>

setcookie () cookie
(. 12.1).
setcookie () - , - , cookie .

.

E* fie **
10 at
Thanamiendvalueodheajokie

This cookie wK PWMSI UWH Wed Dec 31 19:00:01 1363

,. !

. 12.11 ,
HTML-,
. cookies

. 12.12 setcookie () ,
,
cookie . , , cookie

SUM**

Currently your page looks like this!


Select a new background color: | WHITE jJ Select a new text color: |WHITE
Check this box to reset the colors.
SiAmill !

. 12.13 Reset
Submit, PHP cookie (. 12.12)


Web-

, ,
Web-. ,
,
.

include require
, HTML-, cookie ,
. , , . , , HTML- PHP-
Web-.
, , - , . ,
PHP- : include () require ( ) .
:
include("file.php");
require (".") ;

, . , require ( ) , ,
, , . include ( ) , ,

include require

, . require ( ) , ,
include ( ) ,
.
? ( , ,
include ( ) require ( ) , ). HTML,
PHP- . , include () require ( ) ,
, .
.
.
.
HTML- ,
.


1. PHP- .
<HTML>
<HEAD>
<TITLE>

.php, -,
HTML-
print ( ) .
2. , .
<?php
print ("$PageTitle");
?>
$PageTitle ,
(. 13.1).
3. HTML-.
</TITLE>
</HEAD>
<BODY>

4. , .
<TABLE WIDTH="75%" ALIGN=CENTER BORDER=0>
<TRxTD ALIGN=CENTERxB>Welcome to the Site!</Bx/TDxTR>
<TRxTD ALIGN=LEFTxP>

13 Web-

W.ltom. to Sit.!
Content for the borne pqp goei here.
*
Click < to go to the next page.

. 13.1 ,
, Web- , (. . 13.3)

.
, .
, .
,
.
5. header.php ( 13.1) Web.
13.1 , HTML, . , , .
1
2
3
4

5
6

<HTML>
<HEAD>
<TITLE>
< ?php

print ("$PageTitle");
?>

7
</TITLE>
8
</HEAD>
9
<BODY>
10 <TABLE WIDTH="75411 ALIGNCENTER BORDER=0>
11 <TRxTD ALIGN=CENTERxB>Welcome to the SiteK/Bx/TDxTR>
12 <TRxTD ALIGN=LEFTxP>

.
6. PHP- .
7. .
<Px/TDx/TR>

8. , , .
<TRxTD ALIGN=CENTERxSMALL>Copyright 2001</SMALLx/TDx/TR>

include require
9. HTML-.
</TABLE>
</BODY>
</HTML>

10. footer.php ( 13.2) . , .


13.2 ,
HTML-.
.
1
2
3
4
5

<Px/TDx/TR>
<TRxTD ALIGN-CENTERxSMALL>Copyriaht 2001</SMALLx/TDx/TR>
</TABLE>
</BODY>
</HTML>

11. PHP- .
<?php

12. $PageTitle.
$PageTitle = "Home Page";
$PageTitle
, . , , .
13. .
require ("header.php");
, ,
require () , .
header.php . , $PageTitle ,
.
14. .
print ("Content for the home page goes h e r e . \ n " ) ;
,. print ("<P>Click <A HREF=\"page2.php\">here</A> to go
to the next page.Xn");
.
, , .
15. .
require ("footer.php");
16. index.php ( 13.3) .

13* Web-

13.3 ,
require ( )
.
1

< ?php

2
3

$PageTitle = "Home Page";


require ("header.php");

4
5
6

print ("Content for the home page goes here.\n");


print ("<P>Click <A HREF=\"page2 .php\">here</A> to go to the next
page.\n");
require ("footer.php");

?>

,
, .
17. PHP- .
<?php

$PageTitle = "Second Page";


require ("header.php");
print ("Content for the second page goes here.\n");
require ("footer.php");
index.php, $PageTitle , print ( ) .
18. page2.php ( 13.4),
index.php (. 13.1-13.3).
13.4 ,
, 13.3. .
1
2
3

<?php
$PageTitle = "Second Page";
require ("header.php");

print ("Content for the second page goes here.\n");

require ("footer.php");

?>

.php, ,inc, .
,
.inc, .php - (. 13.4 13.5).


date ( ) , . date ( ) , .
, - :
date("formatting");

AUe*-CENTEK BOW>Ol.O>
<1 .1(-1>1 SlteK/BX/
*
'
01: the home pge O
k < m."ini3e!.H>p'
> ttt go to the* ntles J

. 13.2 , . , ,

* *

Welcome to the Site1


Content for tile second page goes here
Copyiig)it2001

. 13.3
, . 13.1, -

So B*i*fe*_tH>

,\
. 13.4 ., :
.
HTML-. .

13 Web-

<1>
<11>
Ophp

print ("I
?>
</TITLI>

<Tl>Lt -"75" 41.ION-CINTI BORDER-!


<TRXT U,I01-CDlTlR><>4eoe Co tin SltP</BX/Tl<TR>

. 13.5 .inc ( ),

. ,

6 , date ( " " ) ; AM


. . .5 ( ).
, date(" 1 F j , Y " ) ;
Friday January 2 6 , 2 0 0 1 .
date ( ) , . , ,
1 1970 -
Unix. 12, time()
. mktime () :
mkt ime(,,,,,);

, $Timestamp=mktime (12, 30, 0, 12, 27, 1 9 9 7 ) ; $Timestamp . 12:30 27 1997 . date ( " D " , $ Times tamp) ;, Sat .
date ()
mkt ime ( ) , .

date
1. PHP- .
< ?php

2. $PageTitle , .
SPageTitle = "Calendar";
require ("header.php");


3.
, . $Month
$Year , .
if ((!$Month) && (!$Year)) {
$Month = date ( " m " ) ;
$Year = date ( " Y " ) ;
, . (, 1) (, 2001).
4. , .
$Timestamp = mktime ( , , , $Month, I, $Year);
mktime ( )
, - . .
5. .
$MonthName = dateC'F", $Timestamp) ;
F, date ( )
(, January).
6. .
print ("<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 ALIGN=CENTER>");

7. .
print ("<TR BGCOLOR=BLUExTD COLSPAN=7 ALIGN=CENTER>
-<FONT COLOR=WHITExB>$MonthName $Year</Bx/FONTx/TDx/TR>") ;
8. .
print ("<TR BGCOLOR=BLUExTD ALIGN=CENTER WIDTH=20xB>
-<FONT COLOR=WHITE>Su</FONTx/Bx/TDxTD ALIGN=CENTER WIDTH=20xB>
-<FONT COLOR=WHITE>M</FONTx/Bx/TDxTD ALIGN=CENTER WIDTH=20xB>
-<FONT COLOR=WHITE>Tu</FONTx/Bx/TDxTD ALIGN=CENTER WIDTH=20xB>
-<FONT COLOR=WHITE>W</FONTx/Bx/TDxTD ALIGN=CENTER WIDTH=20xB>
-~<FONT COLOR=WHITE>Th</FONTx/Bx/TDxTD ALIGN=CENTER WIDTH=20xB>
-<FONT COLOR=WHITE>F</FONTx/Bx/TDxTD ALIGN=CENTER WIDTH=20xB>
-< COLOR=WHITE>Sa</FONTx/Bx/TDx/TR>/n") ;

, , . , HTML .
9. .
$MonthStart = dateC'w", $Timestamp) ;

13 Web-

( 0 6)
$MonthStart .
, . ,
: , ..
10. , $MonthStart .
if ($MonthStart == 0) {
$MonthStart = 7;
}
$MonthStart , , . ,
.
11. .
$LastDay = d a t e ( " d " , mktime ( 0 , 0, 0, $Month+l, 0, $ Y e a r ) ) ;

$LastDay (, 31,
28 30), .
($Month+l) mktime (}.
12. .
$StartDate = -$MonthStart;
, , .
- , $MbnthStart 2, , $startDate -2, .
13. , ().
for ($k = 1; $k <= 6; $k++) {
print ("<TR BGCOLOR=WHITE>");

6 , 6 .
14. , ().
for ($i = 1; $i <= 7; $i++) {
7 , .
15. $StartDate .
$StartDate++;
$startDate . .

16. for, , $StartDate.


if (($StartDate
print
} el'seif
print
}

<= 0) | | ($StartDate > $LastDay)) {


("<TD BGCOLOR=GREEN>&nbsp</TD>");
(($StartDate >= 1) && ($StartDate <= $LastDay)) {
("<TD ALIGN=CENTER>$StartDate</TD>");

$StartDate ( , ) ($LastDate), .
$StartDate ,
($LastDate), .
17. , .

}
print ("</TR>\n");

18. .
print ( " < / T A B L E > \ n " ) ;

19. HTML-, .
print ("<FORM ACTION=\"calendar.php\" METHOD=GET>\n");
20. : , .
print ("Select a new month to view:\n");
print ("<SELECT NAME=Month>
-<OPTION VALUE=l>January</OPTION>\n
-<OPTION VALUE=2>February</OPTION>\n

-<OPTION VALUE=3>March</OPTION>\n
-<OPTION VALUE=4>April</OPTION>\n
-<OPTION VALUE=5>May</OPTION>\n
-DPTION VALUE=6>June</OPTION>\n
-<OPTION VALUE=7>July</OPTION>\n
-<OPTION VALUE=8>August</OPTION>\n

-<OPTION VALUE=9>September</OPTION>\n
-DPTION VALUE=10>October</OPTION>\n

-<OPTION VALUE=ll>November</OPTION>\n
-<OPTION VALUE=12>December</OPTION>\n</SELECT>\n") ;
print ("<SELECT NAME=Year>
-<OPTION VALUE=2001>2001</OPTION>\n
-<OPTION VALUE=2002>2002</OPTION>\n
-<OPTION VALUE=2003>2003</OPTION>\n

-</SELECT>\n");
. , $Month $Year,

13 Web-

. , 5,
.
21. Submit .
print ("< INPUT TYPE=SUBMIT NAME=SUBMIT V A L U E = \ " S u b m i t i \ " > \ n " ) ;
print ("</FORM>\n");

22. .
require ("footer.php");
?>
23. calendar.php ( 13.5), (. 13.6 13.7).
13.5 -

13 Web-

, .

Welcome to tht Sit!

10 11 12 13

14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 I

Select a new month to view (January

3 I2001 J

Copyright 2001

. 13.7 -
, 20 ( ),
date ( " t " ) ; , . .

HTTP-
HTTP ( ) (Web-).
HTML, Web- http://.
HTTP- - , . HTTP- .
HTTP -


26

if (($StartDate <= 0) I I ($StartDate > $LastDay)) {

27
print ("<TD BGCOLOR=GREEN>&nbsp</TD>");
28
} elseif (($StartDate >= 1) && ($StartDate <= $LastDay)) {
29
print ("<TD ALIGN=CENTER>$StartDate</TD>");
30
}
31
}
32
print ("</TR>\n");
33 }
34 print ("</TABLE>\n");

35 // .

36 print ("<FORM ACTION=\"calendar.php\" METHOD=GET>\n");

37 print ("Select a new month to view:\n");

38 print ("<SELECT NAME=Month>


<OPTION VALUE=l>January</OPTION>\n
<OPTION VALUE=2>February</OPTION>\n
<OPTION VALUE=3>March</OPTION>\n
<OPTION VALUE=4>April</OPTION>\n .
<OPTION VALUE=5>May</OPTION>\n
<OPTION VALUE=6>June</OPTION>\n
<OPTION VALUE=7>July</OPTION>\n
<OPTION VALUE=8>August</OPTION>\n
<OPTION VALUE=9>September</OPTION>\n
<OPTION VALUE=10>October</OPTION>\n
<OPTION VAL0E=ll>November</OPTION>\n
<OPTION VALUE=12>December</OPTION>\n</SELECT>\n");
39 print ("<SELECT NAME=Year>
<OPTION VALUE=2001>2001</OPTION>\n
<OPTION VALUE=2002>2002</OPTION>\n
DPTION VALUE=2003>2003</OPTION>\n
</SELECT>\n");
40 print ("<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=\"Submit!\">\n");

41 print ( " < / F O R M > \ n " ) ;


42 require ( " f o o t e r . p h p " ) ;
43 ?>

Welcome to the Sit*1

: 1

10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Select a new month to view: (January

3 |2001

Copyright 2001

"-

. 13.6 . ,
, (. 13.7)

13 Web-
. .6

.>.'
Welcome to the Site'
Srptvnibrr 2003

Sa M Til \V Th F Sa
7

10 11 12 13

14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 I

Select a new month to view: (January

3 |2001 J

SutffiM |

Copyright 2001

. 13.7-
, 20 ( ),
date (" t " ) ; , . .

HTTP-
HTTP ( ) (Web-).
HTML, Web- http://.
HTTP- - , . HTTP- .
HTTP header ( ) . , , - . ( http://
www.w3.org/ProtocoIs/rfc2616/rfc2616.)
:
header("Location:page.php");
cookie- setcookie ( ) , :
header("Set-cookie:name=value;expires=expiration");
header ().., : , - Web-,
setcookie ( ) .

HTTP-
, , ,
, - .

header
1. PHP- :
<?php
2. .
$PageTitle-= "Login Page";
require ("header.php");
3. , ,
.
if ($Message == "Invalid") {
print ("<BxCENTERxFONT COLOR=RED>The username and password

you entered do not match what is on file. Please try again!</FONT>


-</CENTERx/B>\n") ;

,
$Message, Invalid. .
4. HTML- .
print
print
print
print

("<FORM ACTION=\"HandleLogin.php\" METHOD=POST>\n");


("Username: <INPUT TYPE=TEXT NAME=UserNamexBR>\n");
("Password: <INPUT TYPE=PASSWORD NAME=PasswordxBR>\n");
("<INPUT TYPE=SUBMIT NAME=SUBMIT V A L U E = \ " S u b m i t ! \ " > \ n " ) ;

5. -.
require

("footer.php");

6. login.php ( 13.6) .
13.6 ,
,
.
1
2
3
4
5

6
7
8

<?php '
$PageTitle = "Login Page";
require ("header.php");
if ($Message == "Invalid") {
print ("<BxCENTERxFONT COLOR=RED>The username and password you
entered do not match what is on file. Please try again!</FONT>
</CENTERx/B>\n");
}
print ("<FORM ACTION=\"HandleLogin.php\" METHOD=POST>Vn");
print ("Username: <INPUT TYPE=TEXT NAME=UserNamexBR>\n");

13 Web-
9 print ("Password: <INPUT TYPE=PASSWORD NAME=PasswordxBR>\n");
10 print ("<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=\"Submit!\">\n");

11 require ("footer.php");
12

?>

,
.
7. PHP- :
<?php

8. ,
$UserName $Password.
if (($UserName == "Larry") && ($Paseword == " L a r r y P a s s " ) ) {

,
. ,
, .
, . .
9. ,
.
header
exit;

("Location:

index.php?UserName=$UserName");

index.php.
.
exit; , .
10.
. .
} else {

header ("Location: login.php?Message=Invalid");


exit;

, .
login.php. ?Message=Invalid,
URL, login.php (. 13.6).
11. -.
?>
12. HandleLogin.php ( 13.7)
.

HTTP-

13.7
. , header ( ) .
1
2
3

<?php
if (($UserName == "Larry") && ($Password == "LarryPaes")) {
header ("Location: index.php?UserName=$UserName");

4
5

exit;
} else {

header ("Location: login.php?Message=Invalid");

7
8

exit;

?>

index.php,
,
13. index.php ( 13.3).
14. 4 :
print ("Greetings,$UserName!\n");
15. index.php ( 13.8), login.php Web-
(. 13.8-13.10).
13.8 , . $UserName header ( ) ( 13.7).
1

<?php

2
3
4

$PageTitle = "Home Page";


require ("header.php");
print ("Greetings, $OserName!\n");

print <"<P>Click <A HREF=\"page2.php\">here</A> to go to the next


page.\n");
-require ("footer.php");

fi tfmaiaat

*
Welromv to thv Sitel

Usemame: |berry
Password: I""*"
Submitl |
Copyright 2001

At.a .131 '

. 13.8

13 Web-

';
Welcome to the Site!
Greetings. Larry!
Chck hiire to go to the next page.
Copyright 200!

. 13.9 index.prip,

JHL

Golo.ihftp./t^^DMC^<^rcofiJphp/iQ3iaphp'1Ma^s3Qe-lwafaj jj (fjji'Whatf Ratatad fg|


Welcome to the Site)
The useiname 'and password you entered do not matth uiiat is on ,
Dense try a^ain'
Useraame: j
Password: I
Copyright 2001

. 13.10 , login .php


:
mail ("mailto", "subject", "body"};
mail ( ) , sendmail UNIX. ,
, , , ..
mail ("mailto", "subject", "body", "From: fromaddress");


1. PHP- .
<?php


2. .
$PageTitle = "Sending Emails";
require ("header.php");
3. .
if ($BeenSubmitted)

4. , .
if ($MailTo) {
if (mail($MailTo, $Subject, $Body, "From: $MailFrom")) {
print ("<BxCENTERxFONT COLOR=BLUE>Your email has been
-successfully sent!</FONTx/CENTERx/B>\n") ;
} else {
print ("<BxCENTERxFONT COLOR=RED>Your email was not
successfully sent due to a system error!</FONTx/CENTER>

mail ( ) , , .
5. .
} else {
print ("<BxCENTERxFONT COLOR=RED>Please enter the recipient's
-mail to address ! </FONTx/CENTERx/B>\n" ) ;

6. PHP- HTML-,
, ,
, .

?>
<FORM ACTION="email.php" METHOD=POST> Recipient's Email Address:
-<INPUT TYPE=TEXT NAME='"MailTo" SIZE="50"xBR>
, '
Your Email Address: <INPUT TYPE=TEXT NAME="MailFrom" SIZE="50"xBR>
Email Subject: <INPUT TYPE=TEXT NAME=" Subject" SIZE="80"xBR>
Email Body : <TEXTAREA NAME="Body" ROWS="10" COLS="50">
</TEXTAREAxP>
<INPUT TYPE=HIDDEN NAME=BeenSubmitted VALUE=TRUE>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE*" Submit ! " >
7. .
</FORM>
<?php
require ( "footer .php") ;

13 < Web-
8. email.php ( 13.9),
(. 13.11-13.14).
13.9
- mail ( ) . mail
, . .
1

<?php

2
3

SPageTitle = "Sending Emails";


require ("header.php");

4
5
6
7

if (SBeenSubmitted) {
if ($MailTo) {
if (mail($MailTo, $Subject, $Body, "From: $MailFrom")) {
print ("<BxCENTERxFONT COLOR=BLUE>Your email has
been successfully sent!</FONTx/CENTERx/B>\n");
} else {
print ("<BxCENTERxFONT COLOR=RED>Your email was not
successfully sent due to a system error!</FONTx/CENTER>

8
9

10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27

}
} else {
print ("<BxCENTERxFONT COLOR=RED>Please enter the recipient's
mail to address ! </FONTx/CENTERx/B>\n" ) ;
}
}
?>
<FORM ACTION="email.php" METHOD=POST>
Recipient's Email .Address: <INPUT TYPE=TEXT NAME="MailTo"
SIZE="50"xBR>
Your Email Address: <INPUT TYPE=TEXT NAME="MailFrom" SIZE="50"xBR>
Email Subject: <INPUT TYPE=TEXT NAME=" Subject" SIZE="80"xBR>
Email Body : <TEXTAREA NAME="Body" ROWS="10" COLS="50">
</TEXTAREAxP>
<INPUT TYPE=HIDDEN NAME=BeenSubmitted VALUE=TRUE>
< INPUT TYPE=SUBMIT NAME=" SUBMIT" VALUE=" Submit ! ">
</FORM>
<?php
require ( "footer .php" );
?>

,
( ). , , . .
.

Welrom* to the Site


Recipient's Email Address:
jphpeDHCinsigbCs.
Your Email Address:
Emafl Subject
jTeating PHP's Email Capabilities

EmaaBody
',"
This is the bod? of the email which will be sent,
The bod? can go over multiple lines!

Subtil
Copyright 2001

.31* .<_^.- <


. 13.11 HTML-

Wdccmu to the Site!


Your mail has been successfully seut]
R^ctpieat's Email Address:
I
Your Address:
I
Email Subject
I
EmdBody

CopynghliOOl

. 13.12 ,

13 Web-

Wtkome to the Site!


liter th? recipient's mail to address'
Recipient's Email Address:
Your Email Address:
I
Email Subject:
I
Email Body:

Subrratl
Copyright 3001

. 13.13 ,

-* So Muw Conwicmi H*

f ; a^ V-*u ""
n _ ( NmNtg ' *

Bec^Al FowMid _

fUl testing PHP1 Email Capabilities


X-POP3-Rcpt:php@DMCinsi^its.com
Date: Wed. 17 Jan 2001 14:07:40 -0500
To: pl4J@DMCinsights.com
Subject Testing PHP's Emau Capabilities
From: Person@Address.Com
This is the body of the email which will be sent.
The body can go over multiple lines!

a-r

---

. 13.14
, . 13.11

. , ,
, , .
:
, , . , ,
, Web-.


- , ,
, i. , , . 14.1.
, . ,
:
> ;
>- , , ;
> print ( ) .
- . , ,

14 f

, 12, . .
, . , , ,
setcookie ( ) header ( ) , HTML ,
, .
(. 14.2).
- ,
. - . ,
(. 14.1 14.2), . .
.
,
HTML- , HandleLogin.php
( 13).
fife *'*'-ft --*
Parse error: parse error in HandleLopn,php on Hne 2

' aj.
. 14.1 ,

*
Warning: Wrong parameter count for headerO in HaadfoLogm.php on bne 6

. 14.2 , ,
(, )


1. HandleLogin.php ( 14.1).
14.1 HandleLogin.php ,
, headers_sent ( ) .
1

2
3
4
5
6

<?php

if (($UserName == "Larry") && ($Password == "LarryPass")) {


header ("Location: index. php?UserName=$UserName" );
exit;
} else {
header ("Location: login. php?Message=Invalid" );

exit;

?>

2. PHP-.
(. 14.3).
3. PHP- .
if ( headers_sent ( ) ) {
print ("Cannot process your request due to a system error ! \ n " ) ;
} else {
headers_sent ( ) , -
HTML .
, header ( )
. , ,
.
, headers_sent ( )
, .
4. -!
5. HandleLogin.php ( 14.2),
login. php (. 14.4).
14.2 headers_sent ( ) cookie- ,
(. 14.3).

1
2

'

<?php

3 if ( headers_sent ( ) ) {
4
print ("Cannot process your request due to a system error! \n") ;
5 } else {
6
if (($UserName == "Larry") && ($Password == "LarryPass")) {
7
header ("Location: index. php?UserName=$UserName" ) ;

14
8

9
10

exit;

. } else {
header ("Location: login.php?Mess'age=Invalid");

11

exit;

12
}
13 }
14 ?>
, .

...

Wanting: Cannot add header information - headers already sent by (output started at
HandleLogin.php 1) in HandleLogin.php on line 6

-! at
. 14.3 cookie-
, Web- - ,

H*
Cannot process your request due to a system error!

IDocuMrit: Done"

. 14.4 headers_sent ( ) .
. ,
, , . 14.3




.
.

error_reporting ( ) ,
. error_reporting ( 0 ) . ,
. , error_reporting(E_ALL) . ( , .6 ( ) , .)
error_reporting ( ) , , error_log () ,
:
error_log()("message", "type", "destination"};
,
. error_log()
Web- , Web. , :
error_log()("message", "1", "php@DMCinsights.com");
email.php ( 13) , , , .

error_log()
1. email.php ( 14.3).
14.3 email.php, 13.
,
.
1
2
3
4
5
6
7
8
9

<?php
$PageTitle = "Sending Emails";
require ("header.php");
if ($BeenSubmitted) {
if ($MailTo) {
if (mail ($Ma'ilTo, $Subject, $Body, "From: SMailFrom")) {
print ("<BxCENTERxFONT COLOR=BLUE>Your email has been
successfully sent!</FONTx/CENTERx/B>\n") ;
} else {
print ("<BxCENTERxFONT COLOR=RED>Your email was not
successfully sent due to a system error!</FONTx/CENTER>

10

'

'

'

11
12

} else {
print ("<BxCENTERxFONT COLOR=RED>Please enter the recipient's
mail to address!</FONTx/CENTERx/B>\n") ;

13
14 }

14

15 ?>

16 <FORM ACTION="email.php" METHOD=POST>


17 Recipient's Email Address: <INPUT TYPE=TEXT NAME="MailTo"
SIZE="50"xBR>
18 Your Email Address: <INPUT TYPE=TEXT NAME="MailFrom" SIZE="50"xBR>
19 Email Subject: <INPUT TYPE=TEXT NAME="Subject" SIZE="80"xBR>
20 Email Body:<TEXTAREA NAME="Body" ROWS="10" COLS="50">
21 </TEXTAREAxP>

22 <INPUT TYPE=HIDDEN NAME=BeenSubmitted VALUE=TRUE>


23 <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
24 </FORM>
25 <?php

26 require ("footer.php");
27 ?>
2. 9 , .
error_log ("Unable to send an email to $MailTo from
$MailFrom at " . t i m e d . " \ n " , 3, "errors.txt");
, mail (} , . , $MailFrom $MailTo (
t ime ()).
, , , mail ( ) .
3. email.php ( 14.4) Web.
errors.txt, .
4. .
5. errors.txt email.php.
6. errors.txt, .
7. email.php (. 14.5-14.7).
14.4 email.php
error_log() , .
error_log ( ) , .
, .
' 1 <?php
2 $PageTitle = "Sending Emails";
3

require ("header.php");

4 if ($BeenSubmitted) {
5
if ($MailTo) {.
6
if (mail($MailTo, $Subject, $Body, "From: $MailFrom")) {


print ("<BxCENTERxFONT COLOR=BLUE>Your email has been
successfully sent!</FONTx/CENTERx/B>\n") ;
} else {
print ("<BxCENTERxFONT COLOR=RED>Your email was not
successfully sent due to a system error!</FONTx/CENTER>
</B>\n");

error_log ("Unable to send an email to $MailTo from


$MailFrom at " . time(). "\n", 3, "errors.txt");

10
11
12
13
14
15 }
16 ?>

} else
print (."<BxCENTERxFONT COLOR=RED>Please enter the recipient's
mail to address! </FONTx/CENTERx/B>\n") ;
}

17 <FORM ACTION="email.php" METHOD=POST>


18 Recipient's Email Address: <INPUT TYPE=TEXT NAME="MailTo"
' SIZE="50"xBR>
19 Your Email Address: <INPUT TYPE=TEXT NAME="MailFrom" SIZE="50"xBR>
20 Email Subject: <INPUT TYPE=TEXT NAME="Subject" SIZE="80"xBR>
21 Email Body:<TEXTAREA NAME="Body" ROWS="10" CObS="50">
22 </TEXTAREAxP>
23 <INPUT TYPE=HIDDEN NAME=BeenSubmitted VALUE=TRUE>
24 <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
25 </FORM>
26 <?php
27 require ( " f o o t e r . p h p " ) ;
28 ?>

Welcome to the S
Recipient's Emal Address
Your Emafl Address:
jPersoneAddress.com
Email Subject
Error Logging

Emafl Body:
forking, an error ill be logged to ercocs.txt.

Ld
.*>*[ i

. 14.5 email.php , .

14

tfs '<* io Comtncalw U*


Welcome to the Site'
Your email was Hot successfully sent dne to system error!
Recipient's Email Address:
I
Your Snail Address:

Email Subject:
I
Email Body:

Submitl |
Copyright 2001
'Document Dor

. 14.6 , , . (. 14.7)

' * Jearth 59** locb gmflgum ^

g1T ; ?.

JT
. 14.7 ,
. $MailTo
$ i I From,
,
. ,
, , 6
:
if

(imail($MailTo,$Subject,$Body,"From:$MailFrom")){


.
, .

, . , ,
.
:
> ;
> print ( ) ;
> .
, . , 12, . , ,
.
print ( ) ,
,
. , , . . print ( )
.
, , . print ( ) , .
, .
, HandleLogin.php (. ) , , .


1. HandleLogin.php (.
14.2).
2. .
-.
<?php
3. headers_sent ( ) ( 2) print ().
if ( headers_sent() ) {
print ("Headers have been sent. Not attempting to v e r i f y . < P > \ n " ) ; .
print ("Cannot process your reguest due to a system e r r o r ! / n " ) ;

- , ,
.
4. else ( 5) print ( ) .
} else {
print ("Headers have not been sent. Attempting to verify.<P>\n");

^HffT 14
print ("UserName is $UserName. <P>");
print ("Password is $Password. <P>");
print () ,
header ( ) .
print () , $UserName $Password. ,
.
5. i f ( 9) print header ( ) .
if (($UserName == "Larry") && ($Password == "LarryPass") ) {
print ("<P>Match! " ) ,
// header ("Location: index. php?UserName=$UserName" ) ;
exit;
} else {
"Match! ", , , .
, header ( ) , . , , .
6. else ( 13) print ( ) ,
header ( ) .
print ("<P>Not a Match!");
// header ("Location: login. php?Message=Inval id ");
exi t;

7. HandleLogin.php ( 14.3),
login. php (. 14.8-14.10).
14.5 HandleLogin.php , . print ( ) ,
.
1 <?php
2 if ( header s_sent () ) {
3

4
5

print ("Headers have been sent. Not attempting to verify. <P>\n" );

print ("Cannot process your request due to a system error !\n");


} else {

6
7
8
9
10
11
12
13
14
15
16
17
18
19

print ("Headers have not been sent. Attempting to verify.<P>\n");


print ("UeerName is $UeerName. <P>");
print ("Password is $Password. <P>");
if (($UserName == "Larry") && ($Password == "LarryPass")) {
print ("<P>Match!");
// header ("Location: index.php?TJeerName=$TJserName") ;
exit;
} else {
print ("<P>Not a Match!");
// header ("Location: login.php?Message=Invalid");
exit;
}
?>

Headers have cot been sent Attempting to verify


UserName is Larry.
Password is pass.
Not a Match!

. 14.8
.
,

Headers have not been sent. Attempting to verify.


UserName is Larry.
Password is LarryPass.
Matchl

. 14.9 ,
HandleLogin.php, . ,

header()

14

Headers have not been sent. Attempting to verify.


XJserName is .
Password is LarryPass.
Not a Matchl

. 14.10 . - . , UserName . : , login.php HandleLogin.php


die
- . ,
- , . , , . , MySQL ,
. ; email.php,
( UNIX), .
, .
die. , .
. ,
$Link=mysql_connect($Host,$User,$Password) or die
("Couldn't connect to d a t a b a s e . " ) ;
- ,
Couldn't
connect to database.
$Link=mysql_connect($Host,$User,$Password) or die (mysql_error()};
, ,
die mysql_error ( ) .
, MySQL.
: ,
or (, mysgl_connect) , ( die) .

die

, : ,
. , , , ,
or .
die ,
MySQL, .


1. PHP- .
2. HTML-.
<HTML>
<HEAD>
<TITLE>Die!</TITLE></HEAD>
<BODY>

3. PHP- .
<?php

// .

$Host = "localhost";
$User = "username";
$Password = "password";

$DBName = "database";
4. .
error_reporting(0);

die,

.
5. MySQL.
$Link = mysql_connect ($Host, $User, $Password) or die("Couldn't
connect to the d a t a b a s e ! " ) ;
MySQL.
- ,
Couldn't connect to database, .
: , ,
", . ( , error_reporting,
).
6. .
mysql_select_db ($DBName, $Link) or die (mysql_error () ) ;
, $DBName, ,
, MySQL.
7. MySQL -.
mysql_close ($Link);

14

8. HTML-.
Testing the die statement!
</BODY>
</HTML>

, - . ,
.
9. die.php ( 14.6),
(. 14.11-14.13).
14.6 , ,
. ,
die . die ,
( . 14.11
14.13).
12
3
4
5

6
7
8
9
10

<HTML>
<HEAD>
<TITLE>Die!</TITLEx/HEAD>
<BODY>
<?php

// .
$Host = "localhost";
$User = "username";
$Password = "password";
$DBName = "database";

11 error_reporting(0);
12 $Link = mysgl_eonnect ($Host, $User, $Password) or die("Couldn't
connect to thedatabase!");
13 mysql_select_db ($DBName, $Link) or die(myeql_error());

14 mysql_close ($Link);
15 ?>
16 Testing the die statement!
17
18

</BODY>
</HTML>

. @ ,
, , . :
$Link=@mysql_connect ($Host, $User, $Password);
@ ,
, , . die @ .

die
die .
, , :
$Link =@mysql_connect ($Host, $User, $Password) or
die(print_message("Couldn't c o n n e c t . " ) ) ;

Couldn't connect to the database)

. 14.11 die, . ,

Access denied for user'usemame@localhost' to database 'NewDatabase'

. 14.12 die
mysql_error (),
, MySQL

Warning MySQL Connection Failed: Access denied for user: 'usenuime@bcalhc-sf


(Using password: YS) m die.php on line 14
Couldn't connect to toe database!

. 14.13 ,
, ,
die. . . 14.11,

, ,
, . , , .
, .
. -,
? -,
? , UNIX (, Linux) Windows.
Web-,
UNIX- - Apache, , , .
Windows- IIS.
, :
, , PDF
Shockwave, XML ..
.
, Linux, Windows 2000.
, - .

Linux
Linux,
Web-, . . ,

Linux

. Linux
, , .
Linux- . - , Linux .

Apache
1. Apache ,
/usr/local/ (. ).
Apache http://www.Apache.org.
2. .gz,
( Enter ).
gunzip php-4.0 .Opll. tar..gz
gunzip apache_l.3.14.tar.gz
Apache, .
, (,
php-3.0.3pll).
3. .
tar -xvf php-4.0.4pll.tar
tar -xvf apache_l.3.14.tar

, ,
.
, (. .2).
4. Apache
(. .).
cd../apache_1.3.14
./configure-prefix=/www
cd . Apache,
.
5. (. .4) .
cd../php-4.0.4pll
. /configure-with-apache=../apache_l.3.14-enable-track-vars.

Iroo1*server

lroot*server

Ip*wafl
local]*

local!*

. .1 Is .
Apache

..
php-4.0.4pl t
php- 4.0.4pi t
php- 4.0.4pl 1 /Zend/2end_Jinguegt_*canmr.h
pftp- 4.0.4pl I /ZeM/ZV
.
php-4.0.4pnv2tnd/nd_Hst.h
- 4.0. 4pl 1 /Z*nd/ndJ IW.c
php-4.0.4pM/Zel/nd_JHt.h
pnp-<Q.4pt t /Zend/2*nd_OpcodB.C
.
.
_
.
php-4,0.4plt/Z*flaYtenLjpentorg.h
php- 4.0.4pl 1 /Z*nd/zend_ptr_3tKk.c
php-4.0.4pl 1 /Zan<l,/zend_ptr-atack.h
php-4.0.4plt/Zend/nd_iprintf.c
.
.
php- 4.0.4pf l /Z<nd/zend_*t*ck.h
pftp-^O^II/Zendrtendutatic-Jtlocatorc
php-4.Q.4pU/Zend/zend_*titlc_jlloctor.h
php-4.0.4pl1/ZefKl/ren<L.v,rlebl*e.c
php- 4.0.4
php- 4.0 4pl 1
php- 4.0.4pl 1
_
.
php- 4.Q.4pl I /2end/itnd_lengu9-pirMr.h
php-4.0,4pl 1 /Zend/zeM_l*nguap_c*nntr.c
php-4.0,4pl I /Zend/ndJng<M9f_cann(r^c.
php- 4,0. 4pt t /Ztnd/zend_)ni^MrMi' -output
php-4.0.4pl 1 /Zend/nd_lnl_prMr.e
php- 4.0. 4pl t /Zod/zendJni_pr3er.h
php- 4.0.4pl 1 /Z(Hl/nd_i ni_3cennere
php- 4.0. 4pl 1 /Zftd/wnd_inl_3ennr_jw;.ec
php-4.0.4pli/TSRri/
php-4.0 4pl 1 /TSRH/Mtkerile.ln
php-4.0.4plinSRM/UCEM5
php-4.0.4plinSRh/Mikefile.*m
php- 4 0 *4pl 1 /T3RM/TODO
php-4.fl.4pl 1 5/.
php- 4.0.4pl I nSRM/TSRM.d9p
php- 4.0.4pl 1 /TSRrbTSRH.h
php- 4.0. 4pl 1 /TSRM/eaunfig.h
php*4.04pM/TSRM/cinclui]t.in4
php-4 0.4pM n
php-4.0.4pl I it
php-4.0 4
php-4.0 4pl 1
php- 4.0. 4pl 1 /TSRM/thre*fc.m4
php-4.0.4plt/TSRf1/l3rm.m4
php-4.0.4pl 1 /TSRM/tsrm jonfig-w32 h
php- 4.0 4pl 1 /TSRM/tsrm_ronfigj;ommen.h
php- 4.0. 4p) 1 /TSRM/l3rm_strtok_r .c
ptip-4.0 4pnnSRM/trm_3trtok_r.h
php-4.04pl1/TSRM/lsrin_vtrtueljcvdx
php- 4.0.4pl 1 /TSRn/brnu.virtiNl_cwd.h
php-4.0.4pll/ecconfig.h
php- 4.0.4PM /9*neretU ist
php-4.0.4pM/mkin9telldir
php- 40 4pM/lD9taM-ih
php-4,0.4pl1/ecloeel m4
[roetsetver loeall*

. .2 tar
,

Vou nev heve succeasfully fuilt M tnattlled the |


Apache 1 .3 HTTP server. To verify that Apttche actually |
vorka correctly you now should It ret check the
|
( initially created or preserved) eonfiguretion file I
1
sr/local /apac he /conf/ Mtpd.conf
.
I
and then you should bal
I
Apeche the first time by running:
I
/wsr/loctl /apache //apechectl start
I
Or vhen you went to run It vlth SSL enabled us:
/usr/locel/apAche/bin/epKhectl Marts 1
1
Thanks for uaing Apache.
The Apache Group
http://vwv.epeche.org/ |
[root*serv

jU

. . Apache
. ,

Linux

1 root* server loctll*


Irwtserv*r pt.p-4.Q.4ptD*
CODIHCLSTANDARDS
JCREDITS
EXTENSIONS

c d p h p - 4. 0. 4p 1 1
1i

FUNCTION-LIST .
INSTALL
LICENSE
MtkefHe.fn
NEWS
- HEADME.BCMATH
README .CVS- RULES
README.EXTJSKEL
README D
README S ELF-CO NT Al NED- EXTENSIONS
REAOME.Zeu3
TOW)

ClOCi,m4
ePKtoC-Ml.t3rt

ft}:::
!-! ;1>St

confif.que
config.aub
-'/--t :,VL;:conTigureJn
:*v: i-N-n
dynllb.m4

;>-,[
php.lnl-dlit
pht>.,ni-cptimized
fhM (it
php4.3pec.in
,>

pidoe.txt
;-:;- !!

imherpm
mlatlmj

footer
J v ^ ' l IbJ

?,*:.*1 fi.

,"

Ins1*li-*h
Itconfiq

teconf if h
cconftij.h.in
t:\tK\\rtt.trt4
(rwt*server php-4,Q.4pl 1 1*

3tmp-h.in
,

j-^

. .4

,
. , . , Apache, , Apache. -enable-track-vars
HTML-.
6. (. .5).
make

make install

, Apache.

This w.ftvr it subject to the PHP License, evailable In


is

distribution ID the ril LICENSE. By continuing this Imt


Ittion |
process, you are bound by the terms of this I i cense gram
nt. |
f you do Mt gree vith the term* of IMi licen, you mu
tart |
the inttillation procts*t thit point.
I

hank yau fur ualno PHP.

. .5
,

7. Apache, , .
cd. . /apache_l .3.14. /conf igure-activate-module=rc/modules/php.4/libphp4 .a
make
make install
, Apache ,
.
8. php.ini .
cp/usr/local/php-4.0.4pll/php.ini-dist /usr/local/lib/php.ini
php.ini . php.ini-dist.
Apache ,
.
9. Apache,
bin/apachectl start
Apache Web-.
10. , Apache, (. .6).
on-line, ,
http://www.DMCinsights.com. offline, http://localhost/ IP- .

:
Test Page
Thto page is used to test 0 propei optiitun of the Apache Web sewer after it Has been installed. If you can nad Otis page. It means that the Apache Wett semr iwttBed at
this site is working property.

If you are the administrator of this website:


VOu nay now add content to this directory, and repto this page. Note thit unul you da so, people siting your webshe win see thto page, and in) your content.
you taw upgraded ( Rid Hat Linux 6.: and euUer. then you a seeing this page because the default nt in /tc/httpd/conf /bttpd . coaf has
chaned Any subdiiectoriM which * fed under /ho* /bttpd should now mowed to //wrw. Altetnatvely, the cDittenb of /v*r / be moved to /bc**/bttpd.

If you ore a member of the general public:


Tlw ftd mat you an seeing Otic page mdteabs tbt thf wetuite you Just visited either experatncing problems, or undergoing iiuuntenfliK*.
If you would Uto to let dmiiurtto> of vebsite know that you've seen tWi page instead of the page you expected you shouil aeml them e-mail In general, mail
stnt to the nime "wtbmaitef nddtncM to tnt ebdtt's shooklnach the ajipmpiwte person
For example, if you experienced problem dub raffing www example .com. you shoutl send e-mail to "webmastei^estampfc com*.

Tne Apwhe docanieji^JieB ^ been incltKM With thli C


For docimenBUon and on Red Hat Linux, pleaie visit the Red Hat Inc. mbsite Tlw iMniud for Red Hat Llitux Is available here
You are fiee to use the image below on an ApacKe-poweied Web umi ftr usuig Apache !

FXV ITS f-i


You aie fe To use thl image betow on a Red Hit Unux-powend Web sener Thante for using Red Hat Lmi>

ll)|r<>dhat

. .6 , Apache

Windows
test.php (. 1).
Linux ( Linux- 16 , 1 90 !), Web- Windows- .

Windows
Apache Windows- ,
Linux-, .
, .
Windows 95, 98, ME, NT 2000, , Windows, Apache
. , Jr JriP

Apache
1. , Apache (. .7).

. .7 Windows


2. (, C:/php). -.
3. Apache, (. .8).

Choose wWch proo/wn feahtes you went (nstafed wwwtwff me*


wit mealed. Recommended for" advanced users.

.-A.8 Apache

4. php.ini-dist (. .9)
(, C:/windows). php.ini.
021
bfc

View

Favorites

Tod*

php

LICENSE

php

mibs

pdf^elated

peat

php.ini-dKt

php.irt-cpti,..

phfrt

- 1*1a
sr
php4ls.cffl

php4Cs

. .9 PHP- C:\php

5. Apache.
'
- Start >- Programs >
Apache Web Server >- Start Apache.
6. , Apache.
Apache - http://localhost/ .
test.php.
Windows- Web-, IIS.

, . php.ini, ,
(. .11).
. -
php.ini php.ini-dist,
.
, ,
mcrypt ( ) ..,

!*~ Format Help

About

'tMs'H^e'controls
f1l,e controls many
mai
aspects of PHP'S behavior, in order for PHP to
read 1t,'
' ' it
' must be named 'php.ini'. PHP looks for it in the current
.._. ...ng directory, in the path designated by the environment variable
PHPRC, and in the path that was defined 1n compile time (in that order).
under windows, the compile-time path 1s the windows directory. The
path 1n which the php.ini file is looked for can be overriden using
the -c argument in command line mode.

Directives are specified using the following syntax:


directive - value
Directive names are "case sensitive" - foo-bar is different from FOo=bar,
The value can be a string, a number, a PHP constant (.e.g. E_ALL or M_PI), one
of the INI constants (on, off, True, False, Y e s , NO and None) or an expression
(e.g. _ALL & ~_NOTICE), or a quoted string C"fo").
Expressions in the INI file are limited to bitwise operators and parentheses:
|
bitwise OR
&
bitwise AND
bitwise NOT
\
boolean NOT
Boolean flags can be turned on us-1nq the values 1, on. True or Yes.
They can be turned off using the values o, off. False or NO.
An empty string can be denoted by simply not writing anything after the equal
sign, or by using the None keyword:

f oo foo - none
foo - "none"

; sets fob" to an empty string


; sets foo to an empty string
; sets foo to the string 'none'

. ,10 php.ini - ,

thought of.
reg1ster_argc_argv
argvAargc

; This directive tells PHP whether to declare the


; variables (that would contain

the GET Information), if you


should turn It off for

Magic quotes
ag1c_quotes_gpc
aglc quotes_runt1meSQL. from execQ, etc.
igic_quotes_syoase
istead of V)

; don't use these variables, you


: Increased performance
; Maximum size of POST data that PHP will accept.
; This directive Is deprecated, use

post.jnax_s1ze
jpQ.order"
var1ables_order instead.
off
-

; magic quotes for Incoming GCT/POST/cooMe data


magic quotes for runtime-generated data, e.g. data from
; use syfaase-style magic quotes (escape ' with ''

automatically add files before or after any PHP document


ut o_pr epend_f11e
uto_append_f1le
-

li

As of 4,0b4, PHP always outputs a character encoding fay default 1n


the content-type: header. To disable sending of the cnarset, simply
set 1t to be empty.
PHP'S built-in default 1s text/html
efault_m1metype - "text/html"
default_charset "1so-8859-l"
'patns'and Directories';
UNIX: "/P hi: /pat h2" windows: "\pathl;\path2"
doc_root
; the root of the php pages, used
only 1f nonempty
user_d1r

j the directory under which php


opens the script using /-usemame, used only If nonempty
extens1on_d1r
./
: directory In which the loadable
extensions (modules) reside
enable__dl
- O
; whether or not to enable the dlQ
function.

. . 11 v php.ini , ,

, ,
php.ini . php.ini . .

,
-. ,
, .
.
, ,
Internet, .

SSL
- () ,
. , PGP, http://www.pgp.com (. .1).

. ,
crypt ( ) , , .
crypt () .

, mcrypt http:/mcrypt.hellug.gr/ mcrypt.
mcrypt ( ) , . mcrypt ( )
.
- ,
, .

Protect your company s privacy


In storage, in transit,
during access, in your steep.

Healthcare Security Newsletter


Important informalion about HIPAA,
technology, privacy, and security

^
PGP .Celebrates Ten Year Anniversary of Landmark Encryption Product
-McAfee and PGP Security Advisa U^ers of Potential Risk from, Chirtgae Hatkys
McAfee and PGP .Security TOP Secure Comnulmg Awards
P_Gg_Sgcyrity PsiivefgjViae^SJigrigijgpSfJj's

Sign Up Now
{Enter E-mail Address

Abvut PGP Scirftv

MAI

Pi*.

CvMt*

y Petkf

Cvnbct

S*txh

. .1 PGP,

SSL.
SSL, , - (Web-) . SSL ( https:// URL)
. SSL cookie, setcookie ( ) . , SSL.
PHP- .
mcrypt (), crypt () , ,
.

-
,
CGI- ASP, .
, .

-, ,
, Web-. Web- . ,
, URL . , Web-,
.
, :
require ( " . . / s e c u r e . p h p " ) ;
secure.php, ,
(. .2). Internet,
Web-.
HTML. , ,
POST, GET URL, .
, ,
. , HTML-
JavaScript . , ..
,
(. 8).
H*

8 of 0 k in 0 of 0 film elected

0 of 0 k JnU of 0 file tttoctttti

tt/>|

z!

. .2 Web- (www dmcinsights-www)


. , , , secure.php

*
,
, .


Web-,
Web- , .
Web-,
. , -, :
>~ http://www.cert.org:
> http://www.security-focus.com:
> http://www.packetstorm.security.com:
> http://www.w3.org/Security/Faq/www-security-faq.html.
, ,
Web- Windows NT
Linux.
, . ,
. , MySQL, MySQL.


PHP

-
.
.
PHP-
Internet , .


,
.
PHP- http://www.php.net/docs.php (. .1) . : PDF, HTML, ,
Palm. Web- (http://www.php.net/manual/net), , .
.
.
, . . :
array f i l e (string filename [, int use_include_path])
int mysql_close ([int link_identifier])
void exit(void)
double round (double val)

"

FAQ

i :

~ ' ' ' " ' "

PHP Manual

The PHg..FAQ is your first :


stop for general
: The PHP manual is available in a selection of languages and formats. Pick a language and formal from the table
Information and those
below. Tip: If you are using Internet Explorer, Opera or Netscape 6, the file size will show up, when you move the
questions that seem to : mouse above one link. If you use another browser, or would like to see alt the information, you can pljck.be_ta
be on most people's
:
minds.
:

Books

goolfc are convenient


\
resources to begin
exploring PHP. The titles ! English
Ijjtgd'hgrs will help you
to start learning PHP, as
wetl as extending your
existing knowledge.
;

Sample Code

View ~
Many Many
View Online Single Plain HTML HTML
Online (plain) HTML text flies flits
iigw

Poiiuguest

vjgw.

bMi.gz liLufc tsr^z

ylgw

html_gz t

2iE

_gi lajiai

view

PDF
Documentation
Unavailable
Temporarily

P.lmPMol PalmPilcl
DOC,
ISIIo

dpc.ptjt-

HTML
Help
thrn

PDF
Documentation
Unavailable
Temporarily

Looking for some more |


sample PHP scripts?
";
Qur jinks . page lists ;
some archives of

sample PHP code;


great places to find many ;
example scripts and
:
:
useful
functions,
organized for your
:
searching pleasure!
:

PDF

jig

PDF
Documentation
Unavailable
Temporarily

yjgw html.gz i

PDF
Documentation
Unavailable
Temporarily

html.gz I.

PDF
Documentation
Unavailable
Temporarily

blml.cjz lit.gz tar gz

PDF
Documentation
Unavailable
Temporarily

dgc.pdt;

isijg. pdb

chrri

isjjo^pdb,

chrp

PDF

Document Done

. . 1 , . ,

, , . f i l e ( ) ,
mysql_close ( ) - , exit () , round () ( ).
( ), . . , exit ( ) , round ( ) ,
mysql_close ( )
link_identifier.

Web-
Web-, . , .
, .

Web-

- (
http://www.php.net).
-,
Zend.com (http://www.zend.com).
, .
PHPBuilder
(http://www.phpbuilder.com). , ,
(. .2). ,

.
PHPstart4all (http://php.start4all.com) - , . PHP-,
, , PHP-
, .
Resource Index (http://php.resourceindex.com)
, (. .).

articles

J( Application Architecture
Miscellaneous
VVeb&ox fFuseboxl Architecture
" Hpw T? Document VoyrP-HP Classes
Smart Architectures in PHP
' PHPLJb and Multiple Databases
1
Best Practices: PHP Coding Style
' Fundamentals of Appjigatign Dejia
1
The Need fpr Sfleed
> Obje.ct Oriented
Obiect Orientation
PHP ano* CJgsseg
Security
Cornpigte, Secure User Auth Library
Check Data
> Session Management
p Segsioq Handlers in PHP4
t in_PHP4
Session
1

forums

ftij Authentication v
> Shopping C^rts
" v Shopping Basket with only PHP4 S
Anaeom .
> Transactions

, . _
_ _
" Introduction to WML. Aoache. and_PHP.
EuHdino WML Sites
Databases
Any Database
MySQL and j
Building Ngxt/Pjev Buttons
o Binarv.pa.ta.
. . . ln_a_QB
__
site?
So u want to use jj database i
Database Normalization and Desicin Techniques
Storing Checkbox Data in a Database
Building Next/Prev Buttons tor Query Results
SOL Theory & How-To

. .2 PHPBuilder ,
(, ) (, - )

fa .. .

f RESOURCE INDEX
; 806 ^ reJated rswr<;s m more than Jsft c<steorig$
SEARCH - WHAT'S NEW - USER REGISTRATION - CONTACT US

[ Search | What's New |


Currently B2B PHP resources fisted in 192 categories at The PHP Resource index.
Hundreds of -made programs of all
sorts ready for use on your web s*e,
comments to help others
Functions aftd Classes f IPS)
identify better resources!
Although not complete scnpts, these
- ---- ~ ..... ---- ~ --------
code pieces aid in development and often
User Registration
with tittle modification can become
Get E-Mail Updates,
complete programs .
rate and comment on
resources, and more!
(200)
Information, books, tutorials, examples
U ?|5 slte
s
Wslt
more

J POPKmark
*"file
and help regarding PHP programming. If
should make it easier.
you want to learn it, here's how.
Includes! Egamplgs; and Tutorials (134)
& <*6)
There is a large PHP community and this
is where you'll find resources such as
jobs, chats, message boards, developer
sites and much more!

g} "Fbfc

2000 Th.lU?hP-JlWJ

P*it of tht i
A Product af Mm't Scri&t

DoOCTrt: Dora

. . PHP Resource Index ,

:
> WeberDev (http: / /www.weberdev.com /maincat.php3?categoryID= 1 06&category
>-HotScripts ('http://www.hotscripts.com/PHP/).
Web-, , - PHP Coding
Standard (http://utvikler.start.no/code/php coding standard.html). ,
, .. . , , .
,
,
. alt.php. alt.php
Usenet. . '
' http://phpclub.unet.ru . . . .


, , .
MySQL, PostgreSQL. .
MySQL Web- MySQL (http://www.mysql.com. . .4). . MySQL,
MySQL 21 (Mark Maslakowski)
(Tony Butcher), MySQL mSQL (RandyJay Yarger),
(George Reese) (Tim King), O'Reilly.
PostgreSQL
(http://www.postgresql.org). - PostgreSQL: -
(Bruce Momjian).

**

"6QL
<decent>

MemeBag

Site Map
Order Support
Partners
Books
Jobs
Advertising
Contact
join Mailing Lists

Latest Verelorts
2001*06/11

- Help MySQL Take our Survey!


2001 AM
News
Articles
Information
Documentation
Support
Training
Downloads
Development

Defining P2P

200IDS 05

Heli> MvSOL -Take Oai Siiivev!


MySQL AB needs your help to make MySQL even
better! Please take 10 minutes to fill-out our gufxsy.
We need this information to help us develop MySQL
to suit future needs. This information will also help us
know what services we may sell to support our
development work. You can provide this, so please
help us!

3.23.39

Ptofesslonal Tialni
n Joins MySQL AB
MySQL AB today announced that a professional
MySQL training team has joined the company, Mr,
Kaj Arno. heading the group, has been appointed Vice
President responsible for building and developing the
MySQL
training
program,
certification
and
documentation. Arno and his crew join from Polycon
AB. a company he co-founded in 1987 and that he
has been running sucessfully as CEO since then.

prt and
Com mejcialJftyJjQ. L
Ljcen$es

3.23.39
1.7.5
1.7.9

2.5037

Rll out our *urvy and


you might be the lucky
winner of one of

Blue We,ltd and MySQL AB to Deliver Embedded


Laaso MySQL Database
Blue World Communications. Inc.-pioneers of the
Web Data Engine(tm] and MySQL AB, developers of
MySQL [tm]--the most widely used database on the
Internet today announced strategic relations and a
licensing agreement for the distribution of MySQL
embedded in editions of Lasso Professional 5. The
embedded MySQL database for Lasso Professional
5. e.g. Lasso MySQL, provides Lasso developers a
powerful SOL database server as an integral part of
Lasso Professional 5.

. .4 Web- MySQL MySQL

,
(MichaelJ. Hernandez) . MySQL PostgreSQL,
, .


,
, , , ,
.
- . ,

. - , Java (
, - ).
Zend.com (http://www.zend.com/zend/tut/class-Intro.php. . .5).
, , - - , - .
,
.
, , , .
, , ,
.
10.
UNIX- ,
UNIX ( man), (Elizabeth Castro) PERL CGI .
UNIX, , UNIX.
Windows-,
Microsoft (http://www.microsoft.com) Windows.
, , ,


.
. ,
. -
.

" <$* What's Related

J& toC4borr[hlip7/www

I Tutorials /An Introduction to Classes

Tutorials
inlet-Platform
Using PHP

By Duncan Latitl) Witli Zend Staff


March 28, 2000

Dron-dDwn a PHP List

EtJL
Serving Qraphjc.al Webf age CojjntBjs
An farti eduction to Classes
Dynamic ImMeQenejatianwilh PHP

lnftggtrtj;turg_far^8ndjina gadReferral .
Cbeckifjg th_g Referral Link

Sesjgioq Handling with PHP


PuttinaAH the Securtt^ Functions T
S Y[$w arintgDIe ^rmat
^gnd inis jTticie to afaend
,( NQtifyjne, when a_oew article

Chanoijq thgjaj Reference ggsiirjatigr] P^oe

LM&
Target Atittince
This tutorial is designed for the intermediate to advanced-level PHP programmer.
hflfottuction
This tutorial teaches you how to write and use classes, to make your PHP code more flexible and easier to manage.
The tutorial guides you through the construction of a simple, security-related class that performs some basic .security functions for
a web site: checking user logons. The class Implements security features that answer some needs for a number of current
security models and could be easily implemented at most dynamic Web sites. Note that thlsclass does not provide a full security

. .5 Zend.com -

. , , .


.1 , (
). , ,

and

or
.2

$
+

?
\

\t
\

()
|

{2]
{1,}

, , ..

[a-z]
[-zl

[0-9]

. , ,
.

[ [: alpha: ] ]
[ [: digit 1 ] ]
[ [: alnum: ] ]

[ [: space: ] ]

[ [! upper: ] ]

[[.lower:]]

[[:punct:]]


.4 ,
- , ..

( ,
,
)
( ,
)

W+

( ,
,
)

( , )

.5 - ,
. , date ()

am

A
d

AM
: 01 31

, : Sun, Mon ..

, : January
12- : 1 12

24- : 0 23

12- : 01 12

24- : 00 23

i
j
1 ( L)
m

: 00 59
: 1 31
, : Sunday
: 01 12
, : Jan

(): 1 12

s
s

; 00 59
: th, nd, rd ..

: 28 31

: 0 () 6 ()

: 01

: 2001

: 0 365


.6 ,

E_ERROR

E__WABfJING

E_PARSE

E_NOTICE

16

E_CORE_ERROR

. 4.0

32

E_CORE_WARNING

64

E_COMPILE_ERROR

( ) . 4.0
. 4.0

128

E_COMPILE_WARNING

. 4.0

256

E_0SER_ERROR

. 4.0

512

E_USER_WARNING

W24

E_0SER_NOTICE

. 4.0
. 4.0

E_ALL


195

86

3
35
55
! 87
!= 84
# 29
$ 33
$ , 132
% 107
&& 87
() 57
() 24
() , 137
* , 132
* 51
+ , 132
+ 51
++ 55
- 52
. 65 k
. , 132
/ 52
< 84
<= 84
= 36
== 84
> 84
>= 84
? , 132
? URL 46
@ 135
@ 258
[] 110

[] , 138

, 132
_ 33
{} 80
| ,
133
11 87
URL 67
24
35
, 132
27
25, 35

null 149
(true) 80
80
(false) 80

74

180
28
HTML 31

74
131

35, 109
132
138

AND, 87
break 95

4ERT

die 256
for 106
global 157
if 79
if-else 89
if-elseif 91
if-elseif-else 91
if-then 79
if-then-else 89
NOT, 87
OR, 87
require() 224
return 152
switch 94
while 101
XOR, 87
80
84
84
107
86
84
84
84
56
36
84

32
157
35, 109
157
38
36
34
34
34
131

168
167

166
168
38

abs() 59
addslashes() 71
array_merge() 114
arsort() 119
asort() 119
ceil() 59
closedir() 189
copy() 185
crypt() 72
date() 228
decrypt() 72
die 256
each() 116
echo() 24
encrypt() 72
ereg() 133
ereg_replace() 140
eregi() 133
eregi_replace() 140
error_log() 249
error_reporting() 249
explode() 121
file() 173
filesizeO 188
floor() 59
fopen() 167
fwrite() 168
header() 236
headers_sent() 247
implode() 121
include() 224
is_writeable() 172
join() 125
krsort() 119
ksort() 119
mail() 240
md5() 73, 75
mkdir() 180
mktimeO 230
opendir() 189
phpinfoQ 20
printO 21, 23

printfO 24, 53
rand() 59
readdir() 189
rename() 188
round() 58
rsort() 118
setcookieO 212
shuffle() 119
sort() 118
sprintf() 55
srand() 59
stripslashes() 71
strlen() 75
strtokO 74
substr() 75
trim() 62
unlink() 185
urldecode() 71
urlencode() 67
148
152
145
197
149
161
145

for 106
while 101
106

34
59
34

131

35

Cookie 211
218
212
220

DMKSSH33

, ,
.
Internet-
www.dmkpress.ru.
,
, , , . Internet-
, : , ,
.

Internet- www.dmkpress.ru.
, ,
;
--""''
1
: /ffrpcffljio--'
, ; \
' -^ ,
,

,

.
.


:
:
:
ISBN:

'

. .
70x100 16
592 .
5-94074-064-2


, . , ,
386 Pentium III, MS-DOS, Windows 3.x,
Windows 95/98 Windows ME.

, . , Microsoft
Office 2000, Paint Imaging, Web Internet Explorer 5 Outlook Express 5, .
, ,
,, , Internet.



:

107014, , / 468

. (095) 962-1703

E-mail:

sale@dmk.ru.
dmk@home.relline.ru

-:

http://www.dmkpress.ru

369-7528


. .
. .
. .
". .
. .
. .
. .
01903 30.05.2000
30.06.2001. 7016.
. .
. . . 18. 3000.
. 1727
, 105023, , . , . 2/8.
: www.dmkpress.ru, info@dmk.ru

104100, ., . , ., 1