Upload
aaron-mercado
View
74
Download
2
Embed Size (px)
Citation preview
www.bhv.ruwww.bhv.kiev.ua
! 1! 1
1|
.
4-
-
2003
681.3.06
. .
4. .: -, 2003. 576 .: .
ISBN 5-94157-071-6 4 - , , -
, Web-. - HTTP CGI, , , --
, -
, .
Web-
:
.
.
681.3.06
02429 24.07.00. 27.01.03. 70x100V,e. . . . . 46,44.
. 5000 . Me 699"-", 198005, -, ., 29.
, 77.99.02.953..001537.03.02 13.03.2002 . .
"" .
199034, -, 9 , 12.
ISBN 5-94157-071-6 . ., 2001 , "-", 2001
1 2 3 4 5
I. WEB- 9
1. 11 11 TCP/IP 13 14
IP- 14 16 ' 19
20 20 21 21 22 22.... 22 23- () 23 24 24HTML- 24 ( HTML-) 24Web- 25
World Wide Web URL 25 26 26 26 27
2. CGI 28 CGI? 28 URL 29 GET 30
GET 32POST 32Content-type 32User-Age n t 33
IV
Referer 33Content-length ' 33Cookie 34Accept 34 telnet 34
POST 35 36 37
"" 38 38 39 POST\\ 40
3. CGI 42 43
44 CGI- 46
CGI- 48 48 GET 50 POST 51 URL- 53
56 57 61 62
64 64 (file) 66
Cookies 67 Cookie 69 Cookies 71 Cookies 71
73
II. .WEB- APACHE 77
4. Apache 79: ? 79 80 : Apache 80
: 81 : Apache 82 : Apache 86
Apache 88
V
5. MySQL 93 93 Apache 95 96 97 MySQL 98 MySQL 100
III. 103
6. 105 ? 106 108 - 110 Web 114
7. , , 117 117
118 121 122 123
123 124
124 126
126string 127int, long 127double, float 127bool 127array 128list 128object 128void 128mixed 128
129 129 130 130
130 132 133
135 136 136 136
VI
137 137 138 138 140
140
8. 143 143 145 146 Cookies 148 149 151
9. 153 if-else 153 ; 154 while 155 do-while 156 for 156 break continue 157 do-while break 159 foreach 160 switch-case 161 require 162 include 163 include 163 164
10. 167 " ". 168 list() 170 : ? 170 array() 171 172
172 countQ 173 173 175 177
178 179
11. 181 182 184
return ...185
VII
186 187 188
190 191
SGLOBALS 192 194 195 195 197 " " 198 199 : Dump() 201 202
IV. 203
12. 206 206 if-else 207 209 210 212 213 214 216 ( ) 217 218 219 221- 223 225
13. 226 226
(asort()/arsort()) 226 (ksort()/krsort()) 227 uksort() 227 uasort() 228 array_reverce() 228 sort()/rsort() 228 usortQ 229 shuffleQ 229
230 231 ... 232
VIII
232/ 232 234 236
14. 238 238 239 239 241 242 242 243
15. 244 244 245
or die() 249 249
250 > 250
/ 251 / 251 CSV- 252
253 254
254 255
255 256
257 258 260 261
262 "" 265 266
16. 268 268 269: 271
17. 273 273 275 ...276
IX
18. 277
19. 280 timestamp 280 281 283
20. 285 . 285 286
286 287 287
: "" 288
21. WWW 289 289
289 290
290 Cookies 291
291 Cookie 292 Cookie 293
SSI virtual() 294 virtualO 294
22. RegEx 296 296
296 297 297
298 298
298 299
RegEx 299 300 302 304 304 305"" 305
308 309
309 309 310
310 310 E-mail 311 ..... 311
312
23. 314 GetImageSize() 315 GD 316 316 317 318 319 RGB 320
320 320 321 RGB- 322
322 322 323 324 324 324 325 325
326 326 327 327
TrueType 327 : 328 329 329
24. 332 332 333
error^reporting 334magic_quotesjgpc on/off 334max_execution_time 335track_vars on/off. 335
335 336 @ 337
337 ...338
XI
339 339 341 343
344
25. 345 ? 345 346 347 348 349
349 350
351 352
352 354: 354
Cookies 357 SID 357 358 359 Cookies ? 360
26. MySQL 361 362 MySQL 363 364 365 365 MySQL 366
366 371 371 371 371 372 , 372 ...372
373 373 374 374 375 MySQL 377
MySQL 378 379
XII
27. 381 381 DNS 382
IP- 383 IP- 383
V. 387
28. 389Multipart- 390 390 391 392
392: 393 395 396
29. . "" 397 397 398 404 405
: auto_prependjlle 406 : Apache 407
Apache 407 411 412 -.413
30. 415 416 417
417 419 421 422
423 423 425 426 427 428
429 431 ? ...433
XIII
434 Apache 441 443
"" 449 450 451
31. - 453 454
454 456 MySQL 456
459 . 460 461 462 464 MySQL 465 478
479 481 482
32. 486- 486 488 493
33. 496 496 501 503 checkbox 504
VI. 507
1. Apache httpd.conf 509
2. php.ini 536
555
-...
!!!in
Get ReGet!ReGet - , ,
FTP- HTTP-. , ReGet -.
, ReGet
.
ReGet 1.7- MS Internet Explorer 5.5,Windows 2000 .
ReGet - . ,
, .
ReGet - .
!www.reget.com
-
.
, "" ,
. , , -
Web, , , Web-. - , , -
, .
(, ) - .
, -
, -
Web. ", , - ""
? - ,
- , "" ,
, , . , -, ,
..." . ,
, ,
, Web, , - .
, . ,
, Web-. , .
" ", Web- . ,
.
. , Web- . ...
, , -
, " ", - "-
" . , -
( ), , ,
. . - -
Web: " ", -
( , ) . - , ,
"" ,
- .
, IBM, : " . : - . , -
, ". ,
.
, Web-, - . , , -
? , , " " , , -
. ,
. , ,
,
- .
. , ? , , , ,
. , ,
.
, , , -
( , - )? . , , - Doom, .
, , Web- ( , Web) -
. -
. -
,
, "" Web-. - , ,
, . , ,
" ". ,
, ,
, , -
" ", .
, "". , -
"" . -
, , , -
( ) , . ? , ,
.
.
Sun Microsystems (, ), - Windows 50 . , ( , 10 , -). 50 20 =1000 ( 20 ). , 30 (, - , - , -
). , -, 1000 /(30/60 )//3600 =555 555 , 555 555/24=23 148 - 23 148/365=63 ! - , , , 24 , .
, , ,
( ). , " ", , ?.. 50 , 5 . , , 1000 . - 6 . , , - 555 555/10/1000(24/6)=222 , . ... , ?.. , , -
. , ?!,
. , -
, . ,
, Internet Explorer? ...
, : Web-. - , .
, .
, ,
Web-. , , -
,
Web., ,
. -
4, - , Web- , , -
. -
, ,
Web, , . -
Web-, . - ,
Web-. , - . -
, "" " ",
, -
, Web. "" "
, ..." " ...",
. ,
, , -
. : " , , ,
, ". ,
,
. : - , -
, , -
, -
, , . -
, . -, "
" .
, ( ) , :
;
Web-. , - . ,
, ( - ), . : "", . . -
. ,
-
. , ,
, -
.
, 33 , .
. -
CGI (Common Gateway Interface ) , Web- - . -
.
.
,
Web-. .
Web, -, .
(, Perl ), . , - Web, CGI, , HTML Web, CGI HTML . , Web- . CGI -
, "" ( - ). , : - , "". ,
.
, .
-
, -
Apache. Apache , ( , ). ,
. ,
- -
, Apache. Apache Windows, , , -
. , -
- , " ",
. - "" Web- " " .
.
.
, -
Web. 99% , - . 1% - Perl ( ). , : , - , , ,
, ,
. , -
, .
-
,
, . -
, , -
. , ,
. ,
, ,
. , "" Web-, , , -
. , -
( -), , - .
-
. -
, . ,
, Web- , . -
,
, , -
-
. ,
- , , HTML- .
,
. : - (upload) , , - . .
, Web-. 1 - Apache httpd.conf. ,
. 2 , -
. -
, ( ).
I.
WEB-
1
, -
, ,
. . , , -
-
, -
, , .
. . , -
, ,
, .
, ,
.
, ""
, ,
. "": - , "" -
. ,
, , ,
.
. ,
,
, -
, . .
, -
, .
.
, . ,
, Web-. -
12 I. Web-
TCP (Transmission Control Protocol - ), , HTTP (HypertextTransfer Protocol ), TCP. HTTP Web-., ,
.
. ,
,
.
,
"" , , , . . -
"" , -
. . 1.1 , -
Web- . - : - ( ), . , -
, .
,
"", . -
,
TCP/IP ( - "").
TCP
1IP
.
1>
Web-
t i
TCP
:'IP.
[
. 1.1.
1. 13
" " ,
" ". , IP ( TCP) TCP, a TCP, , " " HTTP ( Web-, HTTP ). -
, .
.
, ""
, . . HTTP , - TCP.
TCP/IP , -
TCP, , , -, (, - TCP ). , -
, , IP ( , IP , - ). TCP IP - ,
TCP/IP ( UDP, - ). - TCP, .! -
, .
(, , , ), "" - , -
.
-
, -
. , "" -
,
. , (-, ), , , -
.
TCP/IP , - , -
14 I. Web-
. -
, -
, -
.
,
.
( ), "" ( ). , ""
, .
, -
TCP/IP. Web- TCP/IP - ( ) - "", , HTTP, - . , -
.
. ,
TCP/IP, .
, . ,
,
. , -
( - ). , , ,
. TCP/IP IP- . , .
, , .
. , " " -
, . -,
, -, ,
"-" , .
IP- ,
"",
1. 15
, IP-. 30 (, )IP- :127.12.232.56
, 8- ( 0 255 ), . IP-: (, 127.. . 1 -, , 255 - ). - .
: ( ). , , IP- , ? "" ( ""?),
, ? -, , , -
, -
.
.
, ,
. , 1 ( - ), 11 ( ) . , ?, , -
, HTTP, WWW (World Wide Web, ).
( \ , , , -
.
, -
"", .
,
,
, ""
. , -
( , ,
). - .
, 1 somehost - IP-. : -- , somehost.
16 _ I. Web-
(, 0,1 , . . -
, ), , . ? . . -
, somehost. , , - 0,1 . ? 0,2 11x10== 110 . , . , 1 "" 10 - , . . 10 , !, : - . ,
, , ""
. , , ,
100 .
) .
,
"" -
. IP- - , , D. , -
. TCP/IP ( ).
- IP-. , ,
. , -
DNS (Domain Name System ).
DNS , - IP-. - -, , -
. ,
DNS, .
, DNS IP-, . :www.somehost.msu.suTo , ( ), -. N- (-
1. 17
, su , m s u . s u - - , s o m e h o s t . m s u . s u - . .) , DNS- : - , :
www . somehost . msu . su .
(-, ) -, -
. -
, .
^
, ? . IP- DNS- . - . -
. , ,
, ...
, IP- - .
IP-. HTTP 1. 1 ( ) Web-, - , ,
, ,
IP- . - HTTP 1.1 , - ,
Web. , DNS- IP-. DNS - , , ,
, ,
(, ). , Web- - (, ) . - , , Netscape. DNS-? - DNS-, , IP-. , . -
IP- w w w . h o s t . r u . ( - ! ). , - (, DNS-, ),
18 I. Web-
" ." ( -, ). : IP- (, IP- DNS-), - ru. IP- , , -
host ru ".". IP- www somehost .ru., "" , , -
, . . . -
, , , -
ru. ( )-- , h o s t . r u . -- , . .
, , -
. ,
, -
, , , -
DNS-, DNS-.? . , ".", IP- - . , -
DNS-, ( ru, com . .) . , ,
, w w w . h o s t . r u . , , ,
host , , www. w w w . h o s t . r u . , IP-, . -
DNS- -. , -
, , , host . ru. IP-. , .
, , , -
, IP-: - ,
IP- .
( ^ ^ , -
IP-, , IP- , , , . .
1. 19
, -
. ,
, .
, , -
. , -, (, - ) IP. TCP . ,
, - -
. , ,
TCP. , - . , TCP , .
( ), -
() . , :
"" , -
;
,
- ;
. "-
" ( "-" ). , ,
TCP, , , 0 65 535 ( 2). TCP , , - ""
( ). ,
. , ,
"" , .
TCP- : , , ? , . , -
, :
IP- , ; , .
2 . 699
20 I. Web-
, ,
TCP , - IP- . " " , , .
"", , -
- , .
, TCP - : . "" ? -, - , -
( , , TCP ). - TCP , -
-
"" . -
.
, .
"" ( - " ", -
3 ), - . ,
Unix ( , -). , , , , -
. ,
, PHP f sockopen ( ) .
,
"" . , -
, .
, , , , -
"" . " -
". ,
, .
, -
, , "-
" .
"" IP-, -
1. 21
, . -
(""), , - IP- ( ), .
, "". , -
. ,
. -
, - TCP/IP, . . - "" . ,
, -
( , ,
, TCP/IP). , .
"" , ,
( , TCP - ), . , , WWW, Web-. , , - . , , -
.
, , IP-. - . -
( , )., : , -
IP- , . () , ,
. ,
,
IP-. , ,
WWW, DNS-., , TCP "", - IP- . , IP- .
, , -
. ,
TCP. , ,
22 I. Web-
, . ,
Web- 80, , - , 80 .
,
, -
. , -- -.
Web-, FTP- Telnet-.
^~
" " Unix. ,
, -
( , , , ). - ( ), - , . - "-
" .
, Web- , -
. , . .
Web-. - , ,
"" . , ""
(-), -, - , -
.
( 100200 ), , .
, ,
.
( , ).
, . -
, . ,
1. 23
. , -
. -
. ( ) , , , . ,
, , .
, : , , .
, IP- , , , - (, DNS-). - , -
HTTP 1.1. Web- (, -, ) , , IP-. , ,
HTTP 1.1, .
" " Web. , -
Web HTTP 1.1. sendmail SMTP (SendMail Transfer Protocol ) " ", , -
, . , syn.com - microsoft.com, E-mail [email protected] - [email protected]. , , IP-.
- (), ( ) ,
. -, -
, , telnet- ( - ) . . - ,
. , -
-, -
( ). - Web-
24 I, Web-
, : , Web- - Windows. ( , -
TCP , , ,
.) , -. , ,
.
, -.
,
HTML- ( HTML-). , -, , . ,
, -
.
HTML-, HTML.
( HTML-)
World Wide Web, Web- . HTML-, -
" " -
. , , -
, -
, HTML- . HTML(Hypertext Markup Language ) - .
, -
. , , -
HTML, - , .
1. 25_
Web- , -
, , .
"i". , HTML- - , , "
" . ,
, Web-. - ( , , . .) Web- -. , Web- - (, -, -
), . Web-, .
, ""
, , . .
" ". , ,
, .
^
, - -
. , -
, , IP- . .
World Wide Web URL "" WorldWide Web, Web WWW ( ). -, WWW HTTP (Hypertext Transfer Protocol - ). , ,
.
, - "" .
URL (Universal Resource Locator -- - ) , . URL? DNS-?
26 I. Web-
- . , Web- . , -
, -
.
URL :http://www.somehost.com:80/path/to/document.html
URL.
URL, - ( h t t p : / / ) , , - Web-. HTTP, . -, HTTPS , , -
, Web- . , , TCP, . -
, , -
HTTP.
, -
( www.somehost .com). , IP-. , - , (), IP-.
( ) . , HTTP 80 ( 81). , . ,
(, , ), , 80 Web-, HTTP- - . , -
, FTP Telnet, .
1. 27
,
( /path/to/document .html). -, , -
, , " "
. -
, / Y / M / N . h t m l N Y, -, ht tp ://_/20//20.html , 20 2000 . 20.html , ,
( , ). ,
, -
.
, -
. -
. , :
http://www.somehost.com/cgi-bin/something
, cgi-bin, , - .
html ( HyperText Markup Language -) Web. HTML , , , -
. . html : g i f ,jpg , cgi, pi (, ) . . , , , ,
, htm HTML- ( ).
) ,
.
2
CGI
CGI (Common Gateway Interface ) , Web- Web-. . ,
Web- CGI--. . CGI - Web-, CGI- .
CGI-, . , -
, , "
" , Web--. -, . , .
CGI?,
http://www.somehost.com:80/path/to/document.ext
, HTML- ( , ). , , / p a t h / t o / document. ext, ( , , Web-, 80 ). . .
/path/to/, document.ext .
(alias) . , ,
Web-, "" -
( 7).
2. CGI 29
document. ext , -, , -
, HTML- (, , , , ). , . ,
. ,
, .
. ,
, , CGI. CGI - , . -
, CGI, - - ,
-, Basic (, Perl ). . , -
, , " ". -
, , -
. , -
, ,
. ,
, , -
! . ,
, ,
. ,
, ( - , )? , - , -
, ( , -, ). - CGI. URL.
URL, , - URL? , . URL "" :http://www.somehost.com:80/path/to/document.ext?parameters
, parameters, - . -
. , , -
( ,
30 I. Web-
URL-, . ). - CGI-.
^
-
. ,
.
. -
, , :
http://www.somehost.com/script.cgi?time=+5
script.cgi, , (, - time +5, . . 5 ) - . , -
=.
(, , )? :http://www.somehost.com/script.cgi?time=+5&name=Vasya
, &. ,
. ( - ,
""? , ). , , : , . . , -
,
.
, ( - URL) GET. , (, - ), GET. ? , . ( -) - POST, , "" .
GET , ,
somestring .
2. CGI 31_
somestring? , . . , ( , ), Web- -. - :
GET somestring HTTP/1.0\n... ...
\n\n
\ , \\ - , (, ). , .
, GET- -, . -
. (headers), - . HTTP - .
HTTP. , - , , -
, POST, - .
-
. -
, -
(, -) - . ( ) - , .
CGI-, - . ,
,
( ). .
^) , - -
, ,
. Web-, .
,
,
CGI-. .
32 I. Web-
, ,
. .
GET : GET ? /1.0 : REQUESTJJRI; QUERY_STRING -
, REQUEST_METHOD - GET.
( POST) . - , ( , ,
). HTTP/I . , H T T P / I , i. - ,
, .
? , URL. - , -
. URI(Universal Resource Identifier - ). URL ( , - HTTP). , URL Web- , , - URI , ( IP-) .
POST : POST ? / 1 . 0 : REQUESTJJRI; QUERY_STRING -
, REQUEST_METHOD POST. POST. , ,
GET , , .
Content-type : Content-Type: application/x-www-form-urlencoded
: CONTENT TYPE
2. CGI 33
.
appiication/x-www-form-uriencoded, - , ( - ) . , GET POST. ,
multipart/form-data. , , - .
,
, -
.
User-Agent : User-Agent: M o z i l l a / 4 . 5 [en] ( W i n 9 5 ; I) : HTTPJJSER_AGENT ( Netscape Navigator).
Referer : Referer : _
: HTTP_REFERER , URL -, -
. , , -
(, ), , - Referer.
), , , referer - - "". , . , HTTP, , -, .
,
HTTP_REFERER.
Content-length : Content-length:
: CONTENT_LENGTH
34 I. Web-
, -
, POST. GET, , , -.
Cookie : Cookie: _)
2. CGI 35
, -
"Bad Request", , -. ,
HTTP/I . .
, . -
: "\\" (, , "" ), , , -
.
, -
, Cookies, POST . . -, , ( - , ).
POST POST. , GET POST ( \\) - ? .
Content-length , :POST /script.cgi HTTP/1.0\nContent-length: 5\n\nTest!
,
. ,
\\, , Test ! 5 . , POST-( , ), - . ,
, . . ,
? content-Length, .
.
POST? , . , Web (. ) . , POST
36 I. Web-
: , GET, , , , URL , POST- URL .
, GET, POST - URL- . ? , (, - , 20 ), - - E-mail Web - " " , 127. -, 0 .. 32 128 .. 256 URL- . , , : % . , (+). , .
,
(, 3 !). -
-.
-. ,
, . ,
, ,
, ASCII. , , , KOI-8-R, WIN-, .
,
( , , ). , - ,
, , -
! , "" ,
, -
. .
, "" - -
, .
( ^ ,
,
2. CGI 37
. ,
online-. , .
? , , , - ,
. ,
, , -
? , Web- , telnet'y? - - ? -, . ,
. .
, , -
GET POST. URL- ,, . , HTML .
GET. URL . ?, & , %.. . , . ,
HTML, , , . ,
HTML, .,
script.cgi (, , cgi - CGI-, , , ). 2 :name . , .
h t t p : / / w w w . s o m e h o s t . c o m / s c r i p t . c g i HTML-:
, name! , age !
, name age - , .
38 I. Web-
""
URL, . - ,
http://www.somehost.com/script.cgi?riame=Vasya&age=20
:
, Vasya! , 20 !
, &, =. . , .
,
0 , - -
Windows, . , HTML- (, form.html - ) -, . -
2.1.
I 2.1. /form.html
:
:
,
(, name="age"), . , , HTML ( , , ), . - name value , . , HTML ( -
2. CGI 39
), .
. :
'jlXAhomolciaclcciAwwwYlorm.hlml - Microsoft ^ | J
........ " ............... , ...^ ' ; ."
' i - - ; : ." :
\ | http://wvvw.sornehos1.camAorm.html
: [ : (
! J ;
:.[ | | |S|
. 2.1. HTML-
, ,
!, URL, action :http://www.somehost.com/script.cgi ? , input , (&). - =. , -
?, URL, , (, Vasya 20 ):http://www.somehost.com/script.cgi?name=Vasya&age=20, , , -
, , URL- . ,
-
.
action . - (/), .
40 I. Web-
-
, script.cgi , (, HTML- ).
( J , , , "" . -
- ( -, , ), URL, - / URL . http://www.somehost.com. , . , .
, ,
. action - :
,
(, , ) / . , , - ,
URL , , ( ). :
, ,
, , .
, ,
"" .
World Wide Web - ( ) , , .
POST , GET, - POST? : method=GET method=PosT. .
action , GET.
2. CGI _ 41
,
, , . .
,
, .
: -
, - ( ). , -
, : -
, . ,
HTML- , . , , ,
, . ,
, -
: ", . -
, ?". - , ,
URL .
( 99% , -). , "" ( URL , , -, ). ( - ) . .
3
CGI
CGI. , .
- CGI- (CGI-), ? - , ? , .
,
CGI-. , , , -
() - - CGI- ( ). , - . , . . -
; , , ( , , -
.). , - .
,
( , "Hello,world!"). , , ( -, , , ,
Web-). - , CGI , - , -
. , -
(, ). -, , (- !) , ( ++). , ,
,
.
3. CGI 43
, .
, -
" ". , -
,
, HTTP . ,
Web-. ,
, -
. , -
CGI HTML, - , . , -
, .
, ,
( Web-), . . ( ) . , , ,
, . , ,
:
( ) . ( , - ): ( stdout), - . ,
, , -
"". ( , . ,
"" .) , , -
. , -
: ,
. ,
, , GIF- ? -
.
44 I. Web-
, -
, . , -
( ), - , .
\\. , , -, , .
, -
. ,
. -
, , :
/1.1
:
/1.1 404 File Not Found
,
. , -
. , -
, ,
.
( ) ,
. , ,
(, status, ). - .
.
Content-type : Content-type: !_; charset=koi8-r
. charset ( KOIS-R). mime_n , :
text /html HTML-;D text/plain ; image/gif GIF-;
3. CGI 45
image/ jpeg JPG-; .
Pragma: Pragma: no-cache
, -
,
. , , ,
.
Pragma ( , ), .
Location: Location: http://www.otherhost.com/somepage.html
,
,
( URL). , , Location, .
Location - , . , , -
, -
, .
Netscape , , - Location URL ( , , self-redirect). - , , , , -
. Netscape , - , " ". -
, /. V .
Set-cookie: Set-cookie: _)
46 I. Web-
Date: Date: Sat, 08 Jan 2000 11:56:26 GMT
.
Server: Server: Apache/1.3.9 (Unix) P H P / 3 . 0 . 1 2 -
.
CGI- ,
, ( 3.1).
! 3.1. script.!... J
#include // rand()#include // /#include // rand()
// . ,void main(void) {
// int Num; time_t t; srand(time(St));// Num 0 9Num = rand()%10;// . html-printf("Content-type: text/html\n");// printf("Pragma: no-cache\n") ;// printf("\n");// printf ("") ;printf ("!") ;printf(" 0-9: %d",Num);printf ("") ;
3. CGI 47
CGI- .
cgi-bin, . , -
, ( ). , , ,
.
:
http://www.myhost.com/cgi-bin/script.cgi
HTML-. , Reload( ) - , ( ).
Pragma: no-cache
, ,
HTML-, . ,
- GIF- (, - ). : Content-type: image/git
-- GIF- ( fwri te, . . - "" GIF-). :
... - ...
... ...
, . ,
,
, -
. -
, .
: CGI- - HTML-, - MIDI-. content-type. He -
48 I. Web-
, -
500- ( Apache), .
CGI- , ( - , ), . ,
, ( POST) . .
-
.
, , , ( ). ( , -
):
_
( , -) - , -. , -
*/*, , .
HTTP_REFERER , , CGI-. , ,
, ( -, , -
).
HTTP_USER_AGENT . -
MSIE, Internet Explorer, , Mozi i ia, Netscape.
3. CGI 49
HTTP_HOST Web-, . , Host HTTP 1.1. , , -
, Location, ( , "" , ,
).
SERVER_PORT ( 80), . - Location.
REMOTE_ADDR IP- ( ) -, .
REMOTE_PORT, -
.
SCRIPT_NAME ( URL , ?). , , Location (self-redirect), action , ( ).
REQUEST_METHOD, ( - GET POST, ). -, -
, ,
, ,
, , POST. , - .
QUERY_STRING, URL . -, GET, POST ( action ).
50 I. Web-
CONTENT_LENGTH , .
,
POST-.
GET . ( , , URL ?) QUERY_STRING. , URL--. .
, .
, -
getenvo . , .
: 3.2.
#include // /ftinclude // getenvO
void main (void) {// REMOTE_ADDRchar *RemoteAddr = getenv("REMOTE_ADDR") ;
// ... QUERY_STRINGchar *QueryString = getenv("QUERY_STRING") ;
// printf ("Content-type: text/html\n\n") ;
// printf ( "" ) ;printf (". !");printf (" IP-: %s",RemoteAddr) ;printf (" , : %s",QueryString) ;printf ("") ;
CGI-. :
http: //www.myhost.com/cgi-bin/script. cgi?a=l&b=2
3. CGI 51
:
. !
IP-: 192.168.23 , : =1&=2
POST GET, , ( - stdin). To , , , -
. (, , , " " .)
: , POST, , GET. , POST URL-. , ,
QUERY__STRING.
,
POST? ? - CONTENT_LENGTH, (, - ). , POST-, GET-, :
| 3.3. POST
#include linclude
void main(void) {// char *RemoteAddr = getenv("REMOTE_ADDR");char *ContentLength = getenv("CONTENT_LENGTH");char *QueryString = getenv("QUERY_STRING");
// int NumBytes = atoi(ContentLength);
// char *Data = (char *)malloc(NumBytes + 1);
3 . 699
52 I. Web-
I / fread(Data, I, NumBytes, stdin) ;
// // ( )Data [NumBytes] = 0;
// printf ( "Content-type : text/html\n\n" ) ;
// printf ("") ;printf ( " . ! ") ;printf (" IP-: %s",RemoteAddr) ;printf (" : %d", NumBytes );printf (" , : %s", Data) ;printf (" , URL: %s",
QueryString) ;printf ("") ;
, ,
script. cgi , /cg i-b in/ . HTML- :
| 3.4. POST-
vform dction=/cgi-bin/script . cgi?param=value method=post>Namel: Name2 :
, - ,
HTML-, , , - :
. ! IP-: 1 3 6 . 2 3 4 . 5 4 . 2 : 23 , : namel=Vasya&name2=Petya , URL: param=value
3. CGI 53
, POST , GET. , POST , "" ( HTTP HTML).
URL- , , -
, , ""
, URL-. , URL- . . ,
, .
, , -
- ( "" , ) %, - .
, -
.
(, - ) , ( , & =). , - & =, ? , -
? , . , - , .
, : - (=), ( =), , :
| 3.5. URL-// st .// , .void UrlDecode (char *st) {char *p=st; // char hex[3]; // %int code; // // , ( ,
54 I. Web-
// 0, . )do {
// %~ . . .i f (*s t == ' % ' ) { //
h e x [ 0 ] = * ( + + s t ) ; h e x [ 1 ] = * ( + + s t ) ; hex[2]=0;// sscanf(hex,"%X",Scode);// *p++=(char)code;// , //
// , "+", " "else if(*st=' + ') *p++=' ';// , else *p++=*st;
} while(*st++!=0); //
,
, , , -
, . , -
, . .
sscanf () . , , , .
, -
, . -
:
| 3.6. POST- URL-#include #include
void main(void) {// char *RemoteAddr = getenv("REMOTE__ADDR");char *ContentLength = getenv("CONTENT_LENGTH");
// QUERY_STRINGchar *QueryString = malloc (strlen (getenv ("QUERY STRING")) -I- 1);
3. CGI _ 55
// QUERY_STRING strcpy (QueryString , getenv ( "QUERY_STRING" ) ) ;
// QUERY_STRINGUrlDecode (QueryString) ;
// int NumBytes = atoi (ContentLength) ;
// char *Data = (char* )malloc (NumBytes + 1) ;
// fread(Data, I, NumBytes, stdin) ;
// // ( )Data [NumBytes j = ;
// ( , // POST-, )UnDecode (Data) ;// printf ("Content-type: text/html \n\n") ;
// printf ("") ;printf (" . ! ") ;printf (" IP-: %s",RemoteAddr) ;printf ( " : %d", NumBytes);printf (" , : %s", Data) ;printf (" , URL: %s",
QueryString) ;printf ("") ;
, .
QUERY_STRING. ? - , . . -
, , -
3.5. , ,
. ? -: QueryString QUERY_STRING, , , . urlDecode ,
56 I. Web-
, , -
, .
, -
QUERY_STRING , , - ,
. .
, ? , . , -, " , "
( ).
( submit). , ( ). 3 -:
< i n p u t . . . >
< t e x t a r e a . . . > . . . < / t e x t a r e a >
. . .. . .
, , . ,
= , , -
&. , , , name, -
= .
, , -
. ,
( , - JavaScript) . . , :
... - ...
, Go! , , name.
. ,
, , -
3. CGI _ 57
- (, URL ). :
Go! submit=Go ! . - , , -
URL ( ,
submit). , , , =,
, name, ,
, value (, , ).
,
type. . , ,
( , name , ). ! .
HTML , - .
, .
(text)
58 I. Web-
, , , -
maxlen . , -
( "" ) - , -
.
value, .
(password)
, , , , .
, - . ,
value, , , - HTML- , , () ( ). - , , , , , -
,
- .
(hidden)
() . - , - ,
, , .
, , CGI-, - -
. E-mail , , -
, :
3. CGI 59
:
, -
text email. - , . :
: E-mail: :
, -
. , , -
.
,
, URL . , , ,
submit.
( _ j submit , . -
, , ,
submit ( -). , submit-. , . - hidden-, , submit: , , -
,
URL .
(checkbox)
60 I. Web-
( ), - , ( ). , , =, -
, .
checked, -, .
(radio)
3. CGI 61
value=TeKCT
name ( ) (, ), value. , name, - .
=_ ( , , , , ). , submit, (, -- ) , , .
(reset)
62 I. Web-
[width=iiiMpiffla] [height=BbicoTa][=]
>, oe
, . width - , a height . wrap, .
( ). virtual . -
, , ,
, .
.CD Physical , . None , .
, ( , ).
, , , -
, =, -
.
. - ( ) . . :
CTpoKalCTpOKa2
CTpOKaN
, . , -
, - .
size , . size 1, , size . multiple, , . -
, multiple .
3. CGI 63
. value, , - , ,
(, value ). , selected, ., : , HTML ( - ). ,
. , -
=, , ( , value, - ).
(multiple) , multiple-? : , , He-multiple-, , - . , , -
, :
=!&=2&...&=
, , -
. , -
. , -
, -:
OflMHflBaTpM
, -
(, URL- ):=&=&=
: ,
. ,
"", "". -
.
, multiple- - ( ), -miltiple - . , , ,
.
64 I. Web-
( , -
. -
,
Web. V.
-
-
, ,
. HTML . .
,
?, & =. , , ,
. , -
, , URL- - "" - - (, URL- %). - . , -
-
, , .
? &. , -,
POST, GET. , GET ... , - -
, enctype=muitipart/form-data. ( , , , enctype=appiication/x-www-form-uriencoded .) , , - ( ). HTTP- "-", . -
(\, , ):_\
Content-Disposition: form-data; =""\
3. CGI 65
\n\n
, :
3.7. Multipart-
Name: Box: Area: - TeKCT
, submit , :
127462537625367\Content-Disposition: form-data; name="Name"\n\n \
127462537625367\nContent-Disposition: form-data; name="Box"\n\nl\n
127462537625367\nContent-Disposition: form-data; name="Area"\n\n -
, ( _) . , ,
. , . -
. , , -
, , , . -
, ,
( \).
HTTP , - .
66 I. Web-
, .
( ) ( ), -, , . -
( , -)! .
: - , ="-"
( Content-Disposition),
, ( , ). , .
HTTP , \\, \. , , , , \. , - , .
(file) , . -
, , -
Browse . - :
- (, \^) . :
127462537625367\Content-Disposition: form-data; ="_";> f11="\ "\ \
.
.
\
3. CGI 67
,
( filename). , , .
, :,
( , -, ). , ,
.
Cookies Cookies ( , "" , "-
", ""). "", Netscape , . "" , -
, , , -
Cookies, , . ,
Cookie -- "". . , : , E-mail, ( ), , , ,
-
. -.
, -
, ,
.
,
? , -,
, , ,
? , .
, , , -
.
: , IP- . , ,
,
68 I. Web-
. , -
( , ) IP- () ( -
IP-, , , - - ). , -, .
,
, ,
, .
Cookies. Cookie - , -
( , !), ( ,) . , - Cookies, , , ,
. Cookies , ,
( Cookie). , Cookies, "" ( , -), -- "". ,
? , - , Cookies ( . ), , . -, HTML- - value (, , Cookies). . , .
Cookies, , -, Cookies - ( , ). , - Cookies . Cookies, Internet Explorer, "" Netscape, ., , Cookies ,
. , Internet Explorer. ,
Netscape ( , , ). ... , .
3. CGI 69
. , Cookie , . -
, ,
Cookie, URL , - ( ). ? : , - Cookies, (, , -
, Cookies). "" Cookies . : ,
, ( ,
Cookies). , "" Cookies
- Cookie , , ( ), .
Cookie : Cookie - ? " ", - . : Cookie , .
, Content-type, Cookie. - (, , ):Set-Cookie: name=value; !=; 1!=_; path=nyTb; secure
Cookie HTML- . , , - Cookie. :
, -
. : - , Cookie, - . ,. . ,
70 I. Web-
, -
.
^
, , : " , ?" : " , ! , - (, , )".
Cookie:
name
, Cookie. URL- , . . -- . , Cookies , URL- .
value, Cookie. -, ( Cookie) URL-. , , URL- (, , 2 , , . . ).
expires != Cookie. -, Cookie , . , expires=Friday,3i-Dec-99 2 3 : 5 9 : 5 9 GMT, "" "" 31 1999 . , :, "" Cookie. (, , Cookie 10 , - )? , . ,
, -
, , .
domain !1=_ , Cookie. . , ,
3. CGI 71
, , ""
Cookie . , , - .
path path=nyrb (, URI), , Cookie. , , , -
, . : , -
, , URI ( - ) , Cookie .
secure HTTPS, - .
( , ), .
, ( ), Cookie name value. : Cookie URL-, .
Cookies Cookies : - HTTP_COOKIE , QUERY_STRING, & ;. , Cookies:cookiel=valuel cookie2=value2, TO _1 :
cookiel=valuel;cookie2=value2.
,
.
Cookies , Cookies. URL- - , .
72 I. Web-
\ 3.8. , Cookies
#include #include
// void main() {// char Buf[1000];
// Cook Cookieschar *Cook = getenv("HTTP_COOKIE") ;
// 5 ("cook="), // Cookie, // (. ).Cook += 5; // 5
// QUERY_STRINGchar *Query = getenv("QUERY_STRING");
// , , // , , ,// if(strcmp(Query, "")) { // ?// QUERY_STRING,// 5 ( "name=") -// strcpy(Buf, Query + 5);// , Cookieprintf("Set-cookie: cook=%s; "
"expires=Friday,31-Dec-Ol 23:59:59 GMT", Buf);// CookieCook=Buf;
}// printf("Content-type: text/html\n\n") ;printf ("\n") ;
// ( ), if(strcmp (Cook, "")}printf(", %s!\n",Cook);
3. CGI _ 73
// printf ("\n") ;printf("Baine : " ) ;printf ("\n", Cook) ;printf ( "\n" ) ;printf ( "\n" ) ;printf ("") ;
URL - . - -
, . ,
31 2001 URL, , - . , ,
"" . ,
Cookie , , .
, -
. URL- Cookies, , - . , -
, : Cookies setcookie ( ) , Cookies , . .
, , ,
Cookies? ... . .
, - URL - . , , -
(login) (password). .
. -, , -
. -,
CGI- , -
74 I. Web-
, -
( ) , , , - ( , - ,
). , -, - , -
.
.
,
basic-. , -, :
WWW-Authenticate: Basic 1\="_"/1.0 401 Unauthorized"
,
. . _ -
, ,
.
CGI- - () - , ( ), ., , ( , ,
(. ) Cancel, . . ). - : -
, login password. , ,
( ) :
Authorization: Basic TG9naW46UGFzcw==
, , .
, -
( ). , , : ( ), "., , -
".
, ""
. : login password
3. CGI 75
Cookie, "" . , ,
Authorization: Basic _]
II.
.
WEB- APACHE
4
Apache: ? "" -
Apache, , - - Apache Windows 95/98. , , MySQL, Windows. (, - !), , Web!
, MySQL ( Windows 95/98) , . , : MySQL Windows 95/98, - MySQL: http://www.mysql.com.
,
(, Perl), ,
, . ,
100% -, -
( - Unix, Windows). , Win32, , , Apache , MIIS (Microsoft Internet Information Server - Microsoft) ASP (Active Server Pages - ), , , . , , -
. ,
HTML-. SSI (Server-Side Includes -), CGI (Common Gateway Interface ) , -
80 II. . Web- Apache
, . ? ( ) -- Web-. - ,
... ,
, "". Apache. , ,
Windows 95/98 PHP, CGI Perl- , Unix.
,
.
. :
Apache: http://www.apache.org; : http://www.php.net; MySQL: http://www.mysql.com; Active Perl: www.activestate.com; , Web-. : http://www.webclub.ru. : http://www.phpclub.net. dk: http://www.dklab.ru.
: Apache, Apache Windows 95/98. "" -
Apache: http://www.apache.org. -
Windows. Apache .
( ^ , -
. , -
Apache , . -
, , ,
. , ,
4. Apache 81
( ) - Apache, , , .
:
1. Apache. - Next (. 4.1), - Yes, .
Welcome to the Apache Web Server Setup program.This program will install Apache Web Setver on yourcomputer. '.
It is strongly recommended thai you exit all Windows pro gramsbefore running this Setup program.
Click Cancel to quit Setup onb* then dose emy programs you haverunning, pick Next to continue with the Setup program.
WARNING: This program is protected by copyright faw endinternational treaties, .
Unauthorized reproduction or distribution of this program, or any portion. of it may result in severe civil end criminal penalties, and will beprosecuted to the maximum extent possible under law.
fciext>
. 4.1. Apache
Choose Destination Location
Setup will install Apache Web Server in the following folder. , , . ; . .
To insteif to this folder, dick Next
To install to a different folder, click Browse and select another folder.
You can choose not to install Apache Web Server by clicking Cancelto exit Setup-
Destination Folder -. '.--- -.
C:\Program FilesV^acfie GroupNApache Biowse...
82 II. . Web- Apache
2. Next , Apache (. 4.2). - ,
( , , C:\Program Files\Apache Group\Apache). - .
3. Typical () Next (. 4.3).
4. Apache . , Next. - .
5. Finish. - , .
Setup Type
Click the type of Setup you prefer, then click Next.
1 Program will be installed wllh the mostcommonoptions. Recommendedformostusers.
Compact Program will be installed with minimum requiredoptions.
Cy.st.om You may choose the optjonsyouwantto install.Recommended for advanced users
. 4..
: Apache ,
. Apache C:\Program FilesXApache Group\Apache\htdocs, - . ,
,
(, z : ) subst, Windows. , .
4. Apache 83
1. , ( ). , , C : \ I N T E R N E T . z
:.
2. C:\autoexec.bat ( @echo off, ) :subst Z: C:\INTERNET
3. , z: . , C:\INTERNET, z : , . .
, Windows 95/98 . - subst " " (, , Z: C:\INTERNET), - .
Perl- ( ). - .
z: - (, Windows 95/98 DriveSpace). , , , - subst, , -. Web-, ?A DriveSpace . - DriveSpace, Windows . Z: home, locaihost.
Apache , - http://localhost. . cgi www. CGI-, . ,
( ). - . 4.4. httpd.conf, - conf Apache ( C : \ P r o g r a m Fi lesXApache GroupXApache). , - , Edit configuration, | Apache Web Server IManagement. Httpd.conf -- , -. ,
, .
4 . 699
84 II. . Web- Apache
. , -
,
(, , -
). . Apache locaihost, , -
, - .
- locaihost iSji
: JCJ Z:\home\localhost
i ! SI (F:)j : as>sft(Z:)B-Q home
-Sl locaihostCJ cgiCl WWW
LiJ
> |
x ;
J
.d
d '
v' " Pi
cgi ww\v
. 4.4.
serverName :ServerName locaihost
serverName, , . - # ( ), , , Apache.
DocumentRoot , HTML-. , z:\home\localhost\www)DocumentRoot z:/home/localhost/www
, - ( - ). .
:
Options Indexes IncludesAllowOverride AllAllow from all
4. Apache 85
,
( z: ). , -
-
, SSI .htaccess .
,
- . -, . , . .
-
, .
Directorylndex :Directorylndex index.htm index.html
, -
- ,
HTML-. , ,, index.php, .. , .htaccess .
CU :ScriptAlias /cgi-bin/ "z:/home/localhost/cgi/"
:
ScriptAlias /cgi/ "z:/home/localhost/cgi/", , . -
, CGI-. Apache , , http: // locaihost/cgi-bin, - z: /home/iocaihost/cgi. CGI- , /cgi-bin/ localhost, . - CGI- / c g i / .
, . CGI-. - , -
, .
( !) :
AddHandler cgi-script .bat .exe .cgi
86 II. . Web- Apache
Apache , exe, bat cgi - CGI-.
:
AddType text/html .shtmlAddHandler server-parsed .shtml .html .htm
Apache - SSI.
.
: Apache Apache, ! , , ApacheWeb Server, Management Start Apache, , - MS-DOS, . Apache. , , -
- h t t p d . c o n f . . , .
1. MS-DOS. , - . command . .
2. DOS::
cd "\Program FilesXApache Group\Apache"apache.exe
3. Apache , httpd.conf, . httpd.conf , , - "Apache/1.3.14 (Win32) running..."
, .
Windows , , .
, -
, . -
Start Apache - ++, Stop Apache ++. ++ , ++. , .
4. Apache 87
html z :/home/localhost/www, HTML- Apache, index.html . - :
http://localhost/index.html
http://localhost/
.
SSI z: /home/iocaihost/www HTML- Apache test.shtml ( - include!):
: 4.1. test.shtml
SSI Test!
88 II. . Web- Apache
:
http://localhost/cgi-bin/test.bat
DOS dir.
,
Windows: , test.bat, Apache - . , ,
,
Windows. test.bat , : - bat-, -, Unix.
- , Apache -, , - , -
ht tpd.conf . - log-, C:\Program FilesXApache Group\Apache\logs.
Apache, Apache , , z:/home/localhost/www z:/home/localhost/cgi CGI. (, , ) , a Apache ., -
, -
Apache. : IP- IP- ( name-based , -). , , - hacker, , locaihost, cracker 1 2 7 . 0 . 0 . 2 .
, "hacker" "cracker" . ,
Web-, "" . ru . com .
Unix, z: /home , ( locaihost). , hacker -
4. Apache 89
z: /home/hacker, (-, cgi www, ), cracker z: /home/cracker. : access. log ; errors, log ; www, , , HTML-; cgi CGI-. . 4.5 , .
_
; pY\hom
'- j home, Cl cracker
- _j hackei--1J cgi'Jj WWW
:- '21 lOCOlhOSl
_U cgi'O www
(jj
. 4.5.
-
Apache httpd.conf (. ), - Windows. , . httpd.conf ( - Edit configuration. , .
:
I 4.3. ; - -
NameVirtualHost 127.0.0.1# localhost
ServerAdmin webmasters localhostServerName localhostDocumentRoot "z:/home/localhost/www"ScriptAlias /cgi/ "z:/home/localhost/cgi/"
90 //. . Web- Apache
ErrorLog z:/home/localhost/error.logCustomLog z:/home/localhost/access.log common
# hacker
ServerAdmin [email protected] hackerDocumentRoot "z:/home/hacker/www"ScriptAlias /cgi/ "z:/home/hacker/cgi/"ErrorLog z:/home/hacker/error.logCustomLog z:/home/hacker/access.log common
# cracker
ServerAdmin [email protected] crackerDocumentRoot "z:/home/cracker/www"ScriptAlias /cgi/ "z:/home/cracker/cgi/"ErrorLog z:/home/cracker/error.logCustomLog z:/home/cracker/access.log common
,
locaihost. , ( , 127.0.0.1) name-based hacker. , , - , , , .
NameVirtuaiHost , IP- ,
, , HTTP 1.1(, , name-based ). (, Directoryindex . .) - .
.htaccess - , , () "" , .
4. Apache 91
, cracker 1 2 7 . 0 . 0 . 2 , a hacker -- name-based ? - hosts, C : \ W I N D O W S Windows 95/98/Milienium C : \ w i N N T \ S Y S T E M 3 2 \ D R i v E R S \ e t c Windows NT Windows 2000.
hosts ( ) hosts . sam, , - , ! Microsoft -. hosts , .
hosts -- , :
127.0.0.1 localhost
localhost 127. . . 1.
) , localhost - . Microsoft!
,
:
! 4.4. hosts
127.0.0.1 localhost hacker127.0.0.2 cracker
, hacker , localhost. , hosts - IP-. , (, ) , . localhost , hacker . Apache 127. . . 1, hacker, - ., :
hacker: hacker; http: //hacker;
92 II. . Web- Apache
z : /home/hacker;
z\ /home/hacker/www, http: / / h a c k e r / ;
CGI z :/home/hacker/cg i , http://hacker/cgi/;
z: /home/hacker.
cracker:
cracker;
ht tp ://cracker h t t p : / / 1 2 7 . 0. 0. 2;
z : / h o m e / c r a c k e r ; z.-/home/cracker/www,
http: //cracker/;
CGI z: /home/cracker/cgi, h t t p : / / c r a c k e r / c g i / ;
z : /home/cracker .
, (, , - ) - http://127.o.o. l http: //localhost. , cgi-bin "" - , .
Apache.
,
, Stop Apache I I Apache Web Server I Management. Apache, -, , httpd.conf, ., Apache , .
5
PHP MySQL 4, ,, Apache. , setup-,
, Apache. , , .
,
http://www.php.net Downloads : - zip, . , Win32 Binaries. 4, , , , ,
.
. , -
-,
.
,
. ,
.
. -
, 4.0.3. , , -
, 4.0.10. , , , , ,
. , 4, "" "" -
.
1. -. Next (. 5.1).
94 II. . Web- Apache
& Welcome
Welcome to 40. Setup program. Thisprogram will install PHP 4.0.3pl1 on your computer.
You may need to stop your web server before installation. [IS BndPWS do not need to be stopped.
Dick Cancel to quit Setup and then stop your wsb server necessary. Click Next to continue with the Setup program.
WARNlNG;This program is protected by copyright iaw andinternational treaties.
Installer version number 1.0.1 -
Cancel
. 5.1. PHP
2. , I Agree. - Standard.
3. , . - : \, , , C:\program Fiies\PHP4, "" Apache (. 5.2). Browse... , -, , Next, - .
S Choose Destination Location
Setup will install PHP 4.0.3pl1 in the following folder
To install into a different folder, click Browse, and select anotherfolder. ; '
You can choosiSetup.
ell PHP (.. by clicking Cancel to exit
Destination FolderC:\Program Files\PHP4
tiext>
. 5.2.
5. PHP MySQL 95
4. SMTP- (Send Mail Transfer Protocol - ), - .
, Mail . , ,
, Outlook Express. ,
Mail .5. , .
Apache (. 5.3). . , ,
.
.
Apache, -, , -
zip-.
JS Server Type
Please select the type'of http seiver you wish to configure to runphp.
Microsoft FWS on Windows 9x
96 _ II. . Web- Apache
2. :#AddType application/x-httpd-php php
3. :AddType application/x-httpd-php php , php application/x-httpd-php.
4. :ScriptAlias /_php/ ": /Program Files/PHP4/"Action application/x-httpd-php "/_php/php.exe" , -, _php , Apache , -, application/x-httpd-php php.exe.
^
"_php" , , .
5. , Apache, ( I I Apache Web Server IManagement I Stop Apache), . Apache - ( ), , - . -
, 4.
, PHP- . z: /home/iocaihost/www test. php :
I 5.1.
echo "It works ! \n";phpinf ( ) ;?>
: ht tp:// iocalhost/tes t .php. - , -
phpinf ( ) .
5. PHP MySQL 97
, PHP- , CGI-. -, CGI- /cgi-bin/ /cgi/, php- .
, ,
httpd.conf. , - Apache.
, Apache, , Stop Apache, .
Apache, .
,
, zip-. , , FTP (File TransferProtocol ) . . , - , . -
, -
. , .
1. zip- , ( c : \ P r o g r a m Fiies\PHP4). , . ,
extensions, .2. , ,
.
php.ini Windows (C:\WINDOWS). . ,
. ,
,-, .
3. magic_quotes_gpc :magic_quotes_gpc=0ff
-
, . -
.
98 II. . Web- Apache
4. :extension_dir=C:\Program Files\PHP4\extensions
,
C:\Program Fiies\pHP4\extensions, . . , . - ,
. /, . . , - . , , .
5. "" , ;extension=. ,
. GD -, php_gd.dll. MySQL .
6. php.ini. , Apache , , .
MySQL : Web-? ? ( - ). : , - MySQL -, ,
" - " .
, MySQL. . , .
1. MySQL(http://www.mysql.com, Downloads) MySQL. - Windows. - zip-, .
2. setup.exe . Next (. 5.4).
3. Next. MySQL. - C:\mysqi , , , .- \Program Fiies\MySQL (. 5.5). Next.
5. PHP MySQL 99
Welcome to the MySQL Setup program, This programwill install MySQL on your computer.. . "..
It is strongly recommended that you exit all Wiridows programs .before running this Setup program. /
. Click Cancel to quit Setup and then close any programs you hoverunning, dick Next to continue with the Setup program.
WARNING: This program is protectedby copyright law and/international treatise. , .
Unauthorized reproduction or distribution of this program, or any portionof it may result in severe civil find criminal penalties, and will beprosecuted to the maximum extent possible under low. . :
Cancel
. 5.4. MySQL
4. Typical. MySQL. . MySQL .
Setup will install MySQUn the following folder.4: : ': .'; : . ' "
100 II. . Web- Apache
\ 5.2. server.bat
Secho off":\Program Files\MySQL\bin\mysqld"start /m "C:\Program FilesXApache Group\Apache\Apache" Windows NT Widows 2000, , ( - MySQL , ):@echo offstart C:\Progra~l\MySQL\bin\mysqld-nt standaloneC:\Progra~l\Apache~l\Apache\Apache -k start
-
, "" ++ ( Apache, ).
6. Apache MySQL. bat- , , shutdown.bat, - z : .
| 5.3. shutdown.bat@echo off"C:\Program Files\Apache Group\Apache\Apache" -k shutdown"C:\Program Files\MySQL\bin\mysqladmin" -u root shutdown
-
++.
MySQL , .
server.bat, . - mysql .php z :\home\localhost\www.
] 5.4. mysql . php
define ("DBName", "test") ;define ("HostName", "localhost") ;define ("UserName", "root") ;
5. PHP MySQL _ 101
define ("Password", "") ;if ( !mysql_connect (HostName, UserName, Password) ){ echo "He " . DBName. " !";
echo mysql_error ( ) ;exit;
}mysql_select_db (DBName) ;
// t. ,// , . .// "@"@mysql_query ("create table t(id int, a text)");
// 10 for($i=0; $i
6
, ,
, , . ( , , ). ? : ", , Perl!". , . Perl, , . . : Perl . -
,
, . : Perl . , ( )., , -
,
Perl... , , -
(, ) , , Perl . , (, ) , -
. -
Perl , ( Perl ), . , PHP- ( ) , Perl (, Perl-, , - mod_perl)., , -
Perl: .
, , 4 ,
106 _ III.
, Perl. - .
?, , 4, -, . , . -
,
, . -
, , -
- , . .,
.
4.
( ^ , "" .
, , - , -
. , , -
. -
,
, . .
.
, 4. - , ( , ) -. -, , , -
,
. - -
. , () -. .
, ,
. ? , . :
,
"" -, .
, , .
3, , - , -
, . . 4 ( ), - -.
, ?
6. 107
Perl, , - -
, . ,
, 4 , Perl.
,
. , ,
-
( , , - ,
, -
). , " ", , . ,
,
( ), - .
, 4 3. , - .
: - - (, - ,
). , : , 3 , -
.
? , , . . . , ,
- -
, . , -
-
.
. , , -
, .
( ^ , .
, "" , - "-
". , compiler - "", "".
, Perl .
108 _ III. PHP
Perl, , , Web, (, , ). , . , , ,
, - ( , - Perl , - ), . , :
for (long i=0; K1000000; ,
:
for ($i=0; $i
6. 109
, -
?" , . , ... .
, -
( ). , -
.
, ,
"", -
.
(, ) -
" "...
-
, , . .
.
, -
.
. -
,
, , .
, , , -
,
. -
,
, . .
( , , for). -.
. , -
, Web . : ,
,
.
, . . , ,
,
,
.
III. PHP
PHP-, "Hello world!". , -
. :
echo "Hello world!
. , -
, .
, -
. , , "
". , PHP- - CGI-, . .
"i".
, , -
. :
Hello world!
,
HTML-? . -, ,
"" .
? , HTML- - ? , . ( 6.1).
! 6.1.
!
6. _ 111
echo " : $dat \";echo " : $tm\n" ;# echo " 5 : \n";for($i=l; $i
112 III. PHP
...
*/
, , , -
.
- "" , -
. , -
, . -
, : , . , : ,
( , ). , . :
$dat=date("d.m " ) ; : $dat (, $, " ") , date ( ) ., , , -,
( , , ), -, ( ). - , , . date ... , , -
. , "11.12 01". , . -
, . ,
else if-eise, .
,
, . $tm "::", - date ( ) . - .
echo, . :
echo " : $dat \";
: , $, - $dat(, , echo). , - ( echo ):echo " : ",$dat," \";
6. _ 113
:
echo " : ".$dat." \";
" . " ( - ). , , -
, , "+", :
$="100";$="200";echo $a+$b; // "300"echo $a.$b; // "100200"
, , ,
.
.
"" :
$path="c: /windows"; Sname="win"; $ext="com";FullPath="$path\$name . $ext" ;
, :
$path=" : /windows"; $name="win"; $ext="com";$FullPath=$path. "\".$name. ". ".$ext;
( ^ Perl , , , , . . .
,
.
, ""
5 . :
for ($i=l; $i
III. PHP
, , -
, . : , ,
.
, ?>, - HTML-, .! (- 6.2):
I 6.2.
! : 29.01 01
: 04:34:16
5 :
l = 1, 1 = 1
2 = 4, 2 = 8
3 = 9, 3 = 27
4 = 16, 4 = 64
5 = 25, 5 = 125
, , -
. - : .
Web ,
. . -
.
, , ""
HTML-. CGI- . ?. . ( HTML), HTML-. HTML- .
6. 115
( - , -) ? . . , -
.
, , -
.
, , " ,
", . ,
, ,
.
, .
, ? , . , - , -
( , HTML-). , , - 6.1, HTML- "" . , , , i ist i . i .php - Web-. Web-- .
^
-
Apache Win32, II. localhost ., ,
Windows- . --, ,
, ( -) Unix - Windows .
. 6.1 -- , , ( :z:/home/localhost/www/list 1.1 .php). URL (http://localhost/listl.l.php). , Web-. php , , -
. -
5 . 699
116 III. PHP
, -
, PHP- - php.
fahttpiWIocalhost/listl .1 .php
^
I \^ http://1ocalhost/list1.1 .php
! : 29.01 01 : 05:32:25 5 : 1 = 1,1 = 1 2 = 4, 2 = 8 3 9, 3 = 27 4 = 16, 4 = 64 5 =25, 5 = 125
^^ ] \ \ lS^ ()
. 6.1. , 6.1
7
, ,
, , , PHP- , HTML. , , , . -
, -
. .
. ...
( , , Forth), , . , , 3 -!
, . , -
-
. -
. , -
, - ,
( - ). : ,$my_variable , SMy_Variable $MY_VARIABLE. , $ - "" , , .
, ( ""
, ...)
,
"" , ,
118 III. PHP
127, , "" ! - - ,
.
, -
, . - , -
( , , , ). , ( ), - --, . -
, 4 -, .
, ,
. . -
(, ), -, .
(, - ) . , .
5 , .
integer , 32 ( 2 147 483 648 2 147 483 647, - ).
double ( ).
string . ,
, . ,
.
, -
""
200300 ( ). ,
.
7. ^ , 119
array (, , , ). , =>( => -). . ,
, , . , -
:
// "", "", "" ""$a=array(0=>"zzzz", "a"=>"aaa", "b"=>"bbb", "c"="ccc");echo $a["b"]; // "bbb"$a["l"]="qq"; // "qq"$["a"]="new_aaa"; // "new_aaa";
, , array , - .
object, -
. -
, ,
->, . , .
.
: fa l se() true (). ( ), true , 0, - false . , (, ) . fa lse true - .
false true . -, fa l se , a true . , :
echo false; // , . . echo true; // 1
( 7.1).
1 20 _ III. PHP
7.1.
$=100;if ($a==100) echo " 1!"if ($a==true) echo " !"
true 1, , ? . , . , (, - ==, >, < . .) - , -
. ( 7.2) , , , , .
! 7.2.
$=100;$b=true;echo " = $a";echo "b = $b";if($a==$b) echo ' "" b ! ' ;
, , "=100 =, - , " />". -, ( - ), , $, , , .
, "" .
, -
, .
: -, ++ 1 ( 7.3):
I 7.3. ++
$b=true;
7. , , _ 121
echo "b: $b";$b++;echo "b: $b";
1, , - 4.03.
( ^ -
. -
: , .
,
.
( -, ), , - ( , - new). , . , -
, , , -
"". ,
, , .
, ( , ) . isSet . :
if (IsSet ($MyVar) )echo " . $MyVar";
( ,
unset ( ) ), isSet ( ) , . ,
(, ,
122 III. PHP
). , ,
.
,
"" .
( ), @, - ( ).
Unset ( ) . , . .
,
. :
// $ $a="Hello there!";// $ // ... - , $echo $a;// $Unset ($) ;// $ echo $a; // : $
, Unset ( ) .
. , $ for_dei, :Unset ($A["for_del"]); for_del , , - .
,
. .
is_integer ($ ) true, $ .
7. , , 123
is_double ( $ a ) true, $ .
i s_s t r ing($a) true, $ .
is_array($a) true, $ .
is_object($) true, $ .
is_boolean($) true, $ .
gettype($a) , , : array, object,integer, double, string, boolean unknown type . ,
( , -, ,
). , . . .
,
(, ). .settype($a,$type)
$ $type ($type , gettype , boolean). (, $ "" , settype($, "integer")), false.
, , , -
. -
, , . -
=:
$ =;
\24 III.
,
( , ==), , -, . -
,
i f (a=b) { ... }
i f ( a = = b ) { ... }( ), . : - :
$=0; $=1;if($a=$b) echo " "; else echo " b ";
"", , "
b ", , , ( , $=$ , $+$, , , 1).
, , ,
( )? = (, ) : =, == =? . , "" ( ==
), . - .
, (, , , ), . : ( ). 4 ( ).
,
. ( , , , , Perl) -. , , -
, .
7. , , 125
, & ().:
$=10;$ = &$; // $ , $$=0; // $=0echo "b=$b, a=$a"; // "=0, =0"
,
( ). :$A=array('a' => 'aaa', 'b' => 'bbb');$b=&$A['b']; // $b , '' $=0; // $['']=0;echo $A['b']/ // , , -
, . :
$=('' => ' ' , 'b' => 'bbb');$b=S$A[ ' ' ] ; // $ , '' echo " '': (" . $[ ' ' ] . ") " ;
, $ , $ - ( echo). , -
, , .
, , -
, SA.
, , -
. , unset , , , ,
.
, , -
. ,
.
, (), , , .
unset , , .
126 III. PHP
. , , -
.
,
. , -
,
$ . :
$=10;$=20;$=30;$=""; // $="" $="" ( $ )echo $$p; // , $, . . $$$=1; /./ $ 100
, , -
, $. , $, -, $. ,
, . , -
, , .
, , Unix, "" "" , -
. . -
.
, - -
. , , -
, , ,
. ""
, , , "20" 10 30 ( "2010") , .
7. , , 127
, $ , . , -
( ) , -, , $ 10. (, , "Array"). , , -
(, , ), - ,
, -
.
. ,
, , -
, . -
FuncName: FuncName ( $paraml [, $param2])
- -. -.
,
, ( - , ). , . , - , -
.
string , , .
int, long , ( ), , . int, - 0. !
double, float , , , -
.
boot , (, false), ( ).
128 III. PHP
( int, -), , .
array, (. ). =>. , list.
list , 0 - . -
, list array. , , " " , ""
. , -
( , , ), , .
object - . .
void, , -
, : " ". -
( ), void- - false ( ).
mixed, . , ,
... , mixed gettypeo settypeo. , mixed, , .
! , - . , , -
. , ...
7. , , 129
,
- , -
. -
, , . .
, .
, , -, -
, -,
$, . :// , PI, 3.146$=2.34*sin(3*PI/8)+5; // echo " PI"; // " PI"echo " ".PI; // " 3.14"
, "" ,
. , , :
.
: ( - ), . .
FILE_
, .
LINE_
, -
. ""
.
PHP_VERSION
.
PHP_OS , .
TRUE true
"".
FALSE false
"".
130 III. PHP
, .
define , . ( ):void define(string $name, string $value, bool $case_sen=true);
, $name, $vaiue. $case_sen true, - , -
( , , ). .
:
define("pi",3.14);define("str","Test s tr ing");echo s i n ( p i / 4 ) ;echo str;
,
. , -
.
, , ( ) . .bool defined(string $name)
true, $name ., , -
. - .
"", .
, , -
. "": ", ". : - , "-" .
7. , , 131
, ,
, . , 5 -
$=5; , . . 5. , $ 5. , $=$;, , $ 5, $ - 5. . , ,
, ? , $=$ - ! (, Perl). , : 5 ( - , ?). , - :
$=($=10); // $=$=10 $ $ 10. , :
$a=3*sin($b=$c+10)+$d; ? , , :
$=$+10;$a=3*sin($c+10)+$d; , (- ) .
,
"" ,
.
,
. :
$=10*20;$="".(10*20);echo "$:",gettype($)," $b:",gettype($b);// "200:integer 200:string"
(, -, $ string, ),
132 III. PHP
. -
, . ,
:
$ = intval($b);$ = (int)$b;, :
$b=intval() $b=(int)() $.
$b=doubleval() $b=(double)() $.
$b=strval() $b=(string)() .
$ b = ( b o o l ) ( ) . , -
$ true, false.-, (array) ( o b j e c t ) , -
.
,
: (, , 0 1). , ? -
"" (, if-eise). , , , . ., -
.
,
.
>, < (), | | ( ), &&( ), \ ( ) . :$ = 10=l&&$b
7. , , 733
-
? , :Sb = $>=1&&$
134 III. PHP
\$ $, , ;
\ " ; \\ ; \ NN. . :
$="!1";echo "$a world!"
Hello world! ,- .. $ $ ( , - ). .
$a="Hell"; // Hello ""echo "$ao world!";
, . : , $ $?, . , , -
, $ . ? :$a="Hell"; // Hello ""echo $a."o world!"; // echo "{$a}o world!"; // echo "${a}o world!"; // !
, .
. { $ } , .
,
.
-
, here- (). . :
$a=
7. , , 135
, , :
, $name .MARKER;
MARKER - , here- . - 2 here-:
136 III. PHP
) , -
, ( -) . , - ( ) . ,
, .
+
-
*
/ % / ( , -), ( , ), . - % , - , , .
.
[] - , ,
, .
=.
, "", -
,
. :
$ = ($ = 4) + 5; $ 9, $ 4.
,
.
7. , , 137
, -
, -
. :
$ = 10;$ += 4; // $ 4$s = "Hello";$s .= " world!"; // $s "Hello world!" .
, .
$+=1 $-=1 - , , . :
$++ $ 1; $ $ 1. ,
, $ -. :
$=10;$=$++;echo "a=$a, b=$b"; // =11, =10
, $ $, . , ,
$, , $ . ,
, . , -
. :
$=10;$=$;echo "=$, =$"; // =9, =9
.
, for.
(//) . ,
,
138 III. PHP
. , 12 1100, 2 10, 12|2 14 (1110 - ). , , .
& -- , , - , .
| - - , , - , ( ).
~ - , , .
,
.
, .
,
: fa l se true. ,
, true, false. == , .
!= , . < , .
> .
= .
, ( ) . . ( ==), . -
- , -
== , ,
Array, .
4 - ===, . -
, ,
7. , , 139
, . , ,
:
$=10;$="10";if($a==$b) echo " b "; , $ , $ -. , , -
, . , -
"".
$=0; // $=""; // if($a==$b) echo " b ";
$ $ , - , . ? , -
, . -
0, . , - echo . === ( ). , . -
:
$=0; // $=""; // if($a===$b) echo " b ";
. -
"" .
, . .
. :
$=(''=>'');$b=array('b'=>'bbb');if ($a==$b) echo " == a=b";if ($a=$b) echo " === a=b";
, ,
. , , , -
- Array, -. === , .
, === ! == ( !). , , .
140 III. PHP
-
false true. ] , , . && , , . a i i , , , . , , -
, , , -
(, fa i se&&4To false), -, . ,
$logic = 0 & & ( t i m e ( ) > 1 0 0 ) ; time . -
. , , , | | | ,
, false true.
.
, PHP- , -
, .
.
, ?
) , , -
, .
, Perl, , , - "500- ", Perl -. : - 500- , .
, -
" ". , -
, , -
7. , , _ 141
( , ). , no-, . . - . , ,
"" .
. . ,
. , ,
( 7.4):
I 7.4.
142 III. PHP
if(@$doGo) echo " !";
, 7.5 7.4 - @ i f .
(~ )
, @. , -, . , ,
, .
8
, : - -
. -
. -, Web- ( -) , - . ., .
, , ,
, . ,
,
HTTP , POST- . .
-
HTTP, . , , -
, ,
, .
: , "Hello world, 10 -".
.
,
: ", ! , !".
URL ? , =&= ( ). ,
144 III. PHP
. ?, &, %... , HTML, , , -.
,
heiio.php. 2 : name age. HTML-:
, name! , age !
, name age . - ,
http://www.somehost.com/script.cgi?name=Vasya&age=20 .
, .
, . ,
, -
URL ? ,
QUERY_STRING, $QUERY_STRING. - , ( 8.1).
! 8.1.
( test.php ) -:
http://www.myhost.com/test.php?aaa+bbb+ccc+ddd :
: aaa+bbb-t-ccc+ddd
, URL- : $QUERY_STRING, , , . -
.
8. 145
Web--,
$QUERY_STRING , . , ( - , +, ) - $argv, - . ,
, ,
.
$argv ,
, .
( ) , .
. ,
? , - Windows, . , HTML- (, form.html ) . ,
, -
, , ,
( 8.2).
! 8.2. form.html: ! . -:
: :
. ,
, ,
hello.php ? -, - & . , action
146 III. PHP
, . . hei io.php , form.html. , ,
URL- , . -, %, - , .
, , . .
, .
| 8.3. hello .php -
, $name $ . ,
"" ( ), . -, , ,
.
,
QUERY_STRING, . - . -
, GET POST "". , ,
(, REQUEST_METHOD), QUERY_STRING, - . , -
, CGI-. , -
. name -
8. 147
$name, - age -- $. , "" -- URL-. - , , ? , -, , , -
.
hello.php ( 8.4). , :
I 8.4. hello.php:
,
, -
. , -
, -
, . -
, , , ,
. i f , -, , , ( 8.5).
I 8.5. hello.php:
< ? i f ( ! @ $ d o G o ) {?>
148 III. PHP
, , HTML-.
~ ^
, : -?
8. 149
| 8.6. IP- :- - j
IP-:
ENVIRONMENT-GET-POST-COOKIE, . , -
=, , GET- =20 Cookie =. $ 30, Cookie GET, a GET . , - VAR ( - , -
, ), : , :
http://www.somehost./.?\*=___ VAR ? -,
getenvo, , .
.
,
. ,