848
По договору между издательством "Вильямс" и Интернет-Магазином "Books.Ru - Книги России" единственный легальный способ получения данного файла с книгой “PHP 5 для начинающих ” (ISBN 5-8459-1039-0) покупка в Интернет- магазине "Books.Ru - Книги России". Если вы получили данный файл каким-либо другим образом, вы нарушили законодательство об охране авторского права. Вам необходимо удалить данный файл, а также сообщить издательству "Вильямс" где именно вы получили данный файл.

PHP 5 для начинающиx

  • Upload
    serjum

  • View
    132

  • Download
    1

Embed Size (px)

DESCRIPTION

PHP 5 для начинающиx

Citation preview

"" - "Books.Ru - " PHP 5 (ISBN 5-8459-1039-0) "Books.Ru - ". - , . , "" .

32.973.26 018.2.75 M52 681.3,07 . .. .. : [email protected], http://www.dialektika.com 115419, , / 783; 031150, , / 152

, ., , , , , , , , , , . M52 . PHP 5 . : . . . . . ISBN 5 8459 1039 0 (.) . : .. , 2006. 848 . :

PHP. PHP, , , , , PHP 5. , PHP HTTP , XML, (MySQL SQLite), PHP . , UML, PEAR PHP , , . 32.973.26 018.2.75

. , , , JOHN WILEY&Sons, Inc. Copyright 2006 by Dialektika Computer Publishing. Original English language edition Copyright 2004 by Wiley Publishing, Inc., Indianapolis, Indiana. All rights reserved including the right of reproduction in whole or in part in any form. This translation published by arrangement with Wiley Publishing, Inc. Wiley, the Wiley Publishing logo, Wrox, the Wrox logo, and Programmer to Programmer are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

ISBN 5 8459 1039 0 (.) ISBN 0 7645 5783 1(.)

, 2006 , , by Wiley Publishing, Inc., 2004

1. PHP 2. 3. PHP, HTML 4. , 5. 6. 7. 8. XML 9. SQL 10. MySQL PHP 11. PHP MySQL 12. 13. UML 14. PEAR 15. PHP5 16. 17. : PHP . . PHP . SQLite . ODBC . CLI PHP . PHP5 24 34 65 99 159 220 264 292 343 372 418 442 485 518 552 589 606 633 688 710 774 790 804 813 837

22 24 26 26 26 27 29 30 31 31 32 32 34 35 36 36 37 37 38 38 38 39 40 40 43 50 51 53 53 55 57 61 62 62 63 63 63 64

PHP? , p2p.wrox.com

1. PHP PHP , PHP PHP, php.ini ? PHP 5 PHP Linux Apache RPM PHP 4 PHP 5 Apache PHP Apache PHP 5 Apache PHP 5 Windows 2000/Internet Information Server 5 PHP 5 php.ini PHP php.ini PHP

7

2. PHP PHP Web ( ) PHP PHP PHP Web Web : Internet HTTP TCP/IP HTTP HTTP HTTP PHP HTTP Web PHP PHP global PHP PHP PHP sort() asort()

65 66 67 68 68 69 69 70 70 70 71 72 72 73 74 75 76 76 76 76 77 77 78 80 80 80 81 81 81 82 83 83 87 88 93 94 94 95 95 96 97 98 98 99 99 101 101

3. PHP, HTML HTML HTML DTD form input

8

PHP HTTP HTTP HTML ( Web ) HTML URL PHP ( ) HTML ( ) submit reset PHP , Cookie PHP 103 104 104 106 106 109 110 111 111 111 112 114 116 116 118 119 119 120 122 124 124 126 127 129 130 131 134 136 137 138 138 140 143 144 145 145 146 146 146 151 153 155 157 157 159 159 160

4. , PHP

if > < == === != (AND, OR, !) switch while do while for current() key() next() prev() list() each() sort() asort() rsort() arsort() ksort() array_multisort()

9160 161 161 161 162 164 164 165 166 166 168 169 170 172 172 174 176 179 181 181 181 184 187 188 189 191 193 196 197 198 200 202 203 203 204 205 206 207 207 207 208 209 209 210 212 214

10

foreach 215 217 217 218 220 221 221 222 223 223 223 224 224 227 227 228 230 231 232 232 232 232 233 233 234 234 236 238 239 239 241 242 243 244 247 249 250 251 252 253 254 254 254 255

5. , PHP PHP PHP PHP PHP5 echo() HTML exit HTML : HTMLSpecialChars() ereg() URL PHP

Try/Catch PHP5

11255 259 262 263 264 265 265 265 266 267 267 268 270 271 272 276 277 278 279 279 280 280 280 281 282 283 285 285 287 288 290 290 291 291 292 293 294 294 294 297 297 298 298 298 300 302

6. , PHP include require

7. fopen() fclose() fread() fwrite()

12

is_dir() is_file() , 305 306 309 310 311 313 314 316 318 319 319 320 322 323 324 325 327 332 337 341 342 342 343 344 345 346 346 347 348 349 350 351 352 352 353 353 358 359 362 363 363 363 364 364 365 366

8. XML XML XML XML XML XML XML : DTD XML DTD XHTML DTD XML XML XML XHTML Web PHP XML XML PHP4 XML DOM DOM PHP XML PHP5 SimpleXML simplexml_load_string() simplxml_load_file()

simpleXML

13368 370 371 371 372 373 374 374 374 375 375 376 377 377 378 379 380 381 382 382 384 384 385 385 385 387 388 390 390 391 392 393 394 395 395 396 397 397 398 400 401 404 405 409 411 412 414

9. SQL / MySQL Windows MySQL Linux MySQL RPM MySQL MySQL (1NF) (2NF) (3NF) SQL SQL MySQL mysql SQL GRANT REVOKE GRANT REVOKE MySQL PHP PHP MySQL MySQL PHP

14

415 416 417 418 418 421 421 422 423 425 426 427 427 431 432 432 432 433 433 433 434 437 440 440 440

10. MySQL PHP PHP SQL common_db.inc html_header() html_footer() error_message() userviewer.php list_records() view_record()

11. PHP MySQL PHP htmlspecialchars() ENUM register.php in_use() register_form() create_account() auth_user.php access_logger.php

442 442 443 444 445 447 450 451 454 456 458 459 460 460 461 462 464 466 467 469

userman.php user_message() list_records() delete_record() edit_record() edit_log_record() view_record()

15473 473 474 474 474 475 476 477 480 482 483

12. ? OO __get __set PHP5

485 485 487 488 489 489 490 491 492 493 494 495 496 499 499 501 502 506 507 510 512 512 513 514 516 517 517 518 518 519 519 520 521

13. UML UML? UML

16

UML UML Entity PropertyObject , DataManager Entity, Individual Organization 521 526 526 527 527 529 535 535 537 541 542 549 551 552 553 553 554 554 555 555 555 556 557 557 557 558 558 559 559 569 572 574 574 574 575 575 577 578 581 585 587 589 589 590 590 592

14. PEAR PEAR? PEAR PHP PHP PEAR PEAR , PEAR PEAR pear.php.net PEAR PEAR PEAR Windows PEAR , ? PEAR XML radiogeneratexml.php radiorequest.php : radiogeneratexml.php : radiorequest.php

15. PHP5 e mail Internet e mail e mail PHP

mail() Internet (MIME) MIME MIME PEAR PHP e mail

17592 593 595 595 595 597 597 604 605 606 607 607 607 608 609 609 609 610 610 611 612 612 613 613 614 616 618 618 620 620 620 622 624 624 627 628 628 629 631 631 632

16. copyright True Type

17. : PHP ? Smarty

633 634 635

18

Smarty PHPUnit PHPUnit sitelogs.db UML settings.php common.php setup.php initialize.php class.LogUtils.php class.PersistableLog.php class.UserLog.php class.LogContainer.php class.UserDemographic.php index.php report.php report.tpl report html.tpl userlog.php 635 637 640 640 641 642 644 644 647 648 648 648 648 649 649 649 651 651 655 657 661 662 664 669 669 670 671 672 672 683 683 683 687 688 688 688 689 689 689 689 690 690 690 690 690

. 1 2 1 2 3

4 5 6 7 8 11 1 2 3 4 5 6 12 1 2 3 15 16 1 2

19691 691 692 694 694 694 694 694 695 696 696 696 696 696 696 697 697 697 697 698 698 698 699 699 699 699 699 699 703 703 703 703 703 704 704 704 704 704 705 705 705 706 706 710 710 711 716

. PHP Web Apache BCMath

20

BZip2 Curl FTP HTTP iconv IMAP Mail Math MIME MS SQL MySQL ODBC PCRE PHP PHP Simple XML SQLite Streams URL XML ZLib 717 717 718 719 720 720 722 722 723 726 728 729 730 730 736 740 741 743 743 744 746 748 749 752 752 753 755 756 757 758 758 760 762 764 770 770 772 773 774 774 775 775 776 776 777 778 779

. SQLite SQLite? SQLite? ( ) SQLite? SQLite PHP

