Вы находитесь на странице: 1из 241

.

PHP:

scanned and converted to PDF including Bookmarks


byHupBaH9I

2004

004.92
32.973.26-018.2
96

96

.
: /. . .:
, 2004. 237 .
ISBN 985-475-050-7.

Web-. ,
,
, , ,
, -.
, .
,
.
,
, .
004.92
32.973.26-018.2

ISBN 985-475-050-7

,, 2004
. , 2004

I
.

II
\/-

14

15

. . 16

Web-

21

31

III
PHP

36

. .36

39

41

Apache

42

.44

. . . .
:

.44
50

51

54

54

HTTP- .

54

54

54

HTTP-cookie

55

55

.55

56

56

.
.

,
.

.-.

...

59

. . . .

62

63

68

71

'

74

78

IV

80

80

83

. . .

88

89

91

H T M L -

94

96

. . .

...

99

103

104

107

, ,

114

115

115

. . . .

117

119

121

125

130

134

134

144

165

170

170
'

177

190

194

: ?

194

195

195

197

198

199

205

1. HTML CSS

205

2.

206

3.

208

4. Cookie.

233

5. POST GET . . 235


6. Unix

236

.
, Internet Explorer , . ,
, ,
. HTML
(. 1)
(, ), ..
HTML-. Internet Explorer, Microsoft
.
(
, ), - .
, , . , - .
( ) , -
. ,
,

,
.
, , , ,

. , , -
(, ..). , , .
, . . , ,
. ,
, .
,
.
, . , ,
,
, .
, ? inter net
( ). ,
- ,
. .
, . ? , , ,
(, ),
.
- ,
,
.

: , , GPRS .. , . , ,
. ,
, ,
,
. , ,
.
. , 1969 .
.

. ,
.
.
.
,
. , 10 %
( 580 ) .
, , 2005 1
.
,
, . 70 % . ,
, .
, , . -

10

, , ..
, , .
. , ,
. , , WWW (World Wide Web,
). 1992 -
(CERN), (). 1993 WWW 200 Web-,
1995 6,5 .
36 Web-, .

, .

.
,
, ,
.
HTML (HyperText Markup Language).
, ,
( , , ,
..), . HTML 1.
URL
(Uniform Resource Locator, ). ,
. URL ,
, ,
.
URL :

1 1

. h t t p : / /
, .
h t t p : // HTTP (. ).
www.wnk.biz .
,
: com
, edu , gov
, mil , net , org . , ,
, . ,
by , , , pi ..
.
.
, . , : info ,
biz - ..
s o m e d i r e c t o r y
( somedirectory) , .
index html.
, , , , , .
, 192.128.45.194.
IP- , ,
IP- .
-, . : , , , ,
.. , , . , , .

12

. , .
? .
. -, . ,
,

. -, . , , , .
.
.
. -, ( , ).
, , . ,
.
2000 . - , ,
. . , , ,
- - -. ,
.
, - , .
? , . ,
486, ,
. -

13

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

II


Web-

, , .
, , ,
. ,
, , -.
, .
, , , ,
? , ,
.
, . ,
, ,
( )
-, ,
.., .
, , .
. ,
, ,
. , , !
( ) , .
, , , .
. , .

, ...

15

, , . , .
, . , . , ?
...

, ...
, , , , . ?
. ,
. , - ,
- , !
. , ,
(, ,
..), , !
, , . , .
, , , .. . ,
. , ,
. , , , Pentium-I
Windows 98. ? ,
. , ,
.
. -
, -
- .

16

Web-

, , , .
, . ,
Pentium-I .
Windows XP NTFS. : , (
- , ). .
,
,
.
. , Windows 98 , . , , , CD-RW , , .
, ? , . .
- . CD-RW flash-.
CD, (,
) USB flash-. : flash-.


!
(
1988 , ,

, - , ?), ,
? , -

17

, .
,
, . ,
. ( 1980- ) , . , -
. ,
- .
, , ,
. . ,
, ?
, ... . , , .

, , . ? , , .
, , . : ? ,
, , .
, . , , .
( )
. , , 220 ,
, .

18

Web-

, ,
. , .
-, . , - ,
. 70 , ,

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

( , ). , , , .

,
.
.
, . , . , .
, .

1_9_

, , .
, . , , .
( ) , , .. (). ,
, . ( ) , .
,
.
: , (
) . ,
:-) ,
.
, . , ,
.
. , . ,
17- ,
19-. , :

.
85 , 100 . ,
1024 768,
100 .
100 ! , 100
, , , , . .
. ,
.

20

Web-


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

. . , ,
. -

Web-

21

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

Web-
Web- . , ,
. Internet Explorer. ,

. ,
, 90 %. , -, , , Netscape Navigator
Opera.
, , .

22

Web-

. , , .
, . ,
, . , -.
. , - .
, .
Internet Explorer, , . , , .
FTP-.
, ,
.
CuteHTML CuteFTP (. 1), , , (
).
CuteFTP FTP-,
Windows Commander, (. 2).
.
.
, ,

. ? ,
, , . .
.

Web-

24

..
, , .

,
subst.exe ( Windows}. . ,
C:\internef\, , . : subst
: C:\internet. , C:\internet\, .. , . , , internet, . ,
. , , . substE: /d. , , C:\internet\, .

, , usr.
.
. , , ?
(.. ) -.
: . , ,
,

. ,
.

( ), , .
, , . ,

26

Web-

,
, - .

. . , -, , Windows,
Unix FreeBSD. Apache ,
, .
, . Windows - .
h t t p : / / a p a c h e . o r g
PGP3' ,
. . , Windows (. 4).
? .
, .
(. 5).
Next .
, , ,
.
Next ,
(. 6).
-. . usr:
E:/usr/apache/.
i - , . {. .)
" PGP (Pretty Good Privacy, )
,
,
, .
{. .)

32

Web-

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

33

. ,
, .
? ,
, .
, log-.
, . log- , , , FTP.
, .
100 , .
, , , .

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

34

Web- \

, , .
, . , ,
.

, .. .
, , FTP- .. ,
.
, , . , ,
, , .
, , , .
, .
, ,
, .
, -, , , , -.
, .
, . ,
, -
. . , - , .

. ,
- ,
,

35

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

37

CGI- ,
Perl, .
( , CGI-)
.
CGI-, , . , ,
. C/C++, Fortran, Perl, TCL, Unix Schell, Visual Basic,
Apple Script . PHP
Perl, .
, CGI- ( ), ,
, .
,
, . , - ,
, 1995 , Personal Home Page Tools (
).
.
, ,
,
, , , ..
1995 ,
.
. , , " .
,

CGI (Common Gateway Interface, ) ,
. (. .)
I 5.0 beta 4. (. .)

38

, HTML-.

. , , .
PHP-, ,
, , JavaScript, (, , PHP-). . CGI-, Perl.
CGI, PHP-
HTML-,
CGI. , - . , , ,
Basic Yamaha.
, . ,
CGI-, ( ,
) . ',
, .
. ,
-
4.1 . ,
. , , ( ,
), . , , , . (. .)

. 2000 2,5 .


.
http://www.php.net
downloads
(. 12).

. 12. www.php.net

, Windows Binaries (. 13).


, , -. , ,

, .

. 13. CmpaHuu,acaumawww.php.netdAHCKa4ueaHUH

, , . , , zip.
- (. 14).
Next, Standard.
. ,
usr. e:\usr\php\ . SMTP-
. -. , -

. -