21 SQLite 780 780 780 782 785 786 790 790 791 792 792 793 793 793 795 799 804 804 805 807 807 808 809 811 812 813 813 815 818 819 821 823 824 824 825 826 837

. ODBC ODBC ODBC PHP ODBC ODBC Windows Linux ODBC PHP ODBC SQL Server PHP Windows Microsoft SQL Server DSN ODBC PHP

. CLI PHP PHP CLI shell PHP CLI PHP CLI

. PHP5 php.ini dist fopen

. c . c Dave W. Mercer) . , . , , , , PHP PostgreSQL MySQL.

(Allan Kent) PHP , , Beginning PHP 4. . Cobol, , .

. . (Steven D. Nowicki) The Content Project. , 300 000 PHP . .

c c (David Mercer) PHP , Beginning PHP 4. Beowulf . Wrox PHP, Perl Linux.

(Dan Squier) PHP , Wrox.

(Wankyu Choi) PHP Beginning PHP 4. .

- (Heow Eide Goodman) NYPHP LispNYC, PHP Web , SQL Server, Interbase/Firebird MySQL.

23

- (Edward Lecky Thompson) Ashridge New Media, , . , PHP Apache Linux .

(Clark Morgan) , , Web PHP MySQL Fusion Computing and Media. . PHP, , PHP, (Debra Williams Cauley), (Maryann Steinhart) c. , PHP, Zend Engine , , PHP Web .

"" .

PHP 5 PHP (PHP: Hypertext Preprocessor) , 1994 (Rasmus Lerdorf) , Web . PHP . , PHP , , XML. Zend Engine (, PHP ) PHP . , PHP 5, , Web . , PHP 5. , PHP? , PHP , : PHP? PHP , HTML , Web . . : PHP , . , PHP , Linux , , Windows. HTML : PHP , PHP HTML . : PHP , . Web

Web : PHP Web . , PHP , Web , PHP HTML . Web , PHP , Web HTML . , , Web, Web . , , HTML (HyperText Markup Language ) , Web

25

, , . HTML , Web , , .. HTML , , . Web , . , , , , . . , HTML . PHP, , : , , Web ; , , , ; , , email . , PHP , Web . , Web . , PHP : Web ; Web email ; ; . PHP 5 : , , Web , . PHP 5 Web . , , , Web . Web , , PHP, . , .. CLI (Command Line Interface ), PHP 4, PHP. (CLI .) GTK (Gnome ToolKit).

26

PHP? PHP , Internet (ISP) Web . PHP , , , PHP . , , , PHP Web , Web . , PHP ? PHP Perl , . PHP, Perl, Web . Perl , Web . PHP ASP, ASP , , . : PHP ? PHP , , PHP . PHP 5 , , . PHP , , .

, , PHP 5 , , , , PHP. , , . , , PHP5 , 1, .

, , PHP 5, . , . , PHP 5 MySQL, , , , PHP . PHP

27

, PHP 5 ( , 2006). , . . , , . . . . XML. PHP 5 ( , MySQL SQLite). . PEAR. E mail. . CLI . , , , PHP 5 .

. , . , , , , , . PHP , . , , . , , . , PHP, , . 1 . PHP PHP Linux Windows . , Web (IIS Apache), PHP Web . , , . 2 PHP5 . Internet HTTP, PHP .

28

, PHP Web. : , . 3 , , HTTP , . , , GET POST, cookie .. , HTML , PHP . , HTTP, . 4 : . , , , , if switch, . , . , . 5 . , PHP 5 . , , , . 6 ; . : , ( ), , . 7 PHP . , , PHP . , , . . 8 XML . PHP 5 , XML. XML. 9 11 , PHP ( ), MySQL. MySQL . PHP , , , , , . , . 12 13 : . 12 ,

29

, , , PHP 5. 13 OO , UML (Unified Modeling Language ), . 14 PEAR (PHP Extension and Application Repository PHP ). PEAR . , PEAR . 15 e mail. , PHP5 e mail , MIME (Multipurpose Inter net Mail Extensions Internet) , e mail MIME. 16 , GD Web . , , GD. 17 . . A , . , , , , PHP . SQLite, PHP 5. SQLite . ODBC (Open Database Connectivity ). , SQL. , ODBC Microsoft SQL Server ODBC PHP 5 SQL Server. PHP Web PHP 5. CLI PHP 5 , Perl, BASH DOS. php.ini, PHP 5. ( ), PHP 5.

, PHP , Windows, Linux, Mac OS X . , , , PHP,

30

. ( PHP 5 1.) . , Web . Apache, Unix ( Windows). Apache Linux, Mac OS X. Web www.apache.org. , Apache . Windows Web Microsoft, IIS (Internet Information Server), Windows 2000 XP ( Home). . Windows 98 IIS, PWS (Personal Web Server), . , Apache , , , Windows ME XP Home ( PWS IIS), Apache .

Windows Macintosh , shell, . . , drag and drop , . , . . ? , , . , , . (, 9 MySQL, .) , : Windows ( ) MS-DOS , , , cmd OK; Unix ( , Linux Mac OS X) console, terminal, konsole, xterm, eterm kterm; shell , Unix . , , :

$ % C:/> # bash$

31

, , . , , . :>

(>), . , , :> mysqlshow +-------+ | Databases | +-------+ | mysql | | test | +-------+

. , , , , . , . : ; : ; , URL : persistence.properties; : . , .

, . www.wrox.com ( www.williamspublishing.com).

32

( ) Download Code, . , ISBN ; ISBN 0 7645 5783 1. . , Wrox www.wrox.com/ dynamic/books/download.aspx , Wrox.

Wrox , . . , , . , . , www.wrox.com . Errata. , Wrox. , , www.wrox.com/misc-pages/booklist.shtml. , , www.wrox.com/contact/techsupport.shtml. , .

p2p.wrox.com P2P p2p.wrox.com. Web , Wrox . e mail , Wrox, , , . http://p2p.wrox.com , , . , . 1. p2p.wrox.com "Register Now" (). 2. "Agree" ().

33

3. , , , "Submit" (). 4. , . , ; . . Web . e mail , "Subscribe to this Forum" ( ). Wrox P2P, , ( FAQ P2P ).

, , . , , . , . . , Web . , , , , . , , . . :E-mail: WWW: [email protected] http://www.dialektika.com

:: 115419, , / 783 : 03150, , / 152

1

PHPPHP, HyperText Preprocessor, web , , , . PHP, web . PHP 5, PHP Web, Web , (HyperText Transfer Protocol HTTP). HTTP Web , , PHP. HTTP; 2. PHP Linux Windows . PHP Web , Web (, Apache IIS), ( Linux Windows). PHP , . PHP Web . Web , , , Web . PHP Red Hat Linux Web Apache, PHP Windows 2000 Web IIS.

PHP

35

, PHP, php.ini, , PHP. , .

PHP PHP HTML , HTML, PHP . , HTML, , , , .. HTML Web , ( ) , . HTML ( ), HTML . , HTML , . , Web 90 , , Web HTML , . Web , Web HTML , , . ( ), HTML- HTML . JavaScript Web , Web . JavaScript , Web , . PERL (Practical Extrac tion and Reporting Language ) Web , ; , HTML . PHP ( PHP/FI) 1995 (Rasmus Lerdorf) Perl , , Web . C , 1998 PHP 3.0 ( , (Andi Gutmans) (Zeev Suraski)). , PHP. PHP , Web . Web , ( ), Web , . PHP HTML , Web , .

36

1

PHP . , PHP , . PHP , PHP . PHP HTTP ( ), ( ) Web . , Web , HTTP Web , Web . , 404 Not Found ( ). , , HTTP. 2 HTTP , PHP.

, PHP PHP , Web , PHP. Web , , , Web Web ( HTML 3, , , Web ). , PHP, . , PHP ( ), .

, , : , , Windows 2000 Linux; PHP Web (, Apache Internet Information Server (IIS); PHP 5 ( www.php.net); ( 9 MySQL SQLite); Web (, IE, Mozilla ..); , Notepad, Emacs, vi, BBEdit . , . PHP .

PHP

37

PHP . , , ( Unix , Windows NT/2000), . , , , , Web .

PHP, php.ini PHP : php.ini-dist php.ini-recommended. PHP php.ini, PHP . php.ini , , , PHP dist , recommended , . dist :; PHP. ; PHP ; , ** .

dist , . recommended . , recommended . .

PHP 5 Red Hat Linux Web Apache, Windows 2000 Web IIS. PHP 5 Web , PHP . , . , Windows , Linux ( ) RPM , PHP . , . , , . ( ). , Google PHPTriad Foxserv.

38

1

Web , , , Internet . Web , , Web , , . , Internet . Web , . Web PHP 5. Web , , PHP ; . PHP ; . , ? PHP README INSTALL. , PHP www.php.net/manual/ , , ( 5.0.2 PHP).

? , : PHP Web Apache Linux ( Red Hat Fe dora Linux); PHP 5 Microsoft Internet Information Server Windows ( Windows 2000). PHP 5 Web / , , , Apache Windows. , . , , , PHP . PHP 5.

PHP 5 PHP 5 Web , PHP: CGI , . CGI (Common Gateway Interface ) , PHP 5. , (. PHP CGI ), PHP 5 . ( Linux Windows) PHP SAPI (Server

PHP

39

Application Programming Interface ). Windows PHP SAPI ISAPI . PHP Web , Web , .php, PHP , , PHP . . PHP (www.php.net). Web Web , ( ) PHP, . , , PHP ( ) PHP . . , Web , PHP, PHP . , Internet, Web , PHP. Windows 98, NT, 2000, 2003 XP. Web (Personal Web Server PWS) . PHP PWS, PHP , , , Windows 98. , Windows NT, 2000 2003, Web IIS. PHP . Windows 2000 PHP 5 Web IIS. Web Linux, , Debian RedHat, FreeBSD Unix. Web Apache. PHP Linux Apache, PHP , Web ( ), , , PHP . (, Web , ) , PHP , , Web PHP.

PHP Linux Apache PHP 5, . PHP , .

40

1

Linux, Apache, MySQL PHP PHP Web . LAMP. LAMP , . PHP Apache MySQL, , . PHP 5 SQLite, MySQL. , MySQL . PHP .

, PHP Apache ( , C) . : . , , , . , , , , , RPM (Red Hat Package Manager Red Hat) Linux. . . . , , , . , RPM- Linux, , Red Hat.

() RPM-

RPM- PHP 4 Red Hat, , Fedora, Red Hat : Fedora Enterprise Red Hat Linux Server. Fedora RPM PHP 5, RPM PHP 4, PHP 5 Fedora. , , RPM PHP 5

PHP

41

Linux, RPM PHP 5 RPM . Red Hat Linux , Red Hat, SuSE, Mandrake, Definite, TurboLinux, Caldera Yellow Dog. , , Debian, . RPM-

RPM Linux. , Red Hat 7 SuSE 7 PHP 4 ( ) , , PHP, , . PHP 4 RPM , RPM Web . FTP , RPM . , www.rpmfind.net RPM . RPM , , Linux , . , , RPM , . RPM , , Linux. , RPM ( rpmfind). i386 PC- Intel : Intel 80386, 486, Pentium, Pentium II, Pentium III Celeron; AMD 5x86, K-, Athlon; Cyrix 6x86 PC- Intel : Intel Pentium II, III Celeron; AMD K- Athlon; Cyrix 6x86 Motorola PowerPC ( ), , Power Mac Apple, G3, G4 iMac. RPM Macintosh Linux , 64- Compaq Digital Alpha 64- SPARC, UltraSPARC Sun Microsystems , Motorola 68000, Amiga Apple Macintoshe, Linux

i586

PPC

alpha sparc m68k

42

1

, , , . , . , RPM ; , , . RPM- ?

PHP RPM : zlib libpng libjpeg gd gd devel apache mod_php4 , , , :> rpm -q zlib zlib-1.1.3-6-i386 > rpm -q libng Package libpng is not installed ( libpng )

, , . , ( 1.1.3), ( ), , RPM ( Intel 386, Pentium III). ( , ). Apache 1.3.29, GD; Apache 2.0.48. GD PHP 5 Apache 2.0.17. , , . , , Web , www.rpmfind.net. , . , . RPM ( CD ) root:> rpm -Uh libpng-1.0.5-3-i386.rpm ##################

PHP

43

, , . # . , , , , .

PHP 5 PHP Red Hat Fedora Apache PHP. (, Konqueror), Red Hat Linux. Linux (, KDE) , Red Hat, System Tools Terminal. . 1.1.

. 1.1.

PHP ( ANSI C). Linux, , www.gnu.org

44

1

( ) , gnugcc. . 1.2 Web GNU, . 1.3 GCC. , www.php.net. tar , gzip, . .bz2, gzip, .bz2.

. 1.2.

, Konquerer. . 1.4 tar . , Konquerer , , , , ( , , ). (. 1.5):tar -xvzf php-5.0( ).tar.gz

PHP

45

. 1.3.

. 1.4.

46

1

. 1.5.

PHP 5 cd:cd php-5.0( )

php-5.0.0RC1 . , , INSTALL (. 1.6). PHP (Dynamic Shared Object DSO), Apache. Apache DSO , , , PostGreSQL. PHP 5 , . PHP , , Apache PostGreSQL, , PHP. (DSO) .

PHP

47

. 1.6. Apache DSO-

PHP 5 DSO , , Apache . Apache :httpd -l

, . 1.7. mod_so.c, . .

PHP 5 ( php-5.0.0RC1. ) shell configure. , , PHP.

48

1

, , PHP 5 ( PHP php.ini, ).

. 1.7. ,

, PHP 5 CGI . PHP 5 , -with-apache; DSO -with-apxs. -with_apxs ( -with_apxs2, Apache 2). , PHP 5. ./configure ( ./ , configure) . -enable-track-vars: , GET POST cookie . -with-gd = ///: GD, GIF PNG . PHP GD, (. 16). -with-mysql = ///: MySQL. -with-pgsql = ///: PostGreSQL.

PHP

49

-with-mysql -with-apxs2. , , , , ( ). , , mysql, , mysql .

. , ./configure --help

. (DSO)

INSTALL : -with-mysql -with-apxs. :./configure -with-mysql -with-apxs

Apache 2 --with-apxs2, --with-apxs. , . , , , , make. :make make install

install /user/local/lib php, PEAR ( PHP ) php.ini. . 1.8 , php.

PHP 5 , , enable_track_vars, with-gd with_pgsql. gd ( ) pgsql ( ), , , , , . PHP CGI-

PHP 5 -with-apache -with-apxs2. Apache apxs, PHP CGI . PHP 5 CGI, /usr/local/bin. cgi-bin, :cp /usr/local/bin/php /usr/local/apache/cgi-bin/php.cgi

, Apache, PHP . CERT advisory CA 96.11 (, PHP 5) cgi-bin,

50

1

. 1.8.

, Web . PHP 5 -with-apache (Server Application Programming Interface SAPI), CGI .

Apache PHP Apache, RPM , Apache Linux Linux. , Red Hat Fedora Apache , , Red Hat, System Settings Server Settings Services ( ). httpd (. 1.9). httpd HTTP . , Linux . , httpd HTTP , , , Web . Linux (, KDE), httpd, , . , http://localhost Enter. . 1.10.

PHP

51

. 1.9.

Apache , :lynx http://httpd.apache.org/download.cgi gzip -d httpd-2_0_NN.tar.gz tar xvf httpd-2_0_NN.tar ./configureprefix=PREFIX make make install vi PREFIX/conf/httpd.conf PREFIX/bin/apachectl start

NN , PREFIX Apache ( /usr/local/apache2).

Apache PHP 5 PHP 5 DSO ( ), Apache ( httpd.conf). Fedora /etc/httpd/conf. httpd.conf . , , Apache PHP. , LoadModule, :LoadModule php5_module /usr/local/apache/lib/libphp5.so

, ; , . , libphp5.so, Konqueror, Tools Find file ( ). libphp5.so /usr/lib/httpd/modules

52

1

. 1.10.

, Apache, PHP . Apache httpd.conf PHP 5 LoadModule . LoadModule.LoadModule php5_module /usr/lib/httpd/modules/libphp5.so

, Web , PHP 5, PHP Apache. , AddModule. ClearModulesList, . , , AddModule, .AddModule mod_php5.c

AddModule , ClearModulesList. , Apache, PHP . , AddType. :AddType application/x-httpd-php .php

, , .php, PHP . , , .

PHP Apache

53

, Apache, httpd. , . , http://localhost. ( Windows PHP), , PHP. Web Linux, , Debian RedHat, FreeBSD Unix. Web Apache. PHP Linux Apache, . Web , , , PHP . (, Web , ) , Web PHP, , , PHP .

PHP 5 Windows 2000/Internet Information Server 5 , IIS . , , , . , IIS , , (Start Programs Administrative Tools Services) (World Wide Web Publishing). , . IIS, (Settings Control Panel) (Add/Remove Programs). , Windows 2000 , Internet Information Server. IIS (Details), ( FTP, SMTP ..). , , . IIS . IIS, ; URL http://localhost/iisHelp. . 1.11, IIS Windows 2000. IIS, IIS (Internet Service Manager). Internet Services Manager. Microsoft (Microsoft Management Console MMC) IIS (. 1.12). MMC , IIS, Web FTP . . 1.13 IIS.

54

1

. 1.11.

. 1.12.

PHP

55

. 1.13.

PHP, IIS, . - (Default Web site) . PHP , Web , IIS.

PHP 5 PHP 5 www.php.net Downloads, . 1.14 ( ). Windows ( zip ), (, C:\PHP5RC01) , . PHP5RC01 , . 1.15 ( Windows). , PHP 5 , PHP 5 , . Windows C:, D:. , , , C: ( , Windows), PHP .

56

1

. 1.14.

. 1.15.

PHP

57

PHP ( PHP5RC01) , php.exe, , php5ts.dll ( dev). dll D:\WINNT\System32 ( D: ). , dll . Windows , , , . dll System32 PHP SAPI ( ), PATH. PATH (), Windows , , dll . , , dll PHP C:\php5\dlls, C:\php5\dlls, . PATH, , (Control Panel System Advanced Environment Variables), PATH).