( , .

. 14.

, .
, Apache. - ,
.

Apache -.
Apache
Apache httpd.conf
E:/usr/apache/conf ,
Word.

42

, , #.
. , ,
Apache.
:
#AddType a p p l i c a t i o n / x - h t t p d - p h p

.php

( # ). , .
php.
:
ScriptAlias

/_php/

" /"

Action a p p l i c a t i o n / x - h t t p d - p h p

" / php/php.exe"

e:/usr/php/. He
, .
(php.exe) -
.
Apache. , , . .
.

Apache
, ,

. -
,
, . ,
.
httpd.conf
:
<VirtualHost 127.. . . 1>
ServerAdmin admin@servername . com

PHP
ServerName

43
www.servemame.com

Directorylndex index.php3 index.phtml index.php


index.htm index, html index.shtml index.shtm
DocumentRoot
ScriptAlias
cgi-bin/"

"e:/usr/public_html/host/virtual"

/cgi-bin/

"e:/usr/public_html/host/virtual/

ErrorLog e : /usr/public_html/host/virtual/logs/error.
CustomLog
common

log

e:/usr/public_html/liost/virtual/logs/access.log

</VirtualHost>
VirtualHost
ServerAdmin
ServerName

127.0.0.2>
admin@my-site.com
www.my-site.com

Directorylndex index.php3 index.phtml index.php index.htm


index.html index.shtml index.shtm
DocumentRoot " e : / u s r / p u b l i c _ h t m l / h o s t / s t a r t "
ScriptAlias
cgi-bin/"
ErrorLog
CustomLog
common

/cgi-bin/

"e :/usr/public_html/host/virtual/

e:/usr/public_html/host/virtual/logs/error.log
e:/usr/public_html/host/virtual/logs/access.log

</VirtualHost>
, .
. VirtualHost
IP-, . . DocumentRoot , .

44

virtual LOG
log- Apache. ,
Apache .

log-, . , . , . Log-
, , , .
, Apache. .

, PHP- . d:/usr/public_html/host/virtual test.php :
<? p h p i n f o ( ) ; ?>
: h t t p : / / 1 2 7 . 0 . 0 . I / t e s t . p h p .

, phpinfo () (. 15).
, .

, . zip . . extensions .
,
, ..
,
, .

. 15. ,
phpinfoQ

.
php.ini.
, . , , .
, php.ini-recommended php.ini. , ,
, , Apache, .
? Error handling
(.16).

and logging

, .
, , . .

. 16. Error handling and logging php.ini

e r r o r _ r e p o r t i n g = E_ALL
, , , . , (. ). ,
, , ,
. , :
e r r o r _ r e p o r t i n g = EJV^RMNG. . 1

: .
1.1

ERROR

E_WAKNTNG

( )

ARSE

EJNOTICE

16

CORE ERROR

32

ECOREWARNING

( )

64

ECOMPILEERROR

128

ECOMPILEWARNING

( )

256

EUSERERROR

512

E_USER_WARNTNG

1024

E_USER_NOTICE

2047

EALL


( , )

d i s p l a y e r r o r s = Off
On, , , , log-.
.

Data Handling r e g i s t e r g l o b a l s =
Off On (. 17).
'
, .

. 17.

,
. e x t e n s i o n d i r .
, , . ,
, , . , TEMP , .
{. .)

49

,
.

php.ini
, Windows ( ,
). .
.
,
.
, .
.
, , : name.phtml?a=l&b=2,
$ $.
. , , 4.1, ,
,

. , , - .
r e g i s t e r _ g l o b a l s
php.ini. r e g i s t e r g l o b a l s = On,
. r e g i s t e r _ g l o b a l s = Off, , ,
.
. .


, , .
.
, ,

. .
,
php.ini, ( , ,
), hosts, E:\WINDOWS\system32\drivers\etc
(. 18). Windows,
. Windows, , .

. 18. hosts

hosts :

PHP

51

127.0.0.1 localhost
127.0.0.6 204040
127 . 0 . 0 . 2 v i r t u a l
127 . 0 . 0 . 3 p r i c e
127.0.0.4 s t a r t
127.0.0.5 t e s t
, ,
.
. , , .
, ,
. - , ,
httpd.conf, e:/usr/apache/conf.
, , Word, (. 19),
.
php.ini,
.
,
, ,
, DOS- Apache, ,
.
, , .


, . Perl. , ,
. ,

.19.1./
PHP
. . , .

.
2.
, ( CGI, log, , , ) ,
.
, .

53

, PHP-, phtml, php3, php. , ,


phtml.
<?php ?>.
, /*, */ ,
//
. , ,
.

. \/11_
,
, , .
. ,
, . :
<? p h p i n f o ( ) ;

?>

phtml , 127.0.0.1/
.phtml. ? ?
Phpinfo .
, .. . FTP.
3 .

54

PHP

Web-,
, .

: Oracle, Adabas D, Sybase, FilePro, mSQL, Velocis, MySQL,
Informix, Solid, dBase, ODBC, Unix dbm, PostgreSQL. .
, ,
. , , ,

, .
.
HTTP-
, , Apache.

, ,
.

.

HTML-, G I F , JPEG PNG.
GD.

.
, , , , -

PHP

55

.. , ,
, .
HTTP-cookie
Cookie (
4 ) , ,
(. 4). cookie, setcookie(). Cookie HTTP-,
setcookie {) ,
- ,
. cookie, , -.

. , . , .

, .

( ,
, )
, , .
, , ,

.
.

56


. , . .
.
, ,
, - , ,

, , .
.
,
,
(
, ) .


.
:
<?php
echo ",

!";

:
<?php. <?, .
,
? , .

57

HTML-, ,
, !.
PHP echo,
.
, .
, .
,
(, ). $,
. , , . , _ ( )
.

(.. ECHO
, echo),
(.. $os $OS ).
,
, , , .
, Pascal
Visual Basic, . , , .

, . ,

PHP

58


.
, .
, (
). ,
, . : @,
. : @$name; if (@$name) .. php.ini
(. ).

. , $ = 5. , $, , 5. :
1 < ?php
2 $name = 6;
3 $hl2 = 4.89;
4

$file_type =

"path/index.phtml";

5 $os = "PHP !";


6 ?>

$name 6, .
$hl2
4.89, .

. , ( ) , .

59


,
.
,
. :
<?php
$ = 5;
$ = 3;
$ = 4;
$d = $ + $ - $;
echo $d;

4,
, , ,
.
.
. , $++; $
.

: $ = $ = 4; $ $ . :
<?php
$b = $a = 5; /* $ $ */

- PHP

60

$ = $++; /* , $
$ {5) , $
*/
$ = $d = + + $b; /* , $d $ $,
, .. $d $ 6 */
$f = 2 * ($d++) ; /* $f $d , ..
2 * = 12, $d */
$ - 2 * (+ + $) ; /* $ $ , ..
2 * 7 = 14 */
$h = $g += 10; /* $
10, 24,
$h */

,
. : .
1, 2 , 3 , 4 , 5, .. ,
. :
<?php
$i = 1; //

$i 1

echo $ i ; // $i
$i++;

//

echo " " . $ i ; // ,


//

$i + + ;
echo " " . $ i ;

61

echo " " . $ i ;


$i++;
echo " " . $ i ;

?>

, , , .

$i+ + ,
$i = $+ + 1;. , ,
.
( ) 1 2 3 4 5.
,
,
HTML- <>. echo " < b >". $ i;.
.
:
;
$i 1;
$i ;
$i ;
$i ;
, ;
.
, . ,
.
, HTML-:
!
HTML-.
1 (. ),
.

PHP

62


: .
:
if ( )

{ } else { }

,
. ( , ) :
() if () () { ,
} () else { ,
}
, , .
, .
, .

. . , , .

. ,
.

-
(, ), , .
, ,
.

63

,
. .
:
<?php
$ = 5;
$ = 9;
if

( $ == $ ) { echo $b - $;

} e l s e { echo $b . $a;

}'

?>


, .

, .
,
!
-.
95, $
$, echo $b.$a; (
, , ) . ,
.
! =,
,
( or, and, >, <= ..).


. while, do...while, for foreach.

PHP

64

, - .
. :
;
;
;
, ;
( );
.
.
, :
<?php
$i = 0;
$n = 10;
while

($i <= $n) :

echo $ i . " < b r > \ n " ;

endwhile;

. $i , , $ . while (),
, . , $i <= $n.

65

, . ( ).
, $i, , ( ), , , ( ).
endwhile .
, ,
10. , echo $i
HTML- <>.
, .
<?php
$i=

0;

while ($i <= 10)

echo $i++."<br>\n";

, ,
.
, .
, PHP do...while. , while
, ,
, ,, . , do...while
, while ( -

66

PHP

while, ,
). do...while
:
<?php
$i = 0;
do

echo $i."<br>\n";

while

($i <= 10 ) ;

?>
for. :
for (exprl; expr2; ) {
}

(exprl) .
2. ( t r u e ) ,
() (). ( false), . .
. 2 , ( , ). ,
, , break , for.
break, , . :

67

$ = 0;
while ($a < 5) {
if

($arr[$a] == "stop")

break;

/ * ,
$[] stop * /

$++;
}

continue,
. :
while
if

(list($key,$value)

= each($arr))

($key 2)

continue;
}


for:
/* 1 */
for

($i = 1; $i <= 10; $i++)

{ print $i; }
/* 2 */
for

($i = l;;$i+ + )

{ if {$i > 10) { break;

} print $ i ; }

/* 3 */
$i = 1; for ( ; ; )
{ if ($i > 10) { break;

} print $ i ; $i+ + ; }

PHP

68
/*
for

4 * /
($i = 1; $i <= 10; print $i,

$i++)

- PHP .


date. : $date = date ("") ;
,
. :
"am"1 "";
A "AM" "";
d , , ( ), .. 01 31;
D , , , " F r i " ;
F , , , "January";
h , , 12- , ;
, , 24- , ;
i , , , ., "00" "59";
j , , ;
1 ( L) , , ,
"Friday";
L , , .. "0" " 1 " ;
m , , .. "01 " "12";
, , , "Jan";
, .. " 1" "12";
. AM (Ante Meridiem) , (Post Meridiem) . (. .)

69

, , " + 0200";
s , , , .. "" "59";
s , , ,
" t h " , "nd";
t , .. "28" " 3 1 " ;
U Unix, .. 1 1970 ;
Y , , ;
w , , "" ;
Y , , "1999";
, , , "99";
z , , "299".


, d D.
. . ,
JavaScript,
( ,
, ).
, , ,
Windows,
, ( ) . , :
<?php
Sh = d a t e ( " H " ) ;
if (Sh >= 5 && Sh <= 11)

echo "

!";

, second (), seventh (). (..)

70

PHP

if ($h >= 12 && $h <= 18) echo "! " ;


if ($h >= 19 && $h <= 24) echo " ! " ;
if ($h >= 1 && $h <= 4) echo " ! " ;
?>
,
:-)

d a t e ( " H " ) ,
, , ,
.
,
,
. ,
, , .
, , , ,
. . :
$time = d a t e ( " H : i " ) ;
$timel = d a t e ( " H " ) ;
$time2 = d a t e ( " i " ) ;
$time_s = 7;
$timel = $timel + $time_s;
if

($timel >= 24)

{ $timel = $timel - 24;

$time = " $ t i m e l : $ t i m e 2 " ;


, ,

. $time_s
.

71

, ,
, . . . ,
, .
, , , , , .
, , , , , , 3423.
, , . , $[ 0],
$[ 1], $[ 2]
.. $ [ 8].
: 9,
8. ,
, .
, : $
[]. , . , ,
. ,
, ,
.
:
<?php
[] = 1;
[]

= 67456;

[]

=0 "";

$ 0,
1 2 1, 67456 . echo $ [ 2 ] ; .

72

.

,
(, , , , ,
), .
,
$ [ ] , $ [ 0 ] , $[1], $[2] ..
.
. . ,
, , , , .

. :
$[

0 ] ;

$[

0 ] ;

$[

0 ] ;

,
: , ,
, , ..
, .
,
.
. :
<php
$ = file (" ");

$
, , .


. , " h t t p : //...", , . .
. (, )
SafeMode, , .
, ?
.
, .
.
end (), next (), prev () reset () . .
end ()
, next ()
(.. )
false, . , false
.
prev ()
(.. ) false, . ,
false.
reset <)
.
c u r r e n t {) ,
. .
, c u r r e n t () false.
(0 ),
false .
sort () ,
, , .

PHP

74

r s o r t ( )
).

, , . .

.


, (
). .
. .
, , , .
,
. , , ( ). . :
<?php
$str = ",";
$sto = "";
$qwe = " ! " ;
$mir = $str.
echo

" ".$sto;

$mir.$qwe;


, , .
, . , -

75

.
, , , , ,

.
, ,
, ,
, , .

, ( ) .
, , . : chop (str) ;
:
$str = c h o p ( $ s t r ) ;
$str .
,
, trim (str) ; :
$ s t r = trim ( $ s t r ) ;
,
ltrim ().
.
u c f i r s t () , , .

ucwords ( s t r ) ; , . . ,
. ,

. s t r t o l o w e r (str) ; (

76

PHP

) s t r t o u p p e r (str) ; ( ). , .


.

.
. .
, -
. ,
? , . , , HTML-
:
<input maxlength= " 10 0 " name=" f orm">
form 100. . ,
,
, .
.
(
), 100 ,
HTML .
, (
),
.
, ,
.
PHP- substring
(string, s t a r t , l e n g t h ) . :

77

$form = substr($form,0,99);

, 100 ( 99,
). ,
.
, substr . string, start () length ().
start , , start string.
:
$form = substr("abcdef",

1); // "bcdef"

$form = substr("abcdef",

1, 3); // "bed"

start ,
, start
string. :
$rest = substr ("abcdef",

-1); / / "

$rest = substr ("abcdef,

-2); / / "ef

$rest = substr("abcdef",

-3, 1); / / "d"

length , length
start. (
),
start.
length ,
length string.
, start. :
$rest = substr("abcdef", - I , -1) ; // "bede"
.

PHP

78

,
, . s t r r e p l a c e ( n e e d l e , s t r ,
h a y s t a c k ) ;, n e e d l e , haystack, s t r :
$str

= str_replace("",

//
$str

"\n",

$str);

= str_replace("red"

"black",

$str);

/ /
. ,
.
- ,
e r e g r e p l a c e {),
. , , ,
.

, PHP 4.O.
, POST GET.
SID.
, . cookie . SID
, .. ,
. tmp ,
( cookie).

79

cookie , SID ,
GET POST, .
. , .
3.

IV


: ,
. :
1 <?php

2 $w = " 4 " ; //
3 $ = " 6"; //
4 if ( $w == $e )
5 {
6 echo $w + $; // ,
7 exi t;
8 }
9 if ( $w > $ ) { echo $w; } else { echo $e; }
10 //
11
12

exit;
?>

. ( 23). , ( 4). if. ,


, $w
$. , .


. , ,
, .
, .
, ,
echo ( 6), , exit. ,
,
11, . , .
, (
, ) , , ( 9). ,
, ,
.
, $w > $e, $w, .
, ,
$w <= $, else {
echo $e; }. ( 4), , $w < $e.
exit 7, ,
, , $.
, .
,
,
, switch. ,
:

82

PHP

function date_format($date)
// $date
{
$year = s u b s t r ( $ d a t e ,

0,

4) ;

/ / $
/ / $date
$month = s u b s t r ( $ d a t e ,
//

2};

$month

$day = substr ($date,


switch
//

4,

6,

2};

($month)

switch($month)

/ / $month
/ / case

xx:

case 01: $month

= "";

break;

case 02 : $month = ""; break;


case 03:

$month - ""; break;

case 04:

$month = "";

case 05:

$month = ""; break;

case 06:

$month = ""; break;

case 07:

$month = ""; break;

case 08: $month = "";

break;

break;

case 09:

$month = ""; break;

case 10:

$month = ""; break;

case 11:

$month = ""; break;

83

case 12: $month = ""; break;

$date = "$day $month $year .";


echo $date;

$date = date("Ymd");
// date()
dateformat ($date) ;
// dateformat ()
?>
.


, ,
. ,
, .
, (,
) ;
.
,
. :
require () include (). . :
include ("text.phtml"). , require () ( [
, a include ()

84

, ,
. <?php ... ?>.
.
, ,
. include (),

.
, include ().
require () . , . ,
require () . require () , include ().

, . ,
h t t p : //, .
, &, ?, %.
PHP-. , : ?=,
,
.
, http://name.com/index.phtml?lex=7 index.phtml. ,

$1 7. . GET.
, , POST (CM. 5).
,
&. , -

85

.
.
: http://HMfl/
index.phtml?link = l
, index.phtml.
:
<html>
... ...
<?php
$url = " " ;
if

(Slink == 1

{ $url = "name1.phtml'

if

($link == 2}

{ $ u r l = "name2.phtml

if

($link = = 3 ) { $ u r l = " . p h t m l

if

($link == 4) { $ u r l =

name4.phtml"

if

($url == "")

error.phtml"

include

{ $url =

($url) ;

... ...
</html>
, if ($url
= = "") { $url = " e r r o r . p h t m l " ; } , .
error.phtml. - ,
index.phtml .
, , . -
, .

86

PHP

,
.
, :
<html>
... ...
<?php
i n c l u d e ("name" . $link.

".phtml");

?>
... ...
</html>
, ,
name.phtml.
. ,
.
.
.
: 1 : / / /
index.phtml?patch/name.phtml. patch/
name .phtml ,
SQUERYSTRING. :
Sadd = SQUERY_STRTNG
index.phtml , . ( ),
$add ,
,
http://www.my_site.com/page_l/info.html. , page_l/info.html.
{..)

87

. main.phtml.
:
<html>
... ...
<?php
$add = $QUERY_STRING;
if

($add = = "")

include

$add = "main.phtml";

($url);

?>
... ...
</html>

. if ($add == "") {
$add = "main.phtml"; } ( ) : if (!$add) {
$add = "main.phtml"; } . , . , ,
.
, ,
,
.
, .
.
, ,
- , .
, ,
.

88


,
. , ,
.
( , ) :
1 <>
2 <?php
3 $filename = "counter.dat";
4 $fp = @fopen($filename,"r"};
5 if ($fp)
6{
7 $counter = fgets ($fp,10) ;
8 fclose($fp);
9 } else

{ $counter = 0; }

10 $counter++;
11 echo $counter;
12 $fp = @fopen($filename,"w");
13 if

{$fp}

14 {
15 $counter = fputs{$fp,$counter};
16

fclose($fp);

17 }
18 ?></p>

, , counter.dat, , .

89

.
1. HTML- <>.
2. .
3. , .
4. , .
56. , .
7. , 10 $counter.
8. .
9. , .
10. .
11. .
12. .
1315. , .
16.


, . ? . ,
.

, :

<form method="POST" a c t i o n = " a c t i o n . p h t m l " >


<p><input type = "text" name="emaii" size="20">
<br><input type = "text" name="name" size="20">
<br><textarea rows="2" name="txt"

cols="20"x/textarea>

<br><input type="submit" 1="" name="Bl">


<input type="reset" value'" name="B2"</p></form>
HTML- ,
(. 20).

. 20.

, , action.phtm.
email, ,
. name,
, . , , ,
. ,
txt. .
, ,
,

91

.
, , , action.phtm. PHP- :
<?php mail{$email,

$name,

$txt);

?>

, , , ,
. , .
$email, $name, $txt.
, ,
. ,
,
POST. ,
GET.
. (GET) , (POST) .


, . , , , , .
,
, ,
, , , , .. , mail.
:
mail ( $ e m a i l , " ", $ s t r ,
" ) ;

"From: -

92

, , (
). $str , $email. ,
.

,
, .. , .
:
<?php
$host = gethostbyaddr($REMOTE_ADDR) ;
$ip = getenv("REMOTE_ADDR") ;
Sdate = d a t e ( " d MY,

H:i:s " );

$ s t r = ("
$date
$host
IP- - $ip
mail ( $email, "", $str,

"" );

,
IP, SREMOTEADDR. IP
. , $email.

93

, , .
-,
( , IP-)
.
(, ):
$filename
$
if

=
(

"data.txt";

@fopen($filename,"r");
!$fp

mail( $email,
$ filename!") ;

"!",

"

, @,
,
. , :
if

(@mail(

$email,

{ ... ,

"",

$str))

... }

else
{ ... , ( , ,
..) . . . }
$ email , , , ,
.

PHP

94

HTML-
HTML-
, , ,
.
, . , , HTML.
, , . :
$header="Content-Type: text/html;

charset=windows-1251\n";

( " , ","
","
<> HTML-. </>
<> <>
<hr>
<tablextrxtd>BoT, </td>

<1<1><<1><><1>
<hr>
",$header);
, $header
Content-Type: t e x t / h t m l ;
HTML-. ,
. , , .

HTML-

95

,
:
$to

= ", ";

$subject = " ";


$text = " ";
$from = " ";
$kodir = " ";

//

$kodir = "windows-1251";

//

$kodir = "koi8-r";

$header = "From: $from\nReply-To:


$header

.= "MIME-Version:

$from\n";

1.0\n";

$lieader .= "Content-Type: text/plain; charset=$kodir\n";

$header

.= "Content-Transfer-Encoding:

$header

.= " $ t e x t \ n " ;

mail($to,

$subject,

$text,

8bit\n\n";

$header);

,
. ?
. , .
, HTML-. .

96

-
.
:
<?php
//
$q[ ]
$q[ ]
$q[ ]
$q[ ]
$q[ ]
$q[ ]
$q[ ]
$q[ ]
$q[ ]

=
=
=
=
=
=
=
=
=

"";
"";
"";
"";
"";
"";
"";
"";

$q[ ] = "";
$q[ ] = "";
$q[ ] = "";
$q[
//

= "";

$e[ 0] = "
$e[ 1] = " " ;
$e[ 2] = "";
:
$e[ 3] = "";

$e[4] =
$e[ 5] =
$e[ 6] =

"";
"";
"";

//
$m = d a t ( " m " ) ;

if
if
if
if
if
if

($m ==

"01") $ = 1;

($m == "02") $ = 2 ;
($m = = "03") $ = 3 ;
($m

== "04") $ = 4;

($m == "05") $ = 5;
($m = = "06") $ = 6;

-
if
if
if

97_

($m == "07") $m = 7;
($m =
"08") $m = 8;
($m =
"09") $m = 9;

/ /
$we = d a t e ( " w " ) ;

/ /
$chislo = d a t e ( " d " ) ;
/ / $
$den_nedeli = $ [$we];
/ /
/ / $q
$mesyac = $q[$m];

echo " " . $ c h i s l o . "

".$mesyac",

" . $den_nedeli;

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

, , , , . , .
.
.

98

PHP

, , . . ,
, .
. , , .
, .
10,
(.. 02), .
, ,
. . ,
,
( ),
.
.
, ,
. $ . ,
,
.
, .
, , .
.
, .
.

99



,
.
.
, URL. . ,
urlflle.txt.
.
, .
counter.txt.
urlfile.txt counter.txt
, ,
.
log.phtml,
index.phtml. ( count), .
, .
log.phtml :

if(SQUERY_STRING ! = "")
{ Surl = $PHP_SELF.'?'.$QUERY_STRING; }
else { Surl

= $PHP_SELF; }

,
$PHP_SELF.
, ,

PHP

100


$QUERY_STRING. ,
SQUERYSTRING ,
$PHP_SELF, , .
:
$add= $DOCUMENTROOT. " / c o u n t / u r l f i l e . t x t " ;
$adds = $DOCUMENTROOT. " / c o u n t / c o u n t e r . t x t " ;
$li

file($add);

$a = c o u n t ( $ l i ) ;

, .
SDOCUMENT ROOT , , , .
$li . , , , .
:
$ i = 0 ; $W = - 1 ;
while

{ $ i <= $ a ) :

$tmp = t r i m ( s t r _ r e p l a c e
if

($tmp == $ u r l )

("\n","",

$li[$i]));

{ $w = $ i ; $ i = $ a + + ;

endwhile;

. , , . :


if

101

($w == -1)

{
$fp

= fopen{$add,

if

($fp)

"a+");

$fw = f w r i t e ( $ f p ,

$url."\n");

fclose($fp);

}
$fp

= fopen($adds,

if

($fp)

$w

= $a++;

"a+");

{ $fw = f w r i t e { $ f p ,

"0"."\n");

f c l o s e ($fp) ;

, ,
.
,
, $w .
, : , , , $w
.
:
$ = file ( $ a d d s ) ;
$co[$w] = t r i m ( s t r _ r e p l a c e

("\n","",

$co[$w]));

$co[$w] + + ; Scount = $co[$w];


$co[$w] = $ c o [ $ w ] . " \ n " ;
$
. $count ,
.
, ,.
, ,,

PHP

102

. ,
. , , , , .
.
:
$ = implode ("", $) ;
$fp = fopen($adds, "w" ) ;
if

($fp) { $fw = fwrite($fp,

$p) ; fclose ($fp) ; }

, $ . ,
, . :

,
log.phtml.
, .
, , index.phtml
:
<? include

($DOCUMENT_ROOT."/count/log.phtml"); ?>

.
,
. :
<table align="center" barder="1">

$add = $DOCUMENT_ROOT."/count/urlfile . t x t " ;


$adds = $DOCUMENT_ROOT."/count/counter.txt";
$li

= file($add) ;

103

$ = f i l e ( $ a d d s ) ;
$ = c o u n t ( $ l i ) ;
.
log.phtml.
. , HTML:
$i = 0; $w = 0;
while

($i < $a) :

echo " < t r x t d > .


<a

href=$li[$i]>$li[$i]</a>

</tdxtd>$co [$i] </tdx/tr>" ;

endwhile;
?x/table>

. !
, :
<? include (SIXXXMENTROOT. " / c o u n t / l o g . p h t m l " ) ;

?>

(
),
,
.


,
, .

PHP

104


(, 4).

cookie

, .
, , :

$ = m k t i m e ( 0 ,0 ,0 , 1 , 1 , 2 0 2 2 ) ';
if

(isset

else

($name))

{ $name++;

{ setcookie

("name "',

s e t c o o k i e ( "name " ,

" 0 " , $y) ;

$name,

$y) ;

. cookie $name , .
cookie .
. :
<> - <? echo $name; ?></p>
, ,
.

cookie . , cookie .
cookie.


, ,
. , ,
. .
, . :
h t t p : / / v i r t u a l . b r e s t . b y / p h p / http://20404 0.com.

105


. , Excel, , .
. .
. ,
http://home.name ( , ,
). , .
, ,
(http://virtual.brest.by/php/ http://204040.com)
: http://home.name/reg.phtml?id=l http://home.name/
reg.phtml?id=2.
? , ,
, $id, ,
.
, . ,
, , .
:
$[0] = "http://home.name";
$[1] = " h t t p : / / v i r t u a l . b r e s t . b y / p h p / " ;
$[2] = "http://204040.com";
,
. ,
. $id,
home.name. ,
.
:
$add = " l o g . t x t " ;
$sl = file($add);

PHP

106


. $id :
if ($id < 1 or $id >= count ($u) ) { $id = 0; }
, .
:
$url = $ u [ $ i d ] ;
$temp = t r i m ( s t r _ r e p l a c e {"\n","",
if (!$temp) { Stemp = 0; }
$temp++;
$sl[$i] = Stemp."\n";

$sl[$id]));

, .
$,
, ,
. $temp , .

.
:
Ssav

= i m p l o d e ( $ s i ," " ) ;

:
$ = @fopen($add, "
if ($) { $fw = fwrite($fp,
header

("Location:

$sav);

fclose($fp);

".$url);

. ,
, , .. , .
. ,
, . .

107


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

. ,
,
. , , .
, .
.
. , :
, .
,
. , , , . .
:

// 1

>
. , cookie,
.

PHP

108

, ..
.
:

$nomer_ban = 3;
$name_file

= " ";

$list = file ($name_file);

$nomer_ban
. ,
.
$file_name , .
, .
.
, $ list.
, ,
.
, , ,
, (
) ( ,
, ) .
:

$set = t r i m ( s t r _ r e p l a c e

("\n","",

$set = t r i m ( s t r _ r e p l a c e

("//","",

$ l i s t [ 1] )) ;
$set));

$set+ + ;
if

(Sset > Snomerban or Sset < 1) { Sset = 1; }

109

$set $list.
, , ,
1.
.
(//) . , .
$set ,
.
, , ..
, .
, , .
, , . , , :
if ($set = = 1)

{ ?> <?

if ($set = = 2)

{ ?> <?

if ($set = = 3)

{ ?> <?

. ,
, :

$list

[1] = "// $ s e t \ n " ;

$ s t r = implode ("",

$list);

$fp = fopen ( $name_f i l e , "w" ) ;


if

($fp)

{ $fw = f w r i t e ( $ f p ,

$str) ; fclose($fp) ;


. $ s t r -

110

PHP

. ,
.

. , , .
.
, .
,
,
, .
HTML-,
. PHP include (" "); , phtml, php php3 .

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

, , ...

111

, , . , , :
< href="http://myhost.com"XIMG SRC="http://myhost.com/
banner.gif" alt="Moft " b o r d e r = " 0 " X / a >
, , , . ,

, , .
. :
, .
, , . .
.
:

, ,
, .
, . ,
, .
, , , , . :
< h r e f = " h t t p : / / m y h o s t . c o m " >
<SMG S R C = " h t t p : / / m y h o s t . c o m / b a n n e r . p h t m l ? i d = l "
alt="Moft "

border="0"X/a>

, id.
,
banner.phtml, -

PHP

112

.
:
header

("Location:

banner.gif');

.
,
, id.
.

. ,
, , .
,
,
.
, $id. , ,
$id
( ). Sid

, .
, , :
$adds = " u r l . t x t " ;
$txt = f i l e ( $ a d d s ) ;
$txt. ,
, . :
$str

= trim(str_replace

("\n","",

$txt

, , ...

113

, . , .
:
list

(Sadd,

Stime,

Scounter)

= split

("

" , Sstr) ;

. , .
$ counter , .
, .
Unix (. 6). , 1 1970 .
,
, , , .
:
$time = time (void);
$counter+ + ;
.
.
(, $id):
A

$txt[$id] = $add.'"-".$time." ".$counter."\n";



.
,
:
Sstr = i m p l o d e ( " " ,
Sfp
if

Stxt);

= fopen($adds, "w");
(Sfp) { Sfw = f w r i t e ( $ f p ,

Sstr);

fclose(Sfp);

, .

114

PHP

, ,
, .




.
stat.phtml.
:
$adds = "url.txt";
$txt = file($adds);
$i = 0;
while ($i <= count ($txt) ) :
$temp = trim(str_replace ("\n","", $txt

list ($add, $time, $counter) = split ("",

$str)

echo $add." - ".$counter." : ".$time."<br>";

endwhile;
, .
,
.
.

115


:
<?

sessionname ("virtualbrest") ;
session_start ( ) ;
session_register("counter");
$counter = @$counter + 1 ; ?>
<htrnl><body>HaacMHre "",

<br>: <?=$counter?>
</body></html>
SID,
.
, PHPSESID. s e s s i o n s t a r t () , session_register("counter")

$ counter.
, , .


,
. , ,
.
, ,
logo.txt .
.

116

PHP

1 <?
2 $lin = file ("logo.txt") ;
3 $a = count ($lin);
4 if ($a < 11)
5 {
6 $size = $a;
7 } else
8 {
9 $size = 10;
10 }
11 ?>
12 <_P>
13 <select name="Dl" size=<? echo $size; ?>
14 <? $i = 0;
15 while ($i < $a) :

16 echo "<optionvalue=".$i.">".$lin[$i] ."</option>";


17 $i++;
18 endwhile; ?>
19 </selectxbr>
2 0 <input type="submit" value="submit" name="B2">

( 2).
, (
3), ( 413).
11, ( 46).
10, ( 710). ,
,
$size 1.

117

,
, (
1518).
( 1920).
<form>
</form>, ,
(. 5).



, , .
:
<form method="POST" a c t i o n = " p o s t . p l i t m l " >
<? $ s l l l = f i l e ( " u r l . t x t " ) ; ?>
<select name="ur" s i z e = " l " >
<option value="0"><? echo $slll[O];
?>: - K / o p t i o n >
<option value="l"><? echo $ s l l l [ l ] ; ?>: -2</option>
<option value="2"><? echo $ sill [ 2 ] ; ?>: -3</option>
<option value="3"><? echo $ s l l l [ 3 ] ; ?>: -4</option>
</select>
<input type="submit" 1="" name="Bl" >
</form>

(. 21),
, .
url.txt,
(
) , , .
post.phtml:
if ($ur =
"") { $ur = ; }
$add = " u r l . t x t " ;
$sl = file($add);

. 21.

I*
*/
$u[0] = "http://-l";
$u[l] = "http://-2";
$u[2] = "http://-3";
$u[3] = "http://-4";
$i = 0;
while ($i <= count ($u) ) :
$sl[$i] = trim(str_replace (" \n" , " " , $sl[$i])).
if ($ur == $i)
{
$url = $u[$i] ;
$sl[$i]++;
}
$i++;
endwhile;
$sav = " "; $i = 0;
while ($i <= count ($u)):

119

$sav = $sav.$sl[$i] . " \ n " ;


$i++;
endwhile;
$sav = str_replace ("\n\n", "\n", $sav);
$ = @fcpen ($add, "w+") ; if ($fp) { $fw = @fwrite{$fp,
$sav); @fclose($fp); }
header
?>

("Location:

".$url);

. :
, .
, , . , , ,
, .


, ,
. .
, , , :
$f = fopen("counter.txt","w + ");
* /

/ *

w+ , ( ).. ,
" ,
.

, ,
, ,
-

120

. ,
, .
, ,
.
.
flock ( d e s c r i p t o r , mode).
(
, , fopen). mode :
1
;
2 , .. ;
3 .
:
flock($f,2);

//

:
flock($f,3);

//

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

,
:

121

, ,
.
. 1-, ..
.

, . . ,
http://subscribe.ru.
, , .
, .
, .
,
. : http://win.subscribe.ru/catalog/
latest.

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

122

PHP

<?php
//
$link = "http://win.subscribe.ru/catalog/latest";
$file = @fopen($link, " r"" ) ;
if ($file) {
$rf = f r e a d ( $ f i l e ,
fclose

200000);

($file);

} else
{
echo "<h3 align=center>M3BMHMTe,
! < /h.3 >
<center>
<EVCJ

src=http://virtual.bresttelecom.by/banner.jpg

width=468 height=60 border=0 =\" \">


</AXbrXbr>";

// 1
$rf = trim (chop ($rf));
$s = strpos($rf, "<!-noindex-XFORM", 0) ;
$rf = substr($rf, $s);
// 2
$s = strpos($rf, "< !-/noindex-xtable " ) ;
$rf = substr($rf, 0, $s) ;
// 3
$rf = str_replace ("/catalog/","http://-win.subscribe.ru/
catalog/",
$rf);
$rf = str_replace ("/archive/","http://-win.subscribe.ru/
archive/",
$rf);
$rf = str_replace ("ACTION=/member/

123

quick", "ACTION=http://win.subscribe.ru/member/quick", $rf) ;


$rf = str_replace ("/img/money2.gif,"http://
win.subscribe.ru/money2.gif,
$rf);
$rf = str_replace ("/img/all4.gif',"http://win.subscribe.ru/
af.gif", $ r f ) ;
$rf = str_replace
af.gif", $rf) ;

("/img/af.gif","http://win.subscribe.ru/

// 4
echo $rf;

. .
. , ( 200 000 ,
).
,
, .
.
1 :
$rf = t r i m (chop ( $ r f ) ) ;
, ,
.
, :
$s = s t r p o s ( $ r f , "<!-noindex-XFORM", 0) ;
,
. $s.
, ( ):
$rf = s u b s t r ( $ r f , $ s ) ;

124

PHP

2. , ,
.
, . ,
, , .
, .

, , : , .
,
.
3. , , , . :
$rf = str_replace
("/catalog/", "http://win.subscribe.ru/catalog/",

$rf);

$rf
. ,
. , .
4. . HTML-, .
,
. : , ,
.
, . .



. ,
,
:
? :
!
.
.
- .
.
.
, .
, .
index.phtml, golos.txt
golos.phtml (, , , , , ).
.
Index.phtml.
, , .
,
.
.
HTML, , :
<foQn method="POST" a c t i o n = " g o l o s . p h t m l " >
<table b o r d e r = " l " X t r > < t d > < t a b l e b o r d e r = " 0 " >
<tr><td>Banie caUTe?</td></tr>

< t r x t d x i n p u t type= "radio" name= "answer"


! </tdx/tr>
< t r x t d x i n p u t type="radio" name= "answer"
</1 d></1 r>
< t r x t d x i n p u t type="radio" name= "answer"
paBHO</tdx/tr>
< t r x t d x i n p u t type=" radio" name= "answer"
- ! < / t d x / t r >

value="l">
value="2">
value="3">
value="4">

<trxtdxinput
type-"Submit"
name="vote" value= " " x / t d x / t r >
< t r x t d x i n p u t type=" Submit" name= "result" value=" "> < / t d x / t r x / t a b l e x / t d x / t r x / t a b l e x /
form>

PHP,
PHTML,
PHP-. (. 22).

. 22.

127

HTML- , .

.
PHP-, , , a c t i o n ,
.
, , , .
golos.txt. ,
.
( ),
. golos.txt
f i l e ( $ a r r a y ) .
,
, , .
. . () , , .
golos.phtml. .
, .
1 <?php
2 $file = "golos.txt";
3 $ = f i l e ( $ f i l e ) ;
4 $i = 1; $ f i = count ($a) ;
5 $n = 0;
6 w h i l e ($i <= $ f i ) :
7 $a[$i] = t r i m ( s t r _ r e p l a c e
8 $n = $n + $a [$i] ;
9 $i++;
10 endwhile;

("\n","",

$a[$i]));

128

PHP

11 if ($answer != "") {
12 echo "<>, " ;
13 $[$answer]++; $++;
14 $rez = " \" . $ [1] .
"\".$[2]:"\".$[3]. "\".$[4];
15 $fp = @ f o p e n ( $ f i l e , " w " ) ;
16 if ($fp) { $counter = fputs{$fp, $rez) ; f c l o s e ( $fp) ; }
17 e l s e { echo " ! " ; }
18
19
20
21
22
23
24

} e l s e { echo "<> "; }


echo "<>! - < b > " . $ [ 1 ] . " < / b > " ;
echo "<> - < b > " . $ a [ 2 ] . " < / b > " ;
echo "<> - < b > " . $ a [ 3 ] . " < / b > " ;
echo "<> - ! - <b>" . $a [4] . "</b>" ;
echo " < b r x b r > B c e r o : " . $ n ;
?>

, , . ,
- , ,
( ),
, .
,
. , .
( 2) $ ( 3). ( 610), ,
( 7).
.
,
"\" ( )
trim ().
, -

129

, , ,
.. , $answer, .
,
,
( 8).

,
. $answer
( 11), .
, ,
( 1416). $answer , , , ( 13).
, , ( 13).
, . ( 15). w
.
, $rez ( 16), ( 17).
$rez :
( ,
) ,
. .
. ,
.

130

PHP

, .
HTML <>.
, . -,
.
, . : , . , .
. , .
,
: ,
, , IP- ,
.. .


, Web- : , , ?
,
,
. .
. ( guest.phtml)
,
. , (guest.txt) , .
FTP-,
.

.
guest.phtml. :
<2> </2>
<form action="guest.phtml" method="post">
e-mail: <input type = "text" name="email">
BauE : <input type = "text" name="name">
: < b r > < t e x t a r e a
cols= "40"></textarea>
<p><input

type="submit"

name="msg"

rows="10"

1="0"/>

(
email), ( name) ( msg) (. 23).

. 23.

PHP

132


, , . .
, ,
, :

$files = "guest.tact" ;
$ = 50;

:
if

(!$email)

{ $email

= "";

$msg = s u b s t r ( $ m s g , 0 , 9 9 9 ) ;
$email

= substr($email,0,39);

$name = s u b s t r ( $ n a m e , 0 , 3 9 ) ;

, ( ,
""). , . ,
, .
, :
if

($msg != " " && $name !=.."") {

, , (. ).
, , , , :

133

Stime = D a t e ( " h : i : M : d " ) ;


$soo = " \ n < b > $ t i m e $name (<a h r e f = \ " m a i l t o : $ e m a i l

\">

$ e m a i l </a>) < / b x b r > $ m s g < h r > " ;


$fp

= fopen($files,

$fw

= fwrite($fp,

fclose($fp);

"a+");
$soo) ;

. .
, HTML.
(
100,
, , 50- 80-).
, . :
$lines = f i l e

($files);

$ = count($lines);
$u = $a - $qq;
for($i = $a; $i >= $u ;$i-) { echo $lines[$i]; } /* */

, ,
, ,
.
, .
, . ,
, . , .

134

.
.
, :
<ahref=guest.txt>apxMB</a>
,
HTML-. , ,
.
,
, , ,
.. .


.
, .
.

. ,
,
, , .
Web- . , Web-
,
.
.
, , CGI (,
Perl).
.

135_

,
C G I ?
,
CGI? , ,
, ?
, , . ,
- .
: ,
(. ) .
, , .
, - . , .
, - C G I .
C G I ,

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

. , ,
.
, : -

136

PHP

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

. ,
,
, . .
:
, ( ,
, -
, ) ,
?
. Windows
2000, .
, -

137

.
( , ..).
, Windows

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

. , : -

138

PHP

, cookie
.
,
.
,
, .
, , .
: , , , guest, , ( ), .
,
, ,
, , ..
.
, , , POST (CM. 5) ,
.
, , .
, - . .
( )
, , (
1 .
.
(. .)

139^

) , .

, , ..
, . ,
, , ..
, . ( , ),
, .
,
. , , POST,
.
GET (CM. 5), ,
..! .
, , ,
. , .
POST, $QUERY_STRING.
, , - GET. .
, . ,
,
,
, , ,
. ,
, , , , . ,
,
,
. ,
, , . - -

140

PHP

, ,
.
,
GET. , , . cookie. , cookie
. cookie
, , ,
, .
:-)
, cookie
, .
, , ,
. GET.
GET
, . . ,

,
GET . ,
, .
.
,
, .
.
.
,
, , . , Windows 2000
(. ): ,

1_41

. , : GET , (
, ),
.
, GET, .
, , , . . ,
,
. ,
, , .
,
.
, ,
, , . .
, .
, .
, , .
POST (, ). ,
, .
. , ,
- . , , . HTML .

142

PHP

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

, ..
,
, . , ,
. ,
,
. , . ,
. ,
- . ,
. ,
GET. ,
, ,
.

143

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

. ,
, - , ,
.
,
. , .
. , , .
, ,
ICQ .
. , . ,
.
,
.
. .

PHP

144


,
. , , ,
, .
, ,
, , .
, 4.
, .
:
index, phtml
tools.phtml
header.phtml
banner.phtml
mainwindow .phtml
msg.phtml
userlist .phtml
memolog
log_chat.txt kto_chat.txt. ,
, ,
.
, .
index.phtml. , , .
, .
:

<form method="POST" action="header.phtml">


<> :</>
<input type="text" name="person"
size="14"

maxlength="10"Xbr>

<p><input type="submit" 1=" " name="Bl">


</form>
(. 24),
header.phtml. ,
.

. 24.

name <input> person,


($person) ,
. $person .
tools.phtml. ,
.
, , , c h a t v i r t u a l b r e s t .
:

PHP

146
<?
sessionname

("chatvirtualbrest");

session_start();

,
c h a t v i r t u a l b r e s t , .
if

( $ip == " 1 2 7 . 0 . 0 . 2 " ) { $ s e r v e r = 1; } e l s e


{ $server = 0 ; }

,
. , ,
,
. Sip 12 7.0.0.2.
, $ip =
getenv("REMOTE_ADDR"); :
echo $ip;
exit;
IP- . 127.0.0.2 .
, $ serve ,
, 0 (). , 1 ().
- ( ), :
if ($server) {,
} else {, }
:
if

( ! $ s e r v e r ) { e r r o r _ r e p o r t i n g (0) ; }

, . , , .

147

:
$time_nast = t i m e ( v o i d ) ;
,
, .
$file_logchat=

"memolog/log_chat.txt";

, log- . ,
.
:
$chat_number = 10 0;
$name_rob = "Robot";
. ($chat_number)
, ,
.
, - . , ,
,
.
$name_rob ,
, ..
, , :
$file_kto_in_cliat

= "memolog/kto_cliat.txt";

Unix-,
:
//

$tme = dsLteCH:!'1 ) ;

. , ,
. ,

PHP

148

, .
, :
$timel = d a t e ( " H " ) ;
$time2 = d a t e ( " i " ) ;
$ t ime_s = 7
$ t i m e l = $ t i m e l + timer_s;
if

( $ t i m e l >= 24) { $ t i m e l = $ t i m e l - 2 4 ; }

$time = " $ t i m e l : $ t i m e 2 " ;


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

, .
header.plitinl. .

,
, .
.

tools.phtml, :
include

("tools.phtml");

149

, . :
session_register( "person",

"pass");

, , , .
, :
$kto = file

($file_kto_in_chat);

: ,
~ (, )
.
, , , 1 1970 .
.
, :
$fi = c o u n t ( $ k t o ) ; //
$met = - 1 ; / * ; -1 , */
$1 =0;


:
while

($i <= $fi) ;

$str = t r i m ( s t r _ r e p l a c e

("\n","",

$kto

[$i]));

:
if
list

($str)
($name_kto, $time_kto)

= split

("~",

$str) ;

PHP

150


split ($name_kto)
($time_kto):
if { {$time_nast- $time_kto)

> $chat_number and

$name_kto ! = $person)
, ,
, , . :

$kto
,
.
:
$sav = "$_~$~ $name_kto~\n";
$fp = fopen($file_logchat,
if

($fp)

{ $Kv = fwrite($fp,

"a+");
$sav);

fclose($fp);

, .
,
. , .
, . 25.
, ( +
fopen). (
, ,
), .

, $met $1. , $i 10 000
(, 10 000 ), $met, :

if ( $name_kto = = $person ) { $met = $ i ; $i = 10000; }


,
( - ) ,
..

:
}

endwhile;
, , . - 1 , , ;
if

{$met == -1)

$sav = "$_~$~1
$fp
if

= fopen($file_logchat,
($fp)

$kto[]

$fw

= fwrite($fp,

$person~\n";

"a + "};
$sav);

= "$person~$time_nast\n";

fclose($fp);

, ? , - (
).
, ,
.
(. 26).

. 26. log_chat.txt

, ,
,
, :
} else { $kto[$met] = "$person~$time_nast\n";

, :
, , , . , , .

,
:

15 3


$sav = implode ( "An" , $ k t o ) ;
$sav = str_replace

("\n\n", "\n" , $sav) ;

$sav = str_replace

("\n\n", "\n" , $sav) ;

, :
$fp = fopen($file_kto_in_criat,
if

($fp)

{ $fw = fwrite($fp,

"w");

$sav) ; f close ($fp) ; }

, HTML:
<html><lieadxtitle>ripiiMep4:aTa</title>
<meta http-equiv="Content-Type"
ctLarset=windows-125 l " X / h e a d >

content="text/html;

,
. ,
, :
<frameset

framespacing="O"

rows="54,*,70">

<frame name="banner" scrolling="no"


"banner" src="banner.phtml">
<frameset

noresize

target=

cols="200,*">

<frame name="userlist" target="userlist"


frameborder="0" scrolling="l" >
<frame name="main_window"
frameborder="0">

src="userlist.phtml"

src="main_window.phtml"

</frameset><frame
name="msg" scrolling-"no" noresize
target="msg" src="msg.plitml" frameborder="0">
</frameset>
banner.phtinl.
, ..

PHP

154
:
<html><head>

<meta http-equiv="Content-Type"
charset=windows-1251" >

content= "text/html;

<style type=text/css>
A { text-decoration: none}
A { color: #FFFFFF}
A:hover {color: #EFEF4B; text-decoration:underline;}
A.mat {color: #FFFFFF}
A.mat:hover {color: #0066FF}
p { font:

8px Verdana }

</stylex/head>
<body topmargin=0 leftmargin=0 bgcolor=#546A8C>
.
.

.
<table border="0" cellpadding="O" cellspacing="O"
width="90%" align= "center"XtrXtd>
<font color= "white ">
/td X/trX/table >
</body></html>
,
, .
main_window.phtnil. , ,
( ):

155

<?

include

{"tools, p h t m l " ) ;

?>

<html><head>
<meta http-equiv="Content-Type"
charset=windows-12 51" >

c o n t e n t = "text/litml;

<meta http-equiv=Refresh content="5; URL==rriain_yvdndcv.phtrrir'>

, , .
,
.
(. 1), :
^ {
scrollbar-face-color:#54 68;
Scrollbar-3alight-color:#FFFFFF;
scrollbar-track-color: #FFFFFF;
scrollbar-arrow-color: #FFFFFF;
scrollbar-border-color:#000000 }
p { font: Verdana; font-size : 12 ; }
</style>
<bocV bgcolor=#E7E7E7>

30 :

$user = file ($file_logchat)


$i = count($user) ;

156

PHP

$fi = $i - 3 0 ;
if

{$fi

while

< 0)

{ $ f i = 0;

($i >= $ f i ) :

30:
l i s t (Sname, S t i m e n a m e , Smsg, Skomu) = s p l i t
trim(str_replace
("\n","",
Suser [ $ i ] ) ) ) ;

("~",

, ,
.
:
if

($name and $msg)

if

{! $komu or $komu == $person)

if

(!$komu)

echo "<small>$time_name>
</small> <b>$name</b> $msg<br>";
} else {
echo "<small>$time_name>
</small> <> $name $komu:</b> $msg<br>";

, - , . .

end while;
?><br></body></html>
.

1 57

msg.phtml.
,
, ,
.
.
,
. ,
, .
<?

ixxrlude

("tcols.phbnnl") ; ?>

<htmlxheadxmeta http-equiv="Content-Type" content="text/


html; charset=windows-1251">
<style type=text/css>
input.button {
border-style:solid;
border-width:lpx;
border-width-color:#546A8C;
width:8 0px;
height:2Opx;
font-family:
font-size:

Verdana;

lOpx;

color: #000000;
font-size:

lOpx;

background: #E7E7E7

p { font: 8px Verdana }


body { font: 12px Verdana }
</style>

158

$kto = file
$fi

($file_kto_m_chat);

= c o u n t ( $ k t o ) ; $met = -]_; $ i = 0 ;

while

($i <= $ f i ) :

$str = trim(str_replace
if

($str)

list
if

("\n","",

$kto

[$i]));

($name_kto,

$time_kto)

= split

("~", $ s t r ) ;

( $name_kto == $ p e r s o n ) { $met = $ i ; $ i = 1 0 0 0 0 ; }

endwhile; ?>
, .
,
, .
:
<base

target="msg">

</head>
<body l e f t m a r g i n = " 0 " t o p m a r g i n = " 8 " bgcolor="#546A8C">
<? i f

($met != -1) { ?>

<form method="POST">
&nbsp;&nbsp;&nbsp;&nbsp;
<input maxlength="500" type="text" name="msg" value=""
size="20">
<input type="submit" value=""

class="button">

(. 27).

. 27.

500. ; , .
, , , :
<? i f

($fi > 2

{ ?>

<select name=komu>
<option value= " " selected>KoMy</option>
<?

$i = 0; while ($1 < $fi) :


$str = trim(str_replace
if

($str

!= " " )

("\n","",

$kto[$i]));

list ($nik) = split ("~\ $str) ;


if ($nik != $person) {
echo "<option value=\ " $nik\ ">$nik</option> " ;
}

160

PHP

endwtiile;
edho "</select>";

,
. . , ,
.

: , , ,
:

if

($met != -1) {

if

{$msg and $person)

$sav = "$person~$time~$msg~$komu\n";
$fp

= fopen($file_logchat,

if

($fp) { $fw = fwrite($fp,

"a+");
$sav) ; fclose($fp) ; }

. . .
(
), :
if

(Skomu)

Ssav = "$komu~$time~$msg~$person\n";
Sfp
if

= fopen(Sfile_logchat,
(Sfp) { Sfw = fwrite($fp,

"a + " ) ;
Ssav);

fclose(Sfp);

1 61

,
, , , .
, :
}

} else { echo "&nbsp;&nbsp;&nbsp; ! " ; }


? ></form></body></html>
, . ,
.
, , ,
.
.
userlist.phtml.
. .
, ,
. , ,
:
<? include

("tools.phtml"};

?>

<html><head>
<meta http-equiv="Content-Type"
charset=windows-1251 ">

content="text/html;

, :
<meta http-equiv=refresh content="15; url=userlist.phtml">
15 , .
,
. , , (, ) ,
, . -

PHP

1 62

,
,
,
.
:
<base
<styie
bod^ {
scrollbar-face-color:#54 6A8C;
Scrollbar-3dlight-color:#FFFFFF;
scrollbar-track-color:

#FFFFFF;

scrollbar-arrow-color:

#FFFFFF;

scrollbar-border-color:#000000
}
p { font: lOpx Verdana }
td { font: lOpx Verdana }
</style>
<body topmargin=0 leftmargin=O

bgcolor=#546A8C>


:
<form method="POST" target="_self">
<table border="0" width="100%" height="100%">
<tr><td width="8%"X/td>
<td width="87%" bgcolor="#E7E7E7" valign="top">
<table border="0" width="100%"><tr>
<td width="100%" height="100%">
<big>B : </bigxp>

163

:
<?
$kto = file ($file_kto_in_chat);
$fi = c o u n t ( $ k t o ) ; $met = - 1 ; $ i = 0;
while

($i <= $ f i ) :

$str = trim(str_replace

( "\n" ,"", $kto

[$i]));

if <$str) {
list

($name_kto, $time_kto) = split {"~", $str) ;

if ( ($time_nast-$time_kto) > $chat_number)


$kto
$sav = " $name_rob~$time~Bonien $name_kto~\n";
$fp = fopen{$file_logchat, "a+") ;
if ($fp) { $fw = fwrite($fp, $sav); fclose($fp); }
}
, .
.
, .
,
2030 . ?
:
if

( $name_kto == $person )

$met = $i;
echo

"<t$name_kto</bxbr>" ;

} else {
echo

"$name_kto<br>" ;

PHP

164

endwhile;

.

:
if {$met = = -1)

echo "<> ! "


} else {
$kto[$met] = "$person~$time_nast\n";

,

.
:
$sav = implode(" \n" ,

$kto) ;

$sav = s t r _ r e p l a c e

("\n\n", " \ n " , $ s a v ) ;

$sav = s t r _ r e p l a c e

("\n\n", " \ n " , $ s a v ) ;

$fp = f o p e n ( $ f i l e _ k t o _ i n _ c h a t ,
if

($fp)

{ $fw = fwrite($fp,

"w" ) ;
$sav) ;

f c l o s e ($fp) ;


, -

1 65

, .
.
, , , , :
<hrxa href = "userlist.ptititil" ></>

</ t a b l e x /boc^/x /frtml>

, . !


, , .

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

166

PHP

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

, Unix (. 6).

. . Unix :
Unix , .

.
.
,
.
, , .
.

167

,
.
, , ,
.
, , , GET. (, ) POST.
.
, ,
.
, ..
, , ( ), ,
.

, ,
. , , .
, , .
.
Unix:
$time = t i m e ( v o i d ) ;
,
:
$ f i l e = " " . $ t i m e . " . p h t m l " ;
, ,
,
.

PHP

168

,
:
$sav = "<? / * * $person * * $kto * \ n " ;
Sperson $kto
.
$sav :
/ /
$ f i l e = " ,

";

$sav = ",

";

$fp = fopen

($file,

"w" ) ; / /

if($fp)

$iw = fwrite ($fp,


fclose($fp);

$sav); // ,

//

else

/ *
* /

, ,
, .
, , , .


. ,

1_6

,
. , , .
,
Unix.
.
.
, .
, , ,
. ,
. ,
, ,
.
,
, , . . , , GET. ,

.
,

.
.
. .
. - , , .

170

PHP

, . .
.

-

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

. , .
, . , , . ,
,
.
Excel ( ,
, , 1: , ,
Excel).
,
.

171

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

Excel ( ), , , ,
, . , . , ,
,
:-) , .
? , , . ,

. ( Excel) - . , ,
, , . ,
, .
Excel .
.
,
. .
: *.txt,
( Enter), . ,
Excel.

-,
.
, ,
.

PHP

172

, , , ..
,
, , ,
. ,
.
,
.
:
$

"price.txt";

$tovar = file

($file);

$tovar [] :
$i = 0; //
while ($i < count ($tovar)) : //
//
echo $ t o v a r [ $ i ] ;

//

echo "<br>"; //
$i++; //
endwhile; //
. , ,
,
. .

.
. , ,
. , ,

173

. , . .
, , ,
, ,
, .
. . , ,
.
, ,
: .
. , , ,
,
.
, - , , ,
, , , , ..
:
.
.
.
,
. . , .
, : $_1, $_2, $_3,
$_4, $_5. ,
$ t o v a r [ $ i ] , :

PHP

174
list
($n_l, $n_2,
$tovar[$i]) ;

$n_3,

$n_4,

$n_5)

split

<"\t",

, .
, " \ t " .
,
. -,
.
. ,
, -.
-? , . ?
, ,
,
, ( ).
, .
, ?
, .
: , ? , . , , . :
, ,
, ..
,
.
, ,
.

175

, cookie.
, . , .
, , .
.
.
, . , . ,
, cookie, .
,
,
. , . , ! . . , - ,
.
. .

.
:
$file " p r i c e . t x t " ;
$as = f i l e ( $ f i l e ) ;
:
$info = $ a s [ $ i d ] ;
$id , . ,
, ,
.

. 1.
(

176

PHP

, ) . . HTML-
, Enter.
,

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

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

177

, .
.
, .
. .
. : _@_
.
, .
SMS ,
, .
, ,
. .

,
-,
,
. ,
.
.

, . .

178

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

G D , . GD
php.ini, Windows (. . ).

, - .
,
. , banner.
, , ,
. ,

. :

179

-
$dir = opendir ("banner/");
while($f = r e a d d i r ( $ d i r ) )
if

( !s t r i s t r ( S f , " . . " )

a n dS f ! =- . " )

{ $ t t [ ] = $ f ;}
} }

, , $ t t .
, , , ( ).
, ,
.

. , cookie .
:
$ t t l = file

( " c o u n t e r . p h p " );

$str = t r i m ( s t r _ r e p l a c e

( " \ n " ," ", $ t t l [ O ] ) ) ;

$str++;
if

($str > = c o u n t ( $ t t )

or $str < 0} { $ s t r = 0; }

( ),
,
. ,
.
, . , , .
:
$fp = fopen("counter.php",
if

($fp)

{ $fiv = fwrite($fp,

"w");
$str); fclose ($fp); }

PHP

180

,
. , . , ,
. ,
. , , ,
.
:
$strl = trim{str_replace
@list

($id_price,

$id_ras)

(".","", $ t t [ $ s t r ] )) ;
= split("~",

$strl);

, , . .
, , , :
if ($id_ras = = "jpg" or $id_ras = = "jpeg")
echo "<img border=0 s r c = b a n n e r / $ t t [ $ s t r ] > " ;

{
} else {

,
:
@$siluro++; }
, , ,
, , , ,
, . . ,
, .
:
$temp_siluro = @$siluro;
if

{@!$siluro} {

,
, $siluro .

181

:
if (@$siluro != $temp_siluro
include("mini.phtml"); }

and

$siluro

<

50)

, , ,
mini.phtml, include ("mini.phtml"); . , -
, ,
. .

, ,
, ..
.
chitatxt.php ,
. :
, , .
, , .
, ,
:
$nomer = 1;
$ file = " c h i t a t x t . p h p " ;
$ii = 0;

$tt = file

( $file

);

$qw = count ($tt);

, :
while ($ii < 4):

;
, . ,
.

PHP

182

, :
$nomer++;
@$str = trim($tt[$nomer]);
list

($data,

$add,

$txt)

= split

("~\

$str) ;

:
echo "<b> $data</b> <a h r e f = \ " $ a d d \ " X b r > $ t x t </a>";
:

endwhile;
. ,
, , .

, ? , ,
, ,
. ,
, ,
:

$dir = opendir("news/");
while ($f = readdir ($dir) )
{
if ( s t r i s t r ( $ f , " . h t m l " ) )
{ $ l i [ ] = $f; }

183

, ,
, .
$i = ; while
include

($i < count ( $ l i ) ) :

{"news/$li[$i]");

echo "<br><hr noshade size = l > " ;

endwhile;

, . , .

- , .
, ,
. , .
Excel
: , , . ,
.. , , ,
(. 28).
Excel , , (. 29).
,
, (. 30).

.

. 28. Excel

. 29. Excel

. 30.

185

, ,
.
,
.
:
,
:
<form methocL= " POST "
name="pop" action="cena.phtml"
="1

">

SUBMIT , , cena.phtml.
.
read.phtml:

$f i l e = $DOCUMENT_ROOT."/$path/price.txt";
$as = f i l e

( $file

);

( $as) price.txt, . , $ file =


$DOCUMENT_ROOT."/$path/price.txt";
, ,
,
$ D O C U M E N T _ R O O T H , , $ path, .
.
,
$path. , .
, ,
:

PHP

186
$ip=getenv("REMOTE_ADDR");
if

($ip != " 1 2 7 . 0 . 0 . 1 " )

{ error_reporting(0) ; }

, IP- , .. , , , , ,
.

, :
$1 = 1;
while ($i < c o u n t ( $ a s ) ) :
$str = trim(str_replace

("\n","",

$str = str_replace

("\t","~",

$str = str_replace

("\"","",

list
$n_l
$n_2

($n_l,

$n_2,

= str_replace
= str_replace

$n_3)

$str);
$str);

= split

<",",".",
(",",".",

$as[$i]));

("~",

$str) ;

$n_l) ;
$n_2);

$ a s [ $ i ] = "$n_l~$n_2~$n_3~$n_4~$n_5";

$as[$i]

= str_replace

(",",",

$as[$i]

= str_replace

("

","

",
",

$as[$i]);
$as[$i]);

endwhile; ?>

, , ,
, , ,

187

( Excel
, ). ,
read.phtml ,
.
minor.phtml. :

$str

= str_replace

@list

($n_l,

$n_2 ,

("\n","",
$n_3)

$as[$q2]};

= split

("~",

$ s t r ) ;

?>

$q2 , ,
( $_1, $_2 $_3). , .
,
:
<? include

("read.phtml");

?>

<table><tr><td>neHa</td>
<td>Ha3BaHHe</td>
<td>OnncaHHe</tdx/tr>
<tr><td>
<?
$q2 = 0;
include

("minor.phtml");

echo $n_l;
?>: </td><td>
< select name="urO" size="l">
< option value=all

selected>

Bbi6paHa</option>

188

PHP

$ii =1; $i = 1;
while

($i < $s) :

$q2 = $ i ;
if

$s = count($as);

include

("minor.phtml");

($n_2 = " " and Si)

, ,
.
, .
.
:
echo "</select><br></td></tr><tr><td>$n_l:</td><td>
<select n a m e = u r " . $ i i . "

size="l">

<option value=all selected>


Bbi6paHa</option>" ;
$ii++; }
, :
else {

if

($n_l)

echo "<option value=\"$i\">".$n_l.":'.'.$n_3. "</option>";


} else { echo "</td><td></tdX/tr>"; }
: HTML. ,
-.
:

endwhile;

189

<br><input type = "hidden"


$ii-l;
?>">
&nbsp;< input
"

name="nom"

T"YPE="submit"

value="<?

^="

echo
-

NAME="B3"X/form>
, .
, cena.phtml.
<h3> </>
<? include

("read.phtml");

read.phtml .

$i = 0;
$_11

= 0;

while ($i <= $nom):


$nu = "ur". $i;
if

($$nu

!= "all")

$q2 = $$nu; include

("minor.phtml");

$n_ll = $n_l+$n_ll;

endwhile; ?>

<font
<br><a

color=red>".$n_ll."</font>
href=servis.phtml>

</>

,
, , .

PHP

190

, $nu 5,
$ $5. :
$ur5 = 1 0 ;
$nu = " u r 5 " ;

echo $nu;

10.
. , $nom, :
. , , . , , ,
.


, . , , , ,
.
: -, ,
. -, .
, , ,
.
, ,
.
.
html , zip ,

191

, , ,
(
,
). html zip .
, , .
,
. , , , . ,
.
$katalog_archiv = "archiv/";

, . , .
, , .
:
$name_temp = "Archiv_News!_";

,
,
. , ,
:

: html, zip txt.
html, txt.

txt:
$dir_archiv = opendir{$katalog_archiv);
while($f

= readdir($dir_archiv))

PHP

192

,
, .
,
:
$ f l = t r i m { s t r _ r e p l a c e ( " . " , " - " , $f) ) ;
list

($id_name, $id_ras)

=s p l i t

("~",

$fl);

, , , , ,
:
if

($id_ras = = "txt")

/ /

,
. ,
:
$f2 =t r i m ( s t r _ r e p l a c e
$f2

=trim(str_replace

( $ n a m e _ t e m p , " " , $ f ));


(".txt","",

$fl=

trim{str_replace

(" " , "~" ,

list

($den,

=split

$m, $ g o d )

$q[]

= "";

$q[]

= "";

$q[]

= "";

$q[]

= "" ;

$q[]

= "";

$q[]

"";

$f2));

$f2));

("~",

$ f l ) ;

193

$q[]

= "";

$q[] = " " ;


$q[] = " " ;
$q [ ] = "";
$q[] = "";
$q[] = "";
if ($m = = "01") $m = 1
if ($m = = "02") $m = 2
if ($m = = "03")

$m = 3

if ($m = = "04")

$m = 4

if ($m = = "05")

$m = 5

if ($m == "06") $m = 6
if ($m = = "07")

$m = 7

if {$m = = "08") $m = 8
if ($m = = "09") $m = 9
$m = $q [$m] ;
, - .
:
echo "<p><b> $den $m 20$god :

</b><br>

: <br><br>";
:
include

("$katalog_archiv$name_temp$f2.txt");

, HTML- . :

194

PHP

echo"<br><br><a
href=$katalog_archiv$name_temp$f2.html>
</> - <a href=$katalog_archiv$name_temp$f2.zip>
</></>";
, :

, , . , html zip txt,


, . ,
.


. : ,
. .
.
: ?
, , . ,
- , ?
.
. ,
, , . . ,
. , .
. , ,
.

195

.
, .
.
:
, : , , , . , .
, .
, .

,
,
.
- , , , .htacces
.
, :
<5>0 </5>
<form name="diler_vhod" method="post" action="diler.phtml">
<> :</><>
<input n a m e = " d i l e r "
<input type="submit"

type="password">
1="">

</form>
(. 31) , , , , .

. 31.
:
<?
$add_price = "memo/price_diler.zip";
.
, .
$pass = "3467899";
, .
, ,
. , :
$no_file = " " ;

:
if

($diler == $pass)

{ header ("Location: $add_price" ) ; }


else { header ("Location: $no_file") ; }
?>

197

, ,
. , , ,
, ,
, , .
HTTP-
HTTP-
Apache- , , CGI-.
PHP- Apache- header () Authentication Required
,
.
, -
$PHP_AUTH_USER, $PHP_AUTH_PW $PHP_AUTH_TYPE,
, , . , :
<?php
if

(!isset($_SERVER["PHP_AUTH_USER"]))

header("WWW-Authenticate:
header("HTTP/1.0
echo ",

Basic realm=\"My R e a l m \ " " ) ;

401 U n a u t h o r i z e d " ) ;

Cancel\n";

exit;
} else {
echo "<>

{$_SERVER[THP_AUTH_USER]}.</p>";

echo "<> {$_SERVER[^$PHP_AUTH_PW ] } .</>";

198

, ,
, . , "Basic"
, realm ( ), "401"
"/1.0 401" .


( ,
) , : ,
. , ,
,
.
. , ,
. - ( ). . ,
:
filesize (name_file). :
$ewq = " i n d e x . p h t m l " ;
$lo_call = 6507;
,
, . . $1_11 , ,
(, ?). , .
.

199


?
.
, . 1994 , .
( ) HTML. ,
, <?php ?>
- HTML?
, . HTML-
PHP-, .
HTML : < s c r i p t
language="php">, , , : </script>.
, PHP- .
, -?

. , , php, php3, php4 phtml. , . , SSI?


shtml.
, .
,
-.
?

. ,
, -

200

. , . ,
.
, , .
, . ,
, . , Apache, , , .
. Apache,
(. . ). .
, 127.0.0.1.
, , ..
?
PHP- .
: php.exe -f index.php | more.
, .
? , , ,
, .
, .
. FTP-
. , , . . 666 777. , .
php,
- ?
- (
, ), . -

201

, . ,
.

.
?
, ,
addslashes (), .
(, ). , .
magic_quotes_gpc
( ON).

?

<?php phpinfo (); ?> ,


, ,
, Web-.

, .

CGI ( $DOCUMENT_ROOT $HTTP_REFERER)
, . ?
, (, ,
"global$DOCUMENT_ROOT;") (.. "$GLOBALS ["DOCUMENTROOT"] " ) .
HTML- <form>?
,
- PHP-,
<input>, <select> <textarea> :

202
<input

name="Array[]">

<input

name="Array[]">

<input name="Array[] ">


<input

name="Array[]">

,
, .
, :
<input

name="Array[]">

<input

name="Array[]">

<input

name="OtherArray[]">

<input name="OtherArray[] ">


Array OtherArray,
PHP-. :
<inputname="AnotherArray [] ">
<inputname="AnotherArray [] ">
<input

name="AnotherArray[email]">

<input

name="AnotherArray[phone]">

AnotherArray 0, 1, email
phone. , , .

?
.
, ,
: .
- , . - , , . :

PHP .

203

and

for

array()

foreach

as

function

break

global

case

if

cfunction

include ()

class

include_once

const

isset ()

continue

list ()

declare

new

default

ld_function

die( )

or

do

print()

echo()

require ()

else

require_once

elseif

return ()

empty()

static

enddedare

switch

endfor

use

endforeach

var

endif

while

endswitch

xor

endwhi1e

CLASS

eval

FILE

exit ( ) _

FUNCTION

extends

LINE

204

- ,
, ?

, ,
$ = i n t v a l ( $ a ) ;
100 % , $ . :
""

-> 0

"123" -> 123


"123" -> 123
"123.55" -> 124
,
doubleval (), strval () ..

1. HTOTaKoeHTMLnCSS
HTML (HyperText Markup Language) . ? , , ,
, .


. ,
, .

. .
, , ..
, . , .

. HTML <center>.
.
</center>. , HTML- . :
<center> </center>
HTML:
< >;
, ();

206

, , ;
, , , ..
.
, .
, .
. , , <>, - <hr>, ( ) ..
, .
HTML-
HTML.
(CSS, Cascading
Style Sheets).
,
HTML.

2.

.
if () {}else{} , , .
, , , , , . :
Parse e r r o r : parse error in c:\usr\local\public_html\
host:\virtual\index. phtml on line 2

. .
, , .

2.

207

. , .
:
.
if () {}else{}
. .
.
?> , , .
. ,
, ,
. .
, : $user , $User. . -
.
( , ) : .
.
? , HTTP (HyperText Transport Protocol,
HTML, .. ). , HTTP- ,
, .
HTTP- .
,
, . ,
, ,
.
,
, , , cookie ..

208

.
:
Warning: Cannot add header information - headers
already sent by (output started at /site/name.phtml:3)
on line 5.

,
. ,
CTpoKe(output s t a r t e d at /site/name.phtml:3) , - . , . , HTML-, ,
echo, ,
< ?
,
include -
, PHP-. . header () ( session_start (),
setcookie ()) .
.

3.

addslashes . : string addslashes (string s t r ) ;
,
.. : ('),
("), (\) .
chop . : string
chop (string s t r ) ;
str , .
convert_cyr_string
. : string

3.
canvert_cyr_string (string str,

209
string- from,

string

t o ) ; from to , . :
k koi8-r;
w windows-1251;
i iso8859-5;
a x-cp866;
d x-cp866;
m x-mac-Cyrillic
echo . :
echo {string a r g l , s t r i n g [argn] . . .) ; . ( ),
. :
<?

echo ", !"; /* ",


" */?>
<?
echo " .
.";
:
<?
$=

5;

$=

3;

$=

4;

$d. = $ + $ - $;
echo $d;

210

4.

echo "$d";
?>

$
explode . :
array explode (string- separator, string string [,
i n t l i m i t ] ) ; , , separator. limit .
:
$pizza = "piecel piece2 piece3
piece6";
5pieces = explode(" ", $ p i z z a ) ;

piece4

piece5

g e t m e t a t a g s . :
array getmetatags (string filename, int [use_include_path]) ;
filename, . :
<meta name="author" content="name">
<meta n a m e = " t a g s " c o n t e n t = " p h p 3 d o c u m e n t a t i o n " >
name , content ,
.
'_', . use_include_path 1 ,

inclucfe.

3.

211

htmlentities
HTML. : string htmlentities (string string);
htmlspecialchars (),
, HTML
HTML-. ISO-8859-1.
htmlspecialchars
HTML. : string htmlspecialchars
(string string) ;
HTML HTML,
.
. HTML ( , ).
:
& () &;
" ( ) &quot;
< ( ) &lt;
> ( ) &gt.
, ,
.
htmlentities ().
imp I ode . : string implode(array pieces, s t r i n g glue) ; ,
, glue
.
:
$array = array("lastname",
$a = implode(",",
echo $a;

$array);

"email",

"phone");

212

:
lastname,email,phone

j o i n implode
I t rim . :
string Itrim(string str) ;

n l 2 b r HTML-
. : string nl2br (string
string); string <br>,
.
p a r s e _ s t r . :
void parse_str (string s t r ) ; str,

URL- , .
:
<?php
$str = "first=value&arr[]=foo+bar&arr[]=baz";
parse_str($str) ;
echo $ first; / / value
echo $arr[O]; / / foo bar
echo $ a r r [ l ] ; / / baz
parse_str {$str, $output) ;
echo $ output [* first' ]; / / value
echo $output['arr'] [0]; / / foo bar
echo $ output ['arr'] [ 1]; / / baz
?>
print . : print {string
arg) ; echo.

rawurldecode , % . :
string rawurldecode(string s t r ) ; ,
admin%201og%40name admin log@name.

3.

213

s t r l e n . : i n t
strlen (string s t r ) ; :
<?pbp
$str = "abcdef";
echo strlen($str) ;

6.
s t r _ r e p l a c e . : mixed
str_replace(mixed

search,

mixed

replace,

mixed

s u b j e c t ) ; search
subject replace
.
:
$string = " ";
$strnew = str_replace("", "",

$string);

$strnew
.
strcmp (). : int strcmp (string s t r l , string str2) ;
<0, s t r l str2;. > 0, s t r l
str2, 0, . ,
.
s t r i p s l a s h e s . :
string

stripslashes

(string

s t r ) ;

str . (\" " ..).


\\ \. :
<?php
$str = " \"?";
echo stripslashes ($str);
?>
:
'?

214

strrpos
. : i n t strrpos (string haystack,
char needle) ; needle haystack. , needle . needle
, .
needle , false.
needle ,
.
strrchr .
: string strrchr (string haystack, string
needle) ; haystack, needle haystack. false, needle
. needle , . needle
, . :
// $
$dir = substr( strrchr( $, ":" ), 1 ) ;
/*
*/
$text = "Line l\nLine 2\nLine 3";
$last = substr ( strrchr ( $text, 10 ), 1 ) ;

strrev . : string
strrev(string string); :
<?php
e c h o s t r r e v ( " , ! " ) ;

:
!,
s t r s t r . :
s t r i n g s t r s t r ( s t r i n g haystack, s t r i n g needle) ; haystack needle

3.

215

. n e e d l e ,
f a l s e . needle , .
:
<?
$address = "autc@yandex.ru";
$ = s t r s t r ( $ a d d r e s s ,
"@");
echo $a;

:
@yandex.ra
strtok . : string
strtok(string argl, string arg2); ,
This is an example string ,
:
$string = "This is an example string";
$tok = s t r t o k ( $ s t r i n g , " ") ;
while($tok) { echo "Word=$tok<br>"; $tok = strtok(" ");}
:
This
is
an
example
string

,
strtok . strtok ,
.
, strtok -

216

.
.
.
, 0. .
strtolower . : string strtolower (string s t r ) ; s t r i n g ,
. , .
:
<?php
$ = " ";
$ = strtolower($a);
echo $a;
:


strtoupper . : string strtoupper(string string);
s t r i n g , . ,

.
:
<?php
$ = " ";
$ = s t r t o u p p e r $ ) ;
echo $a;

3.

217

s t r t r . :
string s t r t r ( s t r i n g str, string from, string t o ) ;
: $addr = s t r t r ( $ a d d r , "", " " ) ;
str, from
to, . from to
,
.
substr . : string
substr(string string, int s t a r t , int [length]);
string, start () length ().
start , , s t a r t
string. :
$rest = substr("abcdef", 1); // "bcdef
$rest = substr ("abcdef, 1, 3); // "bed"
st art ,
, start
string. :
$rest = substr ("abcdef, -1); // "f
$rest = substr("abcdef", -2); // "ef
$rest = substrf'abcdef", - 3 , 1); // "d"
length , length
start. ( ),
start. length , length string.
,
start. :
$rest = substrf'abcdef", - I , -1); // "bede"

218

trim . : string trim (string s t r ) ;


ucfirst . : string ucfirst (string str) ;
str, . , .
:
$ = ", ! " ;
$ = u c f i r s t ( $ f o o ) ;
:
, !

ucwords . : string ucwords (string


str);
str, .
:
$foo = ", ! " ;
$foo = ucwords($foo) ;
:
, !


basename . : string basename (string p a t h ) ; ,
, . Windows (/) (\) .
(/).
$path= " /home/httpd/html/index.php3";
$file = basename($path); /* $file
"index.php3"*/

3.

219

. : int copy (string


source, string dest) ; true , false. :
if

(!copy($file,

$file.'.bak'))

print("
. . . < b r > \ n " ) ;

$file

, $file
, :
$file ...
dirname , . : string dirname (string path) ;
, ,
, . Windows
(/) (\)
. (/).
:
$path = "/etc/passwd";
$file = dirname($path) ; // $file " / e t c "
fclose . : int
fclose (int fp); ,
fp . true false .
,
fopen () fsockopen ().
feof , .
: int feof(int fp); true,
EOF (End Of File, ) . false.
, fopen (), () fsockopen ().

220

fgetc . : string
fgetc(int fp); , , fp. EOF false. , fopen (), (),
fsockopen().
fgets . :
string fgets (int fp, int length);
length ,
fp. , length , ,
EOF. .
false.
, fopen (),
() fsockopen ().
fgetss HTML-. : string
fgetss(int fp, int length); fgets (), , HTML- PHP-
.
file . :
array file {string filename); ( ) .
fileatime . : int fileatime (string filename); false .
filectime
Unix. : int filectime (string filename);
false .
Unix.
f i l e e x i s t s .
: int file_exists(string filename); true, , filename, ; false. ,

3.

221

,
.
:
<?php
$filename = "/path/to/my.txt" ;
if (file_exists ($filename) ) {
print " $filename ";
} else {
print " $filename ";

, ,
:

my.txt

my.txt
filemtime , Unix. : int
filemtime (string filename) ; false
. : $filename = "my.txt"; my.txt.
filesize . : int filesize (string
filename); false .
filetype . : string
filetype (string filename); false. : fifo, char, dir, block, link, file, unknown.
fopen URL. : i n t
fopen (string filename, string mode); filename
" h t t p : //" ( ),
HTTP- .
. filename

222

" f t p : / / " ( ), FTP- .


FTP, . , FTP
( ). filename - ,
, .
, false. mode
:
,
;
+ , ;
w ,
.
, ;
w+ , .
, ;
,
. ,
;
+ , . , .
:
$fp = f open ( " /home/rasmus/f ile . txt" , " r " ) ;
$fp = fopen("http://www.php.net/", " r " ) ;
$fp = fopen("ftp://user:password@example.com/", "w") ;

, ,
-

3.

225

. Windows
, , :
$fp = f o p e n ( " c : \ \ d a t a \ \ i n f o . t x t " ,

"r") ;

fpassthru . : int fpassthru (int fp) ; EOF


. false. , fopen (), () fsockopen ().

fputs . : int fputs (int


fp, string str, int [ l e n g t h ] ) ; fputs () fwrite ().

fread . :
string fread (int fp, int l e n g t h ) ; , fp length. , length EOF.

fseek . : int
fseek(int fp, int offset); fp offset .
fseek (fp, offset,
SEEK_SET).npH 0, 1. EOF . , fopen(),
" h t t p : / / " " f t p : / / " .

fwrite . :
int fwrite(int
fp,
string s t r i n g ,
int
[length]);
string , fp. length , ,
length, s t r i n g .
length,
magic_quotes_runtime string .

224

i s d i r ,
. : bool i s d i r (string filename);
true, filename .
isexecutable , . : bool isexecutable (string
filename) ; true, filename
.
is file ,
. : bool is file (string filename);
true, filename
.
i s l i n k ,
. : bool i s l i n k (string filename) ;
true, filename .
isreadable , . : bool i s r e a d a b l e (string
filename) ; true, filename
. , ,
.
iswriteable , . : bool i s r e a d a b l e (string
filename); tru e, . ,
, .
link

. : int

link{string target,

string link);

mkdir . : i n t mkdir
(string pathname, int mode); , pathname. ,
mode ,
0. :
mkdirC/path/to/my/dir",

0700);

3.

225

true .
pclose , (). : int pclose (int
fp) ; ,
pf . , ().

read file
. : int readfile (string
filename) ; . false
readfile @,
. filename " h t t p : / / " (
), HTTP- .
. filename "ftp: //" ( ), FTP- . ftp,
. filename
- ,
.

re ad link . : string readlink (string p a t h ) ; readlink


path 0 .

rename . : int
rename (string oldname, string newname) ; , oldname newname.
true false
.

rewind .
int rewind (int fp);
fp .

226

0. ,
fopen ().

rmdir . : int rmdir


(string dirname) ; ,
dirname.
. 0.
stat . : array
stat (string filename);
filename , , :

device ();
number of link ( );
user ID owner (ID );
group ID owner (ID );

size in bytes ( );
time of last access ( );
time of last modification ( );
number ofblocks allocated ( ) ..
Is tat
. : array lstat (string filename) ;
filename. stat (),
filename lstat ,
, ,
.
, ,
stat.
symlink . : int
symlink(string target, string link) ; , target, , link.

3.

227

tempnam . :
string tempnam(string dir, string prefix);
. , tempnam () .
.
touch . : int touch(string filename, int time); filename time. time , . , .
true false .
cookie
setcookie ("name", $data, $y) cookie
name $data. $ , cookie
. $ mktime.
setcookie ("name") cookie name. , ,
cookie, cookie, $data
$ .

sessiondestroy . : bool sessiondestroy(void) ; cookie,


. true ,
false.
s e s s i o n i s r e g i s t e r e d ,
. : bool
session is registered(string name);

228

s e s s i o n r e g e n e r a t e i d ID
. : bool
s e s s i o n r e g e n e r a t e i d ( v o i d ) ; true
, false
.
session_register . : bool
s e s s i o n r e g i s t e r (mixed name); true,
.
session_start , SID, cookie POST GET. : bool
s e s s i o n s t a r t (void); true.
cookie,
sessionstart

,
.
s e s s i o n w r i t e c l o s e . : void
sessionwriteclose
(void);
sessionunregister
name . : bool
sessionunregister (string name); true
.
sessionunset
. : void sessionunset (void)

array_sum . : mixed arraysum (array array); , ..
. :
$ = array (5,7,10,1) ;
echo array_sum($a);
23.

3.

229

count .
: int count (mixed var [, int mode]) ;
, . :
$[]

= "Hello";

$[1]

= 3;

$[2]

= 5;

$[3]

= "World";

$result = count($time);
echo

$result

4.
i n a r r a y . : bool i n a r r a y (mixed needle, array
haystack[,bool s t r i c t ] ) ; true, needle haystack,
false. bool
strict true,
needle. :

$new = array("Hello", "NTT", "World", "New");


if

(in_array

("NTT",

$new))

{
print

" NTT $new \

i n a r r a y true,
,
" NTT array "
end . : mixed end ( array array).

230

next
(.. )
,
false, .
, false
. : mixed next ( array a r r a y ) .
p r e v
(.. ) false, .
, false. : mixed prev ( array array).
r e s e t . : mixed reset ( array a r r a y ) ;
c u r r e n t , . :
mixed c u r r e n t ( array array) ;
. , c u r r e n t ( ) false.
(0 ),
false .
s o r t , . : bool sort ( array array)
:
<?php
$animals = array ("dog", "camel", "cat", "giraffe");
sort($ animals);
reset($animals);
while (list($key, $val) = each($ animals)) {
echo "fruits[" . $key . "] = " . $val . "\n";

:
animals

[] = carrel

anirnals

[1] = c a t

3 . PHP

231

animals [2] = dog


animals [3] = giraffe
rsort ( ) . : bool rsort ( array array) ;
:
<?php
$animals=array("dog", "camel", "cat", "giraffe");
rsort($animals);
reset($animals);
while (list($key, $val) = each($animals)) {
echo "$key = $val\n";

:
0

giraffe

dog

cat

3 = camel


checkdate /. : b o o l c h e c k d a t e ( i n t month, i n t day,
int
y e a r ) ; t r u e , ,
false.
date / . : $date
= date ("") ; ,
. :

am

"AM" "";
. AM (Ante Meridiem) , (Post Meridiem) . {. .)

232

d , , (
);
D , , , " F r i " ;
F , , , "January";
h , , 12- , ;
, , 24- , ;
i , , ;
j , , ;
1 ( L) , , , "Friday";
m , ;
, , , " J a n " ;
s , , ;
S , , , " t h " , "nd" 1 '
U Unix, .. 1 1970 ;
Y , , ;
w , , "0" ;
, , ;
z , , "299".
, , d D.
mktime Unix,
, Unix (1 1970 ) .
: int mktime (int hour,
int minute,
int
second, int month, int day, int year) ; :
,
second (), seventh (). (..)

4. Cookie
mktime(O,O,O,

233

12,31,1997);

, 1970 0:00 31 1997 .


time ,
Unix. : int time (void) ;

4. Cookie
Cookie , . ,
, . , cookie 4 , cookie,
, cookie - , . , ,
...
, , .

cookie,
. , cookie , . cookie,
.
cookie ,
setcookie. :
set cookie ("",

"");

,
setcookie("name",

"12345");

234

, $name
, 12 345, :
isset

($name);

, .
,
cookie - ( ) ( ),
HTML-. , :
<html>
... cookie...
:
... cookie...
<html>
... ...

, . ,
cookie.
, cookie,
, . :
if (isset ($name)) { ,
} else { , }
,
cookie , ,
. , . cookie.
, cookie . one-

5.

235

setcookie, cookie , ,
:
$y = mktime(0,0,0,l,l,2005) ;
setcookie("name", "bret", $y) ;
$ , 1 1970 (. 6). ,
mktime (). : , , , ,
. , 1.01.1970. cookie ( , ) 1 2005 .
cookie
, s e t c o o k i e
cookie :
setcookie("name") ;

5.
POST GET
POST , ,
, ,
, .. .
GET , . , ,
index.phtml:
http://myhost.ru/index.pht ml? temp=l&qwe=slovo
, ,
. index.phtml $temp $qwe .

236

6. Unix
-, ,
, . Unix. 1 1970 .
,
.. ,
, , .
, Unix , 1 1970 .
mktime. :
mktime(int hour, i n t minute,
i n t day, i n t year)

int

second,

i n t month,

:
mktime(0,0,0,12,31,1997);
, 1 1970 0:00 31 1997 .

scanned and converted to PDF including Bookmarks


!

:
..
.
.
..
..
02.04.2004.
60x84 ]6 . .
. . . . 13,95. .-. . 10,86.
. 2551
.
310 01.07.2003. , . , . 28, . 112.
: 220050, , / 79.
/: (10-375-17) 211-50-38. E-mail: nk@wnk.biz
:
, ., . 2.
(095) 234-58-53. E-mail: ru@wnk.biz
http://wnk.biz

.
210015, , . -, 4.

Flash MX 2004
ActionScript 2.0:


.. , ..
446 , .

Flash MX 2004 ActionScript 2.0 , . ,


,
-. ActionScript 2.0 .
, Flash
.
ISBN 5-94735-035-1

:
: (095) 234-58-53, e-mail: ru@wnk.biz
: (10-375-17) 211-50-38, e-mail: nk@wnk.biz

,
, ?
, .
:



,
PHP- !

?
. , .
": "

ISEN 985-475-050-7

9 789854

750507

http://wnk.biz

Вам также может понравиться