php.ini , php.ini , PHP, PHP . PHP. PHP. PHP php.ini-dist php.ini-recommended. php.ini-dist D:\WINNT ( ), php.ini, Notepad. :extension_dir = C:\php\extensions ; directory in which the loadable extensions (modules) reside

, PHP 5. , ( ext PHP). , php_ .dll. php.ini , PHP. , , , , PHP . extension=php_gd.dll, :;extension=php-filepro.dll extension=php-gd.dll ;extension=php_mssql.dll

GD, PHP ( 16, ). php.ini .

58

1

IIS Internet Services Manager . , (Default Web Site), (Properties) (. 1.16).

. 1.16.

. , ISAPI PHP 5, PHP SAPI , CGI . ISAPI (ISAPI Filters). (Add) , PHP. sapi PHP php5isapi.dll ISAPI PHP. , (. 1.17). , , IIS PHP5 . IIS , .php, PHP . (Home Directory) (Configuration). . (. 1.18). (Browse) php5isapi.dll. (Extension) .php, , IIS .php . OK. IIS. , - (Start).

PHP

59

. 1.17.

. 1.18.

60

1

MMC , Web , PHP 5 . Web ( C:\Inetpub\wwwroot). wwwroot . (, ). .php. , PHP . , :

test01.php ( , .php) wwwroot. , http://localhost , , , : http://localhost/php_file/myfile.php). , . 1.19 ( PHP , PHP). , . , .

. 1.19.

PHP

61

PHP . PHP . PHP , , :

wwwroot ( , Windows 2000/IIS, /Web ). . : , !. (Page cannot be displayed), PHP, , Web . Web (parse error), , , . , PHP. ? , ? . , , , . , , PHP . , , , , . , . , ( ), . ( 5 .) PHP : 1. , . Win dows 2000 , ( (Start Programs Administrative Tools Services)), Internet . , , , . , . , ( IIS), Web . Apache Linux httpd ( http://localhost ). 2. HTML wwwroot, , .htm .html (, test01.htm), . , URL

62

1http://localhost/test01.htm, (, D:\inetpub\ wwwroot\test01.htm). 3. HTML , , Web . (, PHP ), PHP. ( 404 (404 Page Not Found)), , , , Web .. 4. PHP, , , PHP . , Windows Linux. 5. . Linux Windows 2000 Windows. root Linux Windows Web . Linux FTP . .

PHP , PHP , php.ini. PHP5 php.ini, PHP . PHP .

php.ini php.ini PHP, PHP ( , Web ). , , ; . php.ini-recommended. , , PHP ( ), .;;;;;;;;;;;;;;;;;;;;;;;; ; ; ;;;;;;;;;;;;;;;;;;;;;;;; max_execution_time = 30 ; max_input_time = 60 ; memory_limit = 8M ; ; . ; ; , (8MB)

PHP; EGPCS- ; . , "" ; . , ; track_vars ; GPC- $_*_VARS[]. ; , ; register_globals. ; , , , ; , ; . register_globals = Off

63

, php.ini, .

PHP-PHP , PHP PHP . . .

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

HTTP 1.1, HTTP 1.0, , ( HTTP 2).

PHP PHP Web . PHP Windows Linux CGI , PHP , PHP , . , , , , PHP .

64

1

PHP . , , : , PHP? , , .., . ? , . Web ? , . , Web , , , PHP , , . PHP ? , , , , , PHP. ( ) PHP? . ? , , .

2 2

, , PHP , , PHP 5. , , Web HTML XHTML ( PC , , Internet Explorer). PHP , . PHP , , PHP HTML XHTML , PHP ( echo, date(), strlen() ..), . , PHP 5 Web , PHP . , , . , , , , . , PHP , PHP .

66

2

PHP- Web , . . 1. HTML : Web-

2. .htm (, simple01.htm). 3. . . 2.1.

. 2.1.

4. , 1, ( Web , ,

67

Web ). , HTTP . . 5. , ..., : , PHP 5:

6. , , , . , , .htm .php. , Web PHP , , () , PHP , . (, ), PHP PHP PHP (), PHP . , PHP ( PHP ). PHP . 7. .php . .

PHP, , , , , . PHP , , , . Web , HTML Web , . HTML ( , HTML, 3). echo, , , .. , ( , ), , , , . echo PHP; unset. , echo ; . , echo . HTML , , (

68

2

HTML , ). echo , $todaysdate:echo $todaysdate;

date() PHP, .. PHP ; . , , . , , , date() . :$todaysdate = date("m",time()) . "-" . date("d",time()) . "-" . date("Y",time());

"m" date() , . time(), . date() , . date() , , time().

PHP- , PHP Web : Web , ; .php; PHP ; PHP . .

Web- ( ) , Web , , PHP 5, , PHP . , , HTML , HTML XHTML, , , XML XSLT. , , Web , HTML, , . PHP , PHP HTML , HTML PHP . , , HTML . ? .php Web , ( ). PHP (

69

PHP , ), , HTML-, PHP . , Web , PHP , .

Web , , .htm .html, , , .shtml. . Web , .php , PHP . .php PHP 5, PHP Web . Web , PHP (, .htm .html). HTML PHP ( PHP ), HTML ( ). , , .htm .html .php, , PHP. , , PHP Web .

PHP- , .. , . , . , , , . PHP , Web . PHP 5 . , PHP (PHP Extension and Application Repository PEAR), PHP 14. PHP 5, , PHP , . , PHP 5 . ASP , , ASP , Web . (ASP Active Server Pages ( ) Microsoft, PHP.) , PHP HTML , : PHP-

70

2

PHP- , PHP . PHP Web PHP , , . , , PHP . ( ) , . ( 5.) , PHP . PHP . , (;):$todaysdate = date("m",time()) . "-" . date("d",time()) . "-" . date("Y",time()); echo $todaysdate;

PHP : (;); ({}); // ( ) /* */ ( ). , ( , PHP ):

, PHP . , , Visual Basic ASP, , ( //).

PHP- Web- , , .exe , PHP , Web . Web , , PHP PHP .

PHP Web . PHP , , PHP . 1.

71

: PHP ( ), , PHP , . PHP , include require ( , ), , . , , HTTP . ( ), . , , , , , . , . , , FTP e mail , . , , Web , FTP . PHP, PHP , HTML / JavaScript Web . PHP , , PHP . , , PHP , , JavaScript, .

Web-: Internet- HTTPInternet Internet . , Internet, . FTP (File Transfer Protocol ), Web HTTP (HyperText Transfer Protocol ). Internet , Web . Web , , , , .

72

2

TCP/IPInternet Internet . Internet , IP ( , , , 64.71.134.49). ( ), , TCP/IP (Transmission Control Protocol/Internet Protocol /Internet ). TCP/IP ( ), T1 , . TCP/IP , , . , , TCP, ( ). TCP , . , ( , ). , ( IP ). , ( HTTP), , TCP/IP , . HTTP , World Wide Web URL http://, , HTTP. TCP/IP , , HTTP (), , . , Web , HTTP . ( Web ), Web . , HTML ( TCP) , ( HTTP) . Web , , ( Error 404: Page Not Found ( 404: )), . , Web , HTTP .

HTTP- HTTP . Web URL . . . , HTTP , ,

73

, . , HTTP , PHP . ( ) HTTP , : /, HTTP HTTP . , .

HTTP- HTTP , Web , , . .GET /testpage.htm HTTP/1.1 Accept: */* Accept-Language: en-us Connection: Keep-Alive Host: www.wrox.com Referer: http://webdev.wrox.co.uk/books/SampleList.php?bookcode=3730 User-Agent: Mozilla (X11; I; Linux 2.0.32 i586)

HTTP (request line), : HTTP , (, GET POST); ; HTTP (, HTTP 1.1). :GET /testpage.htm HTTP/1.1

, , . . GET , URL-. Internet GET- ( , GET-). , , HTML- PHP-, JavaScript Perl- .. URL- , GET-, HEAD- HTTP- , HTTP- (, ). Web-

HEAD POST

HTTP , PUT, DELETE, TRACE, CONNECT OPTIONS. , , . RFC 2068, www.rfc.net.

74

2

HTTP-

HTTP . , , , , . HTTP , : : , ; : ; : . :Accept: */* Accept-Language: en-us Connection: Keep-Alive Host: www.wrox.com Referer: http://webdev.wrox.co.uk/books/SampleList.php?bookcode=3730 User-Agent: Mozilla (X11; I; Linux 2.0.32 i586)

, HTTP , HTTP , . HTTP , HTTP . . HTTP-

HTTP POST, HTTP , , , , HTML ( ). HTTP , .

HTTP- HTTP , . .HTTP/1.1 200 OK Date: Fri, 31st Oct 2003, 18:14:33 GMT Server: Apache/1.3.12 (Unix) (SUSE/Linux) PHP/4.0.2 Last-modified: Fri, 29th Oct 2003, 14:09:03 GMT // // // // // ( )

: HTTP; HTTP , . , HTTP/1.1 200 OK

HTTP 200, OK, ,

75

. HTTP 404 ( ), , Web . , . , . 100199 200299 300399 400499 500599 ; , , Web- , , (.. , ) ( , )

HTTP . HTTP : : , ; : , ; : , . , , . ; .Date: Fri, 31st Oct 2003, 18:14:33 GMT // Server: Apache/1.3.12 (Unix) (SUSE/Linux) PHP/4.0.2 // Last-modified: Fri, 29th Oct 2003, 14:09:03 GMT // // ( )

. , Server, Web . , Web , . , . RFC 2068 ( 4.5, 7.1 7.2).

, HTTP HTML ( , ), . , .

76

2

PHP- HTTP- ( ), HTTP Web , PHP . , (.. Web ). Web HTTP , , PHP , , PHP .

Web- Web PHP, , HTTP , PHP , , PHP .

PHP- PHP, , , ( Zend Engine 2.0), Web . PHP Web . PHP , Zend Engine ( ) , ( Zend , ). , PHP PHP . , , .

PHP . . . . PHP , ($). PHP , PHP . PHP , , PHP (loosely typed language) ( ). . $todaysdate .$todaysdate = date("m",time()) . "-" . date("d",time()) . "-" . date("Y",time());

77

, , : ; ; . .

. , . : . , , . , PHP , : ($); ; , . ($Variable $variable ), 30 . . , , . 6, . PHP :$my_first_variable = 0;

0? PHP , . 0. , , . , (). PHP , . ; , , . , .

78

2

. ? . , , , , , , .. , , . , (string), 1995, , , 1995 5 , 2000. (, PHP ; ). , , 19955, .. , .

, . PHP , , . (strongly typed language) , , , (.. , ). (loosely typed) , , . PHP , , . , , , , . PHP

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

79

Boolean () Integer () String () Array () Object () Resource () NULL ()

; True False ; ; ; ( ) ; , ; , , ; NULL, ,

Float () ; ,

, , , . , - . , , . , ; , . , , , . , ( PHP). PHP

. , , , , , . PHP (casting) ( ) . PHP gettype() , settype() . , , , . , , , :$my_var = 1995; //$my-var echo " ". gettype($my_var) . "
"; $my_var = settype($my_var, "string"); //$my_var echo " " . gettype($my_var);

PHP gettype() , (, string, integer ..). PHP , , , is_string, is_int . , , , gettype() (, integer), ( integer).

80

2

, , , . , . (scope) . , ( ) . , PHP , ( 6) , .. . :$my_data = " "; function send_data() { $my_data = " "; echo $my_data; } send_data(); // echo $my_data; //

. ( ) . $my_data , , , $my_data $my_data , , . $my_data . , , $my_data , .

global . global, , ( 6 global ):$my_data = " "; function send_data() { global $my_data; echo $my_data; } send_data(); // echo $my_data; //

(.. ) static, . , , . ,

81

, 100 . , , . ( ):function get_record() { static $counter = 0; $counter++; // $counter < 100 // , , // // $counter = > 100, echo " " }

$counter .

PHP (constants). , , ( define()) PHP , . , , , . , , , ( ). , , . , define(), , . :define("my_constant", "1995"); // my-constant "1995" echo my_constant; // "1995" // ( , , )

PHP, , . , PHP, , , .

PHP- PHP :$my_data = "Hello";

. . , .

82

2

; , , , . . , , ; , ++ () . , , , . , , ; $my_data = "Hello" . , . . , PHP ?, if. , , , (, ? 01 : 02, , 01, 02). , .

PHP- , . , (, $a = $b + $c, $b + $c ). , $a = 5 , 5. , $a = $b + $c $b $c, $a. . , PHP () . , , ( , ). , . , (*) , (+), 2 + 2 * 12 26 ( 2 * 12 , 2), (2 + 2) * 12 48 ( , , 12).

83

PHP :

, / ( true false) ( PHP 5 ) , shell- , , , ( 4) () (, )

www.php.net ( ). .

: (.). PHP , . .

(.) . PHP :

, $whole_name $first_name $last_name " " ( ). , . :$whole_name = $first_name." ".$last_name;

84

2

Web , HTML ( , ):echo " = $whole_name";

HTML , , HTML , . $whole_name . , PHP , , . , ( ):echo "First name plus last name = \$whole_name";

strlen()

strlen() . . $string_length:$string_length = strlen($whole_name);

, (, ) (, , $string_length) , . , , , . strstr()

strstr() , , . $whole_name ( ) strstr() , . . , FALSE.$part_after_space = strstr($whole_name, " "); echo " - " . $part_after_space . "";

strpos()

strpos() , , . , , ( ). $whole_name ( ) 2. , 3, , , , PHP , 0, 1, 2.

$letter_position = strpos($whole_name, "o"); echo " "": " . $letter_position . "";

85

PHP , ( PHP), (0,1,2,3,4 ..). ( ). chr()

chr() ASCII . ASCII Internet, , . , ASCII 10, 13. , , (chr(10) chr(13)) .

PHP , . . , (.) PHP . . 1. working_ with_strings.php. , Web ( Web ) Web ( ). 2. ( PHP ): PHP5 -

86

2 - strlen() - strstr() strpos() ASCII- chr()

3. , , . . 2.2.

87

. 2.2.

Web . HTML HTML . Web , PHP , HTML , . ( ) (.):

strlen() . , $whole_name. strstr() , . $whole_name (" ") , , .

88

2

strpos() , . $whole_name 2. (, 0, 2.) chr() , ASCII , . ASCII 224.

PHP PHP (, ..) , , . , $c = $a + $b $a $b, $c. ( = == ===, 4.) , , ; , . :

, , , , echo 202, 120.

. , . ( +=, = .) ; . , :$first_number += $second_number;

:$first_number = $first_number + $second_number;

. , (.=), , . :$a = " "; $b = " ."; $a .= $b // $a " ."

89

, . Web PHP.

. : . , :$a $a $b $b = = = = ++$a; $a++; $b; $b; // $a, // $a, $a // $b, // $b, $b .

. , , , ( ) , ; , , , . , () . , B C. () . PHP-

PHP . , , . , floor() . . , ? , . , 100.0, :$a = 100.01; $floor_a = floor($a);

, pi() rand(), . pi() 14 ( 14 , precision php.ini). rand () 1 RAND_MAX ( , ), , , .

. , , PHP . PHP HTML , Web .

90

21. HTML . ( , working_with_numbers.php Web ). PHP5

(++) (* /)

91

+= *= abs() bindec() ceil() floor()

92

2 max() min() pi() rand() sqrt()

2. working_with_numbers.php, . . 2.3.

93

. 2.3.

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

, $a $b.

94$a $a $b $b = = = =

2++$a; $a++; --$b; $b--; // $a, // $a, $a // $b, // $b, $b

pi() rand() , PHP . (, , ).

array (array ), , . , , (keys) () (values), (element) . . , /. , , : . , , , ( ). , , , . , , .

( ) array() , . ( ). , . , . (0). , $my_array , , 0, 1, 2 3:$my_array = array ("", "", "", " ");

$my_array array(). is_array(), ( true), , $my_var . , :

$zero_element = $my_array[0]; $one_element = $my_array[1]; $two_element = $my_array[2]; $three_element = $my_array[3];

95

( ) . , , . , , , :$my_named_array = array("dog" => "", "cat" => "", "hamster" => ""); $my_dog = $my_named_array["dog"]; $my_cat = $my_named_array["cat"]; $my_hamster = $my_named_array["hamster"]; echo " $my_dog, - $my_cat, $my_hamster";

, , . . , , , , , . , PHP , , :$my_named_array = array("dog" => "", "cat" => "", "hamster" => ""); $my_dog = $my_named_array[0]; $my_cat = $my_named_array[1]; $my_hamster = $my_named_array[2]; echo " $my_dog, - $my_cat, $my_hamster";

(.. ) . , array() ([]). PHP , , , . .$my_array[] = " ";

, :$my_array["first"] = " ";

$my_array["first"] , PHP , . $my_array[], PHP

96

2

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

( , ) , , , , . print_r(), . , HTML , PHP :

. 2.4.

. 2.4.

print_r , . ( 4 , .)

97

PHP, , ; PHP , . . ( 3 4.) , . , , . count() ( ):$number_of_elements = count($my_array);

array_count_values() ( ) , . $returned_array $argument_array, $returned_array , , $argument_array. , :$argument_array = array("dog", "dog", "cat", "cat", "hamster"); $returned_array = array_count_values($argument_array); print_r($returned_array);

:Array ( [dog] => 2 [cat] => 2 [hamster] => 1 )

array_flip() , . , , SSN (Social Security number ), , SSN ( SSN , ). :$my_people_array = array("John" => "555-66-7777", John => "444-55-3333"); $my_ssn_array = array_flip($my_people_array);

$my_ssn_array , John .

sort() asort() (, ). sort(). , asort(). sort() , asort() . :$my_unsorted_array = array("Jim", "Bob", "Mary"); $my_sorted_array = sort($my_unsorted_array); $my_sorted_array_with_unchanged_indexes = asort($my_unsorted_array);

98

2

PHP , PHP HTML ( ), Web , PHP ( , , ..). , PHP Zend Engine, Web , . PHP , , . , PHP , . PHP , , PHP , . PHP , ; , . , PHP . 3 , PHP . , HTTP HTML .

1. PHP , , . : A. ; . . 2. PHP , ( ) . : A. 2, 4, 6, 8, 10; . 3, 5, 7, 9, 11.

3 3

PHP, HTML , HTTP, PHP , PHP , . Web . 1994 Web , . Web ; ( DHTML ), , . HTML Web . HTML ( ) Internet . HTML HTTP , PHP . Web ( GET POST), , ( , ), Internet. , HTTP . , PHP .

HTML, HTML, , . PHP PHP Hypertext Preprocessor.

100

3

, PHP HTML (Hypertext Markup Language ). HTML, HTML PHP . HTML (Tim Berners Lee) (Robert Caillau) 1989 . HTML (Standard Generalized Markup Language SGML), 1986 ISO 8879:1986. SGML . HTML SGML , , XML SGML , ( XML 8). SGML , HTML (Document Type Definition DTD), . HTML DTD. W3C (World Wide Web Consortium) www.w3.org. HTML ( XHTML). HTML 4.01. HTML , . HTML ( ) . HTML ( HTML) Web , . , , , , , . HTML , . HTML ( ):

, HTML (, ), HTML , HTML , (, ). HTML XHTML, XML , . XHTML , HTML . , HTML , XHTML. HTML HTML , ( ) () () . HTML

PHP, HTML

101

(). HTML , . , html. HTML . . , , . HTML , , IMG. IMG ( Web ) Web . , , , . HTML . (, SRC) . SRC , URL (, ). , HTML Web , , URL , , Web .

HTML DTD DTD , HTML , . HTML HTML , HTML DTD , , . , HTML DTD IMG, Web . , HTML DTD, . HTML , Web ( ) . , HTML , DTD , . DOCTYPE DTD, . DOCTYPE , Dreamweaver ( Web ):

form input HTML , PHP , . , HTML DTD:

--

DTD , (ATTLIST). action, , , method, , . HTML , , .. DTD .

type , (text , radio ..). Web , HTML Web ( ). Web . :
:

PHP, HTML

103

( ) . www.example.com. HTML PHP Web ( Web )? , HTML Web HTML . PHP , . Web , PHP PHP , , PHP Web , PHP . , , ( , ). . PHP HTML , PHP Web , ( , PHP ) . , .

PHP- HTTP-, , HTTP , ( ) Web ( ) PHP . HTML , Web (, , PHP ). , HTTP, HTML PHP . PHP , , , , . , , Web . Web . PHP , , PHP . , Web PHP , , $_POST ( , , ), $_SERVER, . PHP , . PHP . ( , ). , .

104

3

PHP ( ), . , , . PHP , ( php.ini register_globals=Off). , . , username ( , POST), :$my_new_username = $_POST[username];

, . , HTTP , , , .. , , , PHP, Web , HTTP. , , . , PHP PHP phpinfo(). PHP (. 1), , PHP . , PHP, , , . , phpinfo(), test01.php, 1. , PHP ( 1), , phpinfo(). ( HTML ), PHP, , Zend Engine, php.ini, . , phpinfo(), . 3.1.

HTTP- Web . , IP ( , ). IP , , cookie , , Web . , , , . .

PHP, HTML

105

. 3.1.

PHP (php.ini) register_globals. off ( PHP 4.2) . , (, : $_SERVER['DOCUMENT_ROOT']). (import_request_variables()), GET, POST Cookie , , , .

$GLOBALS $GLOBALS. HTML .

106

3

( displaying_predefined_ vars.php), $GLOBALS. , . , , . Web . , Web .

print_r() . , . HTML , , .

. , PHP , global . $GLOBALS , PHP-. $GLOBALS , HTTP, , , , HTTP, IP- .. Web- , , , URL GET . $_POST $_REQUEST PHP-. , ( ), HTML-, PHP- $_REQUEST cookie-, . , . cookie setcookie(). Cookie ( , cookie-) , POST. $_POST , (, ), HTML-

$_SERVER

$_GET $_POST

$_COOKIE

$_FILES

PHP, HTML

107

$_ENV

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

$_REQUEST $_GET, $_POST $COOKIE $_SESSION

, . , ; , ( HTML ). , displaying_predefined_vars.php. - $GLOBALS - $_SERVER $_GET

108

3

$_POST Cookie - $_COOKIE - $_FILES - $_ENV - $_REQUEST - $_SESSION

PHP, HTML . 3.2.

109

. 3.2.

, Web , , HTML. HTML ( , , ) href, URL . , , , , URL, href, . .

Web .

110

3

, , , Web . , , , , URL .

(query string), URL . /. . , PHP , , . , , John , PHP , , $first_name. / . / , , HTML- XML- .. , PHP , , URL (, $first_name $last_name ): = ? @ \

URL- %2E %2F %3A %3B %3C %3E %3D %3F %40 %5C

, ( , , ). URL :http://localhost/beginning_php5/ch03/form.php?TextArea=I%20would%20like%20to%20 see%20a%20dynamic%20menu%20in%20operation

GET , POST. POST

. URL , GET POST. GET; , URL, HTTP . , , URL. POST . , URL. : GET POST?

. , GET , . , GET , POST , Web . , . POST , , , , , GET, URL . (, Alta Vista),

116

3

GET. GET. POST , , , HTTP , , , . , . , , , . GET, . , POST, , , , , .

PHP ( ) HTML- HTML , , , PHP . (form field), (control) (form element) ; . Web . , Web PHP . , , . PHP , . PHP . Web , , HTML .htm .html. ( , , ). , PHP , PHP , ( , Web , , ). , HTML .

( ) (text fields), (text boxes), , . , type text.

, . , , , . Web , .

PHP, HTML

117

1. HTML : ?

2. text.html. 3. : :

4. text.php. 5. text.html (. 3.3).

. 3.3.

6. (. 3.4).

118

3

. 3.4.

URL . 3.4. URL text.php . Web text.html: ? ...

method GET , HTTP . . 3.4:?Author=Juan+Rulfo

, /. Juan Rulfo. (Author) text.html: ?

name Author. , . , text.php, PHP : :

PHP $_GET["Author"]. . $_GET. HTML Author.

PHP, HTML

119

Web PHP , PHP $_GET Author. Name, $_GET['Name']. , .

, (. . 3.5) , , , PHP .

. 3.5.

, text.html (author ):

text.php $_GET['Author'] ( ):echo $_GET['Author'];

, PHP . HTML , PHP , HTML , PHP $_GET['author'], $_GET['Author']. , HTML , PHP , .

, , HTML : . , , . ,

(text area) WebSites 30 50 . , . ,

120

3

, , . , , . .

1. Web : Web- http:// http:// http:// http://


2. textarea.html . 3. : Web-:

4. textarea.php. 5. textarea.html (. 3.6) URL Web . 6. ( ) . . 3.7 .

, . , URL:http://localgost/beginning_php5/ch03/textarea.php

PHP, HTML

121

. 3.6.

. 3.7.

, POST. Web- ...

122

3

, . : http:// http:// http:// http://

50 . HTML (
); . WebSites. (textarea.php) PHP $WebSites ( ):... Web-: ...

, , HTML , , .

(check box) , , , HTML . , , . , . HTML ; type:

, , /. checked, . , :

, value; on. input , . , .

1. Web :

PHP, HTML - ?

123

2. checkbox.html . 3. :

4. checkbox.php . 5. checkbox.html , . 3.8.

. 3.8.

6. . on (. 3.9). 7. , . , .

124

3

. 3.9.

URL , Web POST. , checkbox.html:

: - ?

checkbox.php PHP , , checkbox.html:

, . , on. .

, ? , (radio buttons), , . , .

PHP, HTML , .

125

1. Web checkboxes.html: - ?
- ?
- ?

2. . :

3. checkboxes.php. 4. checkboxes.html (. 3.10).

. 3.10.

126

3

5. . (. 3.11).

. 3.11.

value : - ?
- ?
- ?

. , Choice1, ( on), $Choice1 checkboxes.php. , PHP . checkboxes.php , checkboxes.html:echo "$_POST[Choice1]
"; echo "$_POST[Choice2]
"; echo "$_POST[Choice3]
";

, . , . , checkboxes.html: - ?

PHP, HTML

127


- ?
- ?

, , , . , . PHP , . . HTML : - ?
- ?
- ?

$_POST. , PHP , . ([0]), ([1]), ([2]). PHP , , , , $_POST[Choice][0]. $_POST[Choice][0] , . $_POST[Choice][1] , , .. , . HTML , , , , 2, PHP .

(radio buttons) . , , . , type radio.

, , HTML checked, . , Web :

128

3

value , "on". , , . :

Web , . , , .

1. Web :





2. radio.html . 3. :

4. radio.php. 5. radio.html (. 3.12). 6. (. 3.13).

PHP, HTML

129

. 3.12.

. 3.13.

GET, . , . , , , , . . , radio.html,

130

3

. , Question1, , :

radio.php , :

(list boxes) (drop down list boxes) , . , . HTML , , : . , , , , . , , , , : $5000 $5000-$10000 $10,000-$25,000 $25,000

, . , multiple. , . , , , .

1. HTML :

PHP, HTML $5000 $5000-$10000 $10,000-$25,000 $25,000

?

1.0L 1.4L 1.6L 2.0L

131

2. listbox.html . 3. :

4. listbox.php. 5. listbox.html (. 3.14). 6. . . 3.15.

listbox.html , . name Price: $5000 $5000-$10000 $10,000-$25,000 $25,000

132

3

. 3.14.

. 3.15.

PHP, HTML

133

listbox.php name PHP $_POST[Price]: name='Hidden1' value='$Message1'>"; name='Hidden2' value='$Message2'>"; name='Hidden3' value='$Message3'>"; value=''>";

135

2. hidden.php . 3. :

4. hidden2.php . 5. hidden.php (. 3.16).

. 3.16.

136

3

6. , (. 3.17).

. 3.17.

HTML echo . HTML , . :$Message1=" "; $Message2=" "; $Message3=" ";

echo . HTML , , , , , echo . , hidden2.php GET:echo "";

, :echo " ?"; echo "";

, $Message1, $Message2 $Message3 .

PHP, HTML echo "$Message1"; echo "$Message2"; echo "$Message3";

137

:echo "

";

:echo ""; echo ""; echo "";

$Hidden1, $Hidden2 $Hidden3 . , :echo ""; echo "";

PHP , . :echo echo echo echo " :
"; "$_GET[Hidden1]
"; "$_GET[Hidden2]
"; "$_GET[Hidden3]
";

, . PHP . PHP . . .echo "
:
"; echo "$_GET[ListBox]";

.

, , , . , :

, . , (text.html) type password. , , , GET, . , POST . , POST . , , , SSL (Secure Sockets Layer ) .

138

3

submit reset submit () , . . , , ? name value . :

, , PHP . PHP , . Submit1, $_GET $_POST Submit1. , Submit2. Submit1 1, Submit2 2. , . , submit . , submit. , reset, .

PHP- , PHP, , Web . , , , . , , . , , . , NAMLLU . . , ( ). : : , 5; : , 10; , ; : , .

PHP, HTML

139

20 , , . 19 , First figure :First figure * (19/10 - (19 Modulus 10)/10)-1

Modulus . :First figure * (1.9 - 0.9) -1

:First figure * 0

20 : , . : 57 50 000 . 50000/5 = 10000. (57/10 - (57 Modulus 10)/10)) - 1 = 4. 10000* 4 = 40000 ( , ). , , , .

( ). , , , , , . . 1. HTML : Namllu Credit Bank : : :

:

$10000 $10000 - $25000 $25000 - $50000

140

3 $50000



$1000 8,0%
$5000 11,5%
$10000 15,0%

2. loan.html . 3. : Namllu Credit Bank

4. loan.php. 5. loan.html (. 3.18) . 6. , , . 3.19.

, . (loan.html) . , , : : :

PHP, HTML

141

. 3.18.

. 3.19.

142

3

, PHP $_POST[FirstName], $_POST[LastName] $_POST[Age] . :

PHP $_POST[Address]. PHP , , , . , : $10000 $10000 - $25000 $25000 - $50000 $50000

. . PHP $_POST[Salary], , , . , . , , , 10 000 , . :

$1000 8,0%
$5000 11,5%
$10000 15,0%

, . , , PHP , $Loan. submit reset:

submit action, , , :

, , , loan.php, , . $SalaryAllowance, , 5:$SalaryAllowance = $_POST['Salary']/5;

, , 10

PHP, HTML

143

. ( ) 10 . Modulus (%). , . 0, 0 19 ; 1, 20 29 ; 2, 30 39 , .. $AgeAllowance:$AgeAllowance = ($_POST['Age']/10 - ($_POST['Age']%10)/10)-1;

. $LoanAllowance, , .$LoanAllowance = $SalaryAllowance * $AgeAllowance;

Web :echo " :$_POST[Loan]
"; echo " :$LoanAllowance

";

), , HTML :

156

3

. 3.21.

HTML , $_GET['whichpage'] ( ). , , :if (isset($_GET['whichpage'])) { echo " $_GET[whichpage].

\n"; $_SESSION["view".$_GET['whichpage']."count"]++; }

for . ,

PHP, HTML

157

, . :for ($i = 1; $i

: (sessions.php), ( session_id()) , ( , $_GET ['whichpage']). . . .

, PHP , Web ( ). , $_SERVER, $_REQUEST. PHP : ( ) HTML ( , ). , GET POST, , . , , HTTP : , , cookie , .

PHP isset(), PHP , . , , , submit login logout. isset() , :if (isset($login)) { // - } elseif (isset($logout)) { // - }

158

3

Web , , PHP , isset(). , ( ), . ( , : XX, YY). : , , , , $PHP_SELF.

4 4

, PHP, , , . , , . , , , , , , . , , (control flow structures) (branching structures). , . , , , if, . , . , , PHP , break , .

PHP- , . , ( ). ( ,

160

4

, , , ) , , PHP . ( 5).

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

? . , : , , . , , , , , . ( , PHP5):// , // , // // // , // , // , HTML- // , // . HTML-,

, // // , // // , HTML- // // HTML- .

161

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

, , , ( , ). (George Boole), .

, , . , and () , A B. , (or) (not). , , . xor ( ) . , "" "" (|| &&), ( 2 ). , , or , xor, not and . ( ). , , . , if..then else..end if if , , ( (true) (false) ). , , if. , else, , .

, PHP TRUE FALSE. ,

162

4

. FALSE: (0); (0.0); (""); ("0"); ; ; NULL ( ). TRUE. , , . , A 20, B 30, A < B (A B), TRUE. : . . , . , : true false. :$Variable = true;

, :1

, , . , , (, , 1 0), , .

, . ( : , , ), . and, or xor. PHP !. , , , and, , . , and, . , , . if..then..else/elseif..end if. ( , then end if PHP ; if

,

163

.) ( AND OR , , ):$my_var = 27; $my_var02 = 30; if ($my_var == $my_var02) { // } elseif ($my_var + 3 == $my_var02) { // } elseif ($my_var + 3 == $my_var02 AND $my_var == $my_var02) { // } elseif ($my_var == $my_var02 OR $my_var == $my_var02-3) { // } elseif ($my_var == $my_var02 AND !$my_var == $my_var02-3) { // }

. $my_var == $my_var02 , . $my_var + 3, $my_var02 , . , , , . , ,

$my_var + 3 == $my_var02

$my_var + 3 == $my_var02 AND $my_var == $my_var02 $my_var == $my_var02 OR $my_var == $my_var02 - 3

$my_var == $my_var02 3 , AND !($my_var == $my_var02) , . . , , , ! true

, , . , , , . , , ( , ). , , . , , :if ($submitted_value !== $my_internal_value) { // }

( , )

164

4

, . , .

, , . , . . , . 1, 1; 2, 2; 3 3, ..

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

,

165

(, ). (, ) (, ), ( ). PHP. PHP , , PHP . , , , PHP . , , ( , if). , PHP (, $fridge $bread_bin, ):if ($fridge == ", ") { if ($bread_bin == "") { make_sandwich(); } else { go_to_store(); make_sandwich(); } } else { go_to_store(); make_sandwich(); }

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

if if 2, , . , : ( ) { ; }

if ( ), . , PHP . : ( ) { ; } ;

, , .

166

4

, : ( ){ ; }

, : ( ){ ; ; } ;

, , .

, if..then..else switch..case. , ( ). , , . , , . ( ), .. 3 , . , , . , .

> < . PHP , . . :if (5 < 6) { echo " "; }

. if , . : . , , . (true). if , . , , . , , , :If ($lucky_number < 6) { echo " "; }

, :

167

If ($lucky_number < $lottery_number) { echo " "; }

, , :If ($lucky_number < $lottery_number){ echo " "; $lucky_number = $lucky_number + 1; }

, PHP 1 10, . PHP , , rand(). .

1. HTML : 1 10

2. guessgame.php . . . 4.1 .

168

4

. 4.1.

, , . , . , :$number = rand(1,10);

rand() , , . $number. , , name guess. 1 10

, guess ; $_POST[posted], isset(), , ( if). , , , . , $_POST[guess], , PHP . , $number, :if ($_POST['guess'] > $number) { echo " ";

, echo "
: $number, , ";

169

, , . else if. , , else if . if , . , :} else if ($_POST['guess'] < $number) { echo " "; echo "
: $number, , ";

, , . PHP . , , else. , .} else { echo "
: $number, !"; } } ?>

isset() , , .

== === , PHP . ; . . :$lucky_number = 5; $lucky_number = 7;

$lucky_number 5, ( 5) (7). , . :if ($lucky_number == 7) echo (" : 7");

, , Visual Basic, (=) . , , PHP , . :$lucky_number = 5; If ($lucky_number = 7) { echo " $lucky_number";

170

4

} else { echo " $lucky_number"; }

7 ( ), 5 ( ), if, () 7 $lucky_number. PHP , . . , PHP 4.01. true, / :if ($lucky_number === $random_number) { echo " $random_number"; }

, , . , , true false, , true false (. ).

!= == ! =. , PHP , ! ( ), , , .if ($lucky_number != 7) { echo (" 7"); }

!= . . if :if ($lucky_number 7) { echo (" 7"); }

(!= ) false , $lucky_number 7. . 3 . , , .

1. HTML :





2. quiz.php . 3. , . . 4.2 .

. 4.2.

4. , .

172

4

if , $_POST[question1] . , ; . (AND, OR, !) , . , , , , PHP. , , . PHP:if ($day == "" AND $weather === " ") { echo (" "); }

AND (&&):if ($day == "" && $weather == " ") { echo (" "); }

OR ! . OR .if ($day == "" OR $weather == " ") { echo (" "); }

, . ( ) ||, :if ($day == "" || $weather == " ") { echo (" "); }

, ( ) && AND . || OR. && || , . NOT , not . NOT . , , true, false . , , :if !($day == "") { echo (" "); }

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

,

173

false, , true. : $answer , echo.if !($answer) { echo (" "); }

, $answer ( PHP ). , ! $answer, $answer false, !($answer) true, . , , if, , true, if . . .

, , , . 21 . . 1. HTML : Namllu. : : :

:

174

4 ?

2. car.php . 3. , . 4.3.

. 4.3.

4. . . 4.4.

, HTML ( , , ). else, , , , ( HTML ).

,

175

. 4.4.

PHP HTML ( age license). $_POST[age] $_POST[license]. HTML . : : :

:

?

name, age, $_POST[age]. (license) , , $_POST[license] on, .

176

4 on , Internet Explorer, Netscape Navigator Opera . , echo(), $license ( echo() 5).

PHP . if car.php , 20 , :if ($_POST['age'] > 20 and $_POST['license'] == "on") { echo (" .");

: 21 , :if ($_POST['age'] < 21 or $_POST['license'] == "") { echo (" , .");

. : , 20 21 , , 20.5? , . . , , >= = 20 and $_POST['license'] == "on") { echo (" ."); } else { echo (" , .");

switch if . if else if, switch. . switch:switch ($grade) { case $grade>90: echo (" A."); break; case $grade>80: echo (" B."); break; case $grade>70: echo (" C."); break; case $grade>50: echo (" D."); break; case $grade, holiday.php 41 . . HTML , . , PHP , $_POST[posted] , ( ) if isset(). if :$price = 500; $starmodifier = 1; $citymodifier = 1; $destination = $_POST['destination'];

180

4

. 4.5.

, $destgrade, $_POST['destination'] $_POST['grade'].$destgrade = $_POST['destination'] . $_POST['grade'];

, $destgrade Barcelonafour. switch ( if):switch($destgrade) {

. ( , , .) , , , , , . , $destgrade Barcelonathree, Barcelonafour, Praguethree, Praguefour, Viennathree Viennafour, . , :case "Barcelonathree": $citymodifier = 2;

, $price = $price * $citymodifier; echo " $destination - $price"; break;

181

Barcelonathree $citymodifier 2, . , break . $destgrade , , . case break, :default: echo (" "); break; }

, , , , else case .

PHP : while, do while for. , , . , , , . , .

( ). PHP . , , . , . , , . ; , , . (iteration). , .

while while if, . , , , :while ( ){ ; }

, , , , ..

182

4

, , PHP . :while ( ){ ; }

, , , . . , , , , . , , PHP :while ($shopping_total > $credit_limit){ echo (" , "); $last_purchase_but_one = $shopping_total - $last_purchase; $last_purchase = $last_purchase_but_one; }

$credit_limit, ($last_purchase) ($shopping_total). $last_purchase, , , $last_ purchase_but_one. , , $shopping_total , $credit_limit. , $credit_limit , . , , . , , false. , . , . . while , , , 3. , . , , . , . , . , , : , . , . , 1000 5% 100 , 50 . , 50 . 950 , 100 , 5% 47,50 . , , : = =

,

183

, , , . , PHP while.

while1. HTML : . Namllu


1000 5,0%
5000 6,5%
10000 8,0%


184

4

2. loan.php . 3. . 1000 , 100 . . 4.6.

. 4.6.

, $_POST['loan'], , $_POST['month']. loan.php. . switch, . $duration, , . switch, , HTML :$duration = 0; switch ($_POST['loan']) { case "1000"; $interest = 5; break;

, case "5000"; $interest = 6.5; break; case "10000"; $interest = 8; break; default: echo " "; exit; }

185

$_POST[loan]: 1000, 5000 10000. $loan , switch $interest . , , . while, . , , $_POST[loan] ; , :while ($_POST[loan] > 0){

$_POST[loan] , , $loan 1000, 5000 10000, 0. $duration, , , , :$duration = $duration + 1;

, , :$monthly = $_POST['month'] - ($_POST['loan'] * $interest / 100);

, 100%, . , , , . , : =

$monthly? :$month = $month - ((($_POST['loan'] / 100) * $interest);

, $_POST['month'] , , , 100 . , $_POST['month'] , . , , , $monthly. . if; . , , , , $_POST['loan']:$_POST['loan'] = $_POST['loan'] - $monthly;

186

4

. :$_POST['loan'] = 1000 $interest = 5 $duration= 0 $_POST['month']= 100

while (1000 > 0)

1000 0, , , $duration = 0 + 1;

$duration . $monthly = 100 - (1000 * 5 / 100);

, $monthly = 100 - (50);

$monthly 50. :$_POST['loan'] = 1000 - 50;

$loan 950. , . , :while (950 > 0)

. $duration 1, $duration = 1 + 1;

$duration 2. , $loan:$monthly = 100 - (950 * 5 / 100);

$monthly 52,5. :$_POST[loan] = 950 - 52.5;

$_POST['loan'] 897,5. , . , . 50 , 52,50 .. :while (897.5>0)

, . 15 , .

,

187

, , , , . . , , $loan>0 . PHP 30 , . Windows 2000 IIS 5, , , Web . , , . ; . , . , $loan . :$_POST['loan'] = $_POST['loan'] - $monthly;

$monthly $_POST['loan']. , $monthly ( ). , $monthly . , , , . , : PHP . , exit, :if ($monthly $credit_limit);

, , . , . , do while . , 14 103. :do{ ; } while ($exit != 103);

, , , , , , . 103 , .. , . do while PHP , , , , . , , . , , , . do while:do{ $remainder = $possible_prime_number % $number; $number=$number + 1; } while ($remainder != 0 AND $number < $possible_prime_number);

$possible_prime_number ( %) 2 $possible_prime_number 1 , . . , , . , , , , , do while . , , , 1, .

,

189

do while , . PHP , 1 10. , , do while, . do while, , PHP .

do while1. Web : :


2. check.php . 3. , . 4.7.

HTML : :

$_POST['guess'], $count:$count=2;

190

4

. 4.7.

2, 1; 1. :do{

$_POST[guess] $count. $count :$remainder = $_POST['guess'] % $count; $count = $count + 1;

. , 25634, 2, 3, 4, 5, 6, 7, 8 .. 25633; .. . : $count $_POST['guess']:} while ($remainder != 0 AND $count < $_POST['guess']);

, , . , $count $_POST[guess], , , $count, $_POST[guess] . , , , . , , , :if (($count < $_POST['guess']) || ($_POST['guess'] == 0)) { echo (" "); } else { echo (" "); }

.

,

191

for for , . , . , while, :for ( ; ; ){ ; }

for , .. , , . for , .. , . , . . , . for? , 10 . 10 echo, . while :$counter=0; while ($counter

2. scope.php . 3. scope.php (. 6.2).

, , , PHP. $global_message:$global_message = " ";

my_function:function my_function() {

$local_message $static_number:$local_message = " "; static $static_number = 0;

284

6

. 6.2.

, :echo "
: " . $GLOBALS["global_message"]; echo "
: " . $local_message; echo "
: " . $static_number;

return $static_number, 1:return $static_number = $static_number+1; }

my_function():echo " :"; my_function();

, , " ", " " 0.

285

, . . $local_message $static_number , :echo echo echo echo "

:"; "
: " . $global_message; "
: " . $local_message; "
" . $static_number;

, , . $static_number.

(nesting). . , , . , parent, ( child). , parent , child, , . . ( , ), : ( ).

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

1. Web :

2. recursion.php . 3. recursion.php (. 6.3).

. 6.3.

, , . . 6.4.

287

. 6.4.

, $num_value:

, $num ; , 1 ( 1, , 1). , . , . ( ), , , , , . , , , .

288

6

include require ( ). . , , include require ( , , , ) , . , . include , require . . PHP , PHP HTML , , PHP . , , , . PHP . PHP , . ( ):include("filename") require ("filename");

, include test.txt, :include("test.txt");

test.txt , Web , . , include require , :$Name ="1"; include ("test" . $Name . ".txt");

test1.txt, , , . , : ; / , ;

HTTP ;

289

PHP ( ); ,