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

..

PHP MySQL

2010

..

004.738.5
32.973.26-018.02
-


:
..
.

.. PHP MySQL/ ..
: , 2010. 108 .

-
" "
,
-.

web- Apache, PHP
MySQL.


: http://kek.ksu.ru/EOS/ITE/index.html


, 2010
.., 2010

PHP MySQL

..................................................................................................... 3
................................................................................................... 5
1.
............................................................................................................ 6
HTML ................................................................................................. 12
................................................................................................... 12
.............................................................................................................. 15
.................................................................................................................. 17
2. .......................... 20
ER- ........................................................................................................... 20
........................................................................................ 21
MYSQL...................................................................................... 23
PHP................................ 26
PHP.................................................................................................. 26
PHP........................................................................... 27
...................................................................................................... 29
........................................................................................................ 31
..................................................................................... 33
.............................................................................................................. 35
............................................................................................................. 36
................................................................................................................. 38
3. ......... 41
............................................................................................................. 41
............................................................................................. 44
4. ... 45
PHP MYSQL...................................................................................................... 45
................................................................... 47
.......................................................... 49
..................................................................................... 50
5. ................................. 54
COOKIES ................................................................................................................ 54
...................................... 56
............................................................................................. 58
......................................................................... 60
........................................................ 61
3

..

........................................................................... 62
6.
................................................................. 63
....................................................................................................... 63
................................................................................................................. 67
...................................................................................................... 67
7. .............................................. 74
: - XML .............. 78
........................................................................... 80
1. ...................................................... 81
(HEADER.PHTML)............................................ 81
(FOOTER.PHTML)................................. 82
(INDEX.PHTML) .................................................................... 82
(CONNECT.PHTML)........................ 83
(CATALOG.PHTML) ........................ 83

(SHOW.PHTML) ........................................................................................................ 84
(BASKET.PHTML)................................................................ 85
(DOBASKET.PHTML).......................................................... 87
(REG.PHTML) .................................................................................. 88
(AUTO.PHTML)................................................................................ 90
(CABINET.PHTML).................................................................... 91
(CHANGE.PHTML) .................................................. 93
(EXIT.PHTML) .................................................. 94
(ORDER.PHTML)....................................................................... 94
(DOORDER.PHTML) ................................................................... 95
- XML (PRICE.PHTML) ................................................... 97
2. PHP ..... 98
.................................................................................... 98
............................................................................................................. 100
................................................................................................................ 101
PHP ......................................................................................... 103
3. PHP MS IIS ................................. 106
................................................................................................... 107

PHP MySQL


.
, ..,
,
.
,
,
.

web-
Apache, PHP
MySQL. :
1. ;
2. ;
3. ;
4. ;
5. ;
6. ;
7. .

. ,
HTML.
PHP.
C , , "
" ,
SQL.
,
.

..

1.
.
, .
,
,
.

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

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

. .
,
.
1,
. 2-6.

PHP MySQL
1.


(
).
,
.
2.


" ".
.
7

..


" ",
" "
"". , " ".


.
3.

,
. (
) " ".
4.


.
8

PHP MySQL

,
, ..

(, ).
5.

, ,
, ..,
. / ,
. ,
(, , e-mail ..)
, .
6.

..

HTML- :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> </title>
</head>
<body background="EULA.jpg" style="background-repeat:repeat-y"
leftmargin="130" rightmargin="5" bgProperties=fixed>
<table border="0" align="right" width="90%" cellpadding="0"
cellspacing="0">
<tr><td>
<table border="0" align="right" width="100%" >
<tr>
<td align="center" bgcolor="#cccccc">
<form action="auto.phtml" method="post">
<table>
<tr><td align="right"><font size=-2>:</font></td>
<td align="left"><input type=text style="width:60; height:20;"
name=login></td></tr>
<tr><td align="right"><font size=-2>:</font></td>
10

PHP MySQL
<td align="left"><input type=password style="width:60;
height:20;" name=pass>
<input type=submit value=ok style="height:20;"></td></tr>
</table>
</td>
</form>
<td colspan="4" align="center" bgcolor="#ccccff">
<font face="Arial" size="+3"><i><b>
</b></i></font></td></tr>
<tr><td align="center" bgcolor="#aaddff" width="20%">
<a href="catalog.phtml"><b></b></a></td>
<td align="center" bgcolor="#ddaaff" width="20%">
<a href="basket.phtml"><b></b></a></td>
<td align="center" bgcolor="#aaaaff" width="20%">
<a href="reg.phtml"><b></b></a></td>
<td align="center" bgcolor="#ffaaff" width="20%">
<a href="order.phtml"><b></b></a></td>
<td align="center" bgcolor="#aaffee" width="20%">
<a href="exit.phtml"><b></b></a></td>
</tr>
</table>
</td></tr>
<tr><td align="center">Welcome!<font face="Arial"
size="+2"><i></i></font><br>
</td></tr>
<tr><td>
<center><h2><font color="#555599"><br>
! <br><br>
.
!
, , ,

- !</font></h2></center>
</td></tr>
<tr><td><center><hr><br>
<a href="index.phtml"> </a></center></td></tr>
</table>
</body>
</html>

web- HTML,
.

11

..

HTML

HTML (HyperText Markup Language)
,
.
. .
,
. HTML-
:
<html>
<header>
<title> </title>
</header>
<body> </body>
</html>

, <html></html>
. (<header>, ,
, <title>)
(<body>).
HTML, ,
, .
:
<b> </b>
<i></i>
<u></u>
: <sub>i</sub>
: <sup>i</sup>
<center></center>


: i
: i

<br> (
).
<hr> (
).
12

PHP MySQL

:
<h1></h1> ( ) <h6></h6> ( ).

:
<ul>
<li>

<li>

<li>

</ul>
<ol>
<li>
<li>
<li>

1.
2.
3.

</ol>

.
( ) . , ,
<body bgcolor="red">

(),
<body background="EULA.jpg">

,
( ,
, HTML-).
.
<body background="EULA.jpg" leftmargin="130" rightmargin="5"
bgProperties=fixed>

13

..

leftmargin="130" rightmargin="5"
( ),
bgProperties=fixed , ..,
.
:
<font face="Arial" size="+2" color="green">

, Arial
2 , .
, #rrggbb, rr,
gg bb ,
, , .
, #000000 , #ffffff , #ff0000 , #880088 - ( ).
<img>, ,
<img src="Logotype.gif" alt=" " width=300 height=300>

src ,
HTTP-, :
<img src="http://kek.ksu.ru/EOS/ITE/Logotype.gif">

alt ,
.
,
, <a>
"". ,
<a href="http://kek.ksu.ru/index.html">
</a>
14

PHP MySQL

,
( ) ,
, href.
,
, :
<a href="basket.phtml"></a>


:
href="?1=1&2=2" , ,
<a href="basket.phtml?type=1&id_Book=25"> </a>

.

PHP.

,
HTML- , , .
,
( ).
<table></table>.
:
border ( 0, ),
align

("right",

"left" "center"),
width
("100%") ("500"),
bgcolor .
, , 80%
:
15

..
<table border="0" align="right" width="80%">

<tr></tr>.
<td></td>.
,
align, width bgcolor.
,
: , colspan=3 3
, rowspan=2 2 .
, ,

8:00-12:00
12:00-16:00
8:00-12:00
8:00-12:00
12:00-16:00
9:00-13:00


<TABLE BORDER=1 WIDTH=100%>
<TR><TD COLSPAN=2 ALIGN="CENTER"></TD>
</TR>
<TR><TD ALIGN="RIGHT" WIDTH="50%"></TD>
<TD WIDTH="50%">8:00-12:00</TD></TR>
<TR><TD ALIGN="RIGHT"></TD>
<TD>12:00-16:00</TD></TR>
<TR><TD ALIGN="RIGHT"></TD>
<TD>8:00-12:00</TD></TR>
<TR><TD ALIGN="RIGHT"></TD>
<TD>8:00-12:00</TD></TR>
<TR><TD ALIGN="RIGHT"></TD>
<TD>12:00-16:00</TD></TR>
<TR><TD ALIGN="RIGHT"></TD>
<TD>9:00-13:00</TD></TR>
<TR><TD ALIGN="RIGHT"></TD>
<TD></TD></TR>
</TABLE>

16

PHP MySQL

web- : ,
, ..
,
.
: -,
,
; -,
. ,
, .
HTML , .
(<form> </form>),
( , , , , ).
:

method (GET POST),

( GET
, , POST
);

action ,

Submit ( . ).
.
.
:
<input type="text" name="login"> - ;
<input type="password" name="pass"> - ,

"".
<input type="hidden" name="id_book"> - ,

, ,
.
17

..

:
<input type="button" name="mybutton" value="OK"> - ;

<input

type="reset"

name="reset"

value="">

;
<input type="submit" name="submit" value=""> -

: web, action ,
.
:
<input type="checkbox" name="cCard" value="1">

, ""
"". ,
. ,
checked.
:
<input type="radio" name="rCard" value="1" checked >Visa
<input type="radio" name="rCard" value="2">MasterCard
<input type="radio" name="rCard" value="3">American Express

- .
, , .
checked,
.
:
<select size="1" name="sCard">
<option value='1' selected > Visa </option>
<option value='2'> MasterCard </option>
<option value='3'> American Express </option>
</select>
18

PHP MySQL

- 3- .
selected.
,
PHP.
, ,
. style,
.
.
CSS ( ).
,
Web- (http://kek.ksu.ru/EOS/TESTS/index.html)

19

..

2.
ER-

.

(). , ,
. " ".

, .
" ",

20

E-mail

PHP MySQL

,
,
. ,
.
, .
, "
".
.
,

.


ER- .
.
(, ,, , , , , )
.
(, ) -
.
(, ) -
.
(, , , )
. .., ,
.
(, , , )
.
21

..

(, , )
(, , , , E-mail, , ,
)

22

PHP MySQL

MySQL
MySQL () .
,
Hughes Technologies Mini SQL (mSQL).
MySQL :
1. ,
Setup.exe MySQL - (,
:\MySQL).
2. ,
. ,
.
WinMysqlAdmin.exe .
: , .
3. MySQL - C:\MySQL\BIN\mysql.exe.
,
MySQL.
, :
1. CREATE DATABASE _;
( !),
2. USE _; ,
3. CREATE TABLE ...; ,
4. INSERT INTO ...; ,
-, MySQL
source __ (
!).
MySQL,
, SQL, , ..,
23

..

, , mySQL,
(http://kek.ksu.ru/EOS/PHP/mySQL/index.html).

.

create database books;


use books;
create table publishers
( id_publ int(5) primary key auto_increment,
name_publ varchar(50));
insert
insert
insert
insert
insert

into
into
into
into
into

publishers
publishers
publishers
publishers
publishers

(name_publ)
(name_publ)
(name_publ)
(name_publ)
(name_publ)

values
values
values
values
values

("");
("BHV");
("");
("");
("Que");

create table categories


( id_cat int(5) primary key auto_increment,
name_cat varchar(50));
insert into
values
insert into
values
insert into
values
insert into
values
insert into
values

categories (name_cat)
(" ");
categories (name_cat)
(" ");
categories (name_cat)
("");
categories (name_cat)
(" ");
categories (name_cat)
("");

create table books


( id_book int(5) primary key auto_increment,
name_book varchar(100),
id_publ int(5),
id_cat int(5),
author varchar(50),
pages int(4),
price int(4),
dat int(4),
image varchar(50)
);
insert into books
(name_book,id_publ,id_cat,author,pages,price,dat,image) values
24

PHP MySQL
("Ajax ", 4, 1, " , ,
", 640, 200, 2006, "1216642298_145214.png");
insert into books
(name_book,id_publ,id_cat,author,pages,price,dat,image) values
("Microsoft Visual Studio 2008", 2, 1, " ., .",
1192, 400, 2009, "4a98c94faa176.jpg");
insert into books
(name_book,id_publ,id_cat,author,pages,price,dat,image) values
(" Ajax", 1, 1, " ", 425, 300, 2008,
"1224319675_izuchaem-ajax.jpg");
insert into books
(name_book,id_publ,id_cat,author,pages,price,dat,image) values
(" - Rails", 1, 1, ".
, . . ", 720, 400, 2008,
"1217485667_1000657293.jpg");
insert into books
(name_book,id_publ,id_cat,author,pages,price,dat,image) values
("Microsoft Visual C# ", 2, 1, ". ",
314, 140, 2006, "4a3de5b9e8517.jpg");
create table basket_books
( id_bask char(15),
id_book int(5),
kolvo int(2),
date_bask date);
create table customers
( id_cust int(5) primary key auto_increment,
fam varchar(30),
im varchar(30),
addr varchar(100),
mail varchar(30),
login varchar(10),
pass varchar(10),
subscribe int(1));
create table orders
( id_order char(15),
date_ord date,
id_cust int(5),
dostavka int(1),
bonus int(5));
create table order_books
( id_order char(15),
id_book int(5),
kolvo int(2));

25

..

PHP
PHP
PHP 1995 ,

.
Perl, Internet-
,
.
Personal Home Page,
,
,
, PHP Hypertext Processor.
PHP 2.0, C.
3.0 . PHP -
web-,
,
, .
NETCRAFT (http://www.netcraft.com) PHP 1 000 000
.
, Perl, , Java,
web- - ,
, . 4.0
, ,
PDF-, ,
XML, ..
PHP ,
web- HTML- PHP. PHP- HTML-,
<? ?>.
. PHP-.
,
. print
echo, HTML-.
26

PHP MySQL

,
. ,

.

PHP
PHP web-: Apache, Microsoft
IIS(PWS), Netscape Enterprize Server, Stronghold, Zeus , ,
: Unix, Solaris, FreeBSD, Windows 9x/NT/XP.
PHP Windows+Apache
( , web-,
,
).
, Apache.
Apache, Windows,
. (
)
, .
apache.exe, - apache.exe -k
shutdown. Apache C:\Program
Files\Apache Group\Apache.
httpd.conf
( CONF) .

ServerAdmin yourname@yoursite.com

. ,
.

localhost:
ServerName localhost

Apache .
http://localhost.
27

..

,
Apache.

PHP. PHP
, , C:\PHP.
php.ini-dist ( 3.0
php3.ini-dist). PHP,
" PHP"
:\WINDOWS php.ini ( 3.0 php3.ini).
php4ts.dll Msvcrt.dll
C:\WINDOWS\SYSTEM. Msvrt.dll ,
.
httpd.conf.
, ScriptAlias.

ScriptAlias /php4/ "C:/php/"

PHP.
AddType. ,
,
AddType application/x-httpd-php .phtml .php
AddType application/x-httpd-php-source .phps

, PHP-
phtml php.
Action.
Action application/x-httpd-php /php4/php.exe

,
PHP-.

apache .
PHP.
phtml, ( ""):

28

PHP MySQL
<?
while (list($var, $value)=each($GLOBALS))
{
print "<br>$var => $value";
}
?>

( <? ?> HTML-)


HTDOCS - Apache.
http://localhost.
.
. ,
Apache, PHP
MySQL. ,
!


PHP :







, C,
(1, 16, 255), (01, 020, 0377)
(0x1, 0x10, 0xff).


(1.5, 0.999) -
(0.15e1, 9.99e-1).
29

..

.
, , ,
, :
$year=2007;
$today="6 $year ";
print $today;

: 6 2007 .
, ,
, , \n, \t, \r ..

, true
false.

, PHP ,
:
$month[0]="";
$month[1]="";
$month[2]="";

,
:
$month[]="";
$month[]="";
$month[]="";

array:
$month=array("","","");

, PHP ,
:
$capital[""]="";
$capital[""]="";
$capital[""]="";

array /:
$capital=array(""=>"",
""=>"",
""=>"");
30

PHP MySQL

.

.

class :
class Light
{
var $isOn;
function click($OnOff)
{$this->isOn=$OnOff;}
}

, -
var,
this. JavaScript.
- new.
$bulb = new Light;

PHP $.
,
. .
.
.
, .., PHP
.
var.
.
,
GLOBAL:
GLOBAL $x;
31

..

$GLOBAL:
$GLOBALS["x"];

STATIC:
STATIC $count=0;

(juggling)
, . ,
,
, .

, .
,
(casting). ,
( , ):
int integer;
real, double float;
string;
array;
object.
, (..,
) .
,
scalar.
:
$x=0;
$y=&$x;

$y $x, $y,
$x.
$GLOBALS, ,
.
,
:
while (list($var, $value)=each($GLOBALS))
32

PHP MySQL
{
print "<br>$var => $value";
}

$
, ..,
. :
$first="something";
$second="first";
print $($second);

? , "something".

. ,
unset:
unset ($MyArray);


PHP ( C Perl):

()

new

! NOT ~

++

--

@
/

, ,

, ,

=>

, , ,

== === != <>

, ,

<<
<

>>
<=

>

33

..

, ,

?:

= += -= /= %= *=
.= &= |= <<= >>=

AND

, ,

/* */

&
&&

//

|
||

XOR

OR

2 :

if () {

}
else {

if () :

else :

endif;

while () {

while () :

endwhile;

do {

} while ();

do :

while ();

for (;
;
)
{

for (;
;
)
:

endfor;

( )
foreach ($ as $) {
34

foreach ($ as $) :

PHP MySQL

endforeach;

foreach ($ as $ =>
$) {

foreach ($ as $ =>
$) :

endforeach;


switch () {
case (1):

case (2):

...
case (N):

default:

switch () :
case (1):

case (2):

...
case (N):

default:

endswitch;

break;

continue;

print ;
echo ;

PHP ,
, .
PHP
XML (
-!).
,
extensions
35

..

php.ini ( . PHP). ,
.
PHP :
function _ ([$1, $2, ..., $N])
{
_
[return [_];]
}

PHP , ..
( , , ).
.
, ,
$.
function english()
{ print "Good morning!"; }
function french()
{ print "Bon matin!"; }
$language="french";
$language(); // french

. " ".
.
.
, , .

array array ([1, 2,
..., N])

void list (1 [,2,


... , N])


(
),

36

PHP MySQL
array range (int _, int
_)

int array_push (array ,



1 [, 2,..., N])
void array_pop (array )

void array_shift (array )

void array_unshift (array ,



1 [, 2,..., N])
array array_reverse (array )

array array_merge (array 1,


array 2,... ,array N)

array array_slice (array 1, int "" ,


[, int ])


bool in_array (, array )

reset (array )

array each (array )

void end (array )

next (array )




;
,

prev (array )



37

..

; ,


int sizeof (array )

int count ()

,
;
,
1;
, 0

array array_count_value (array


)

sort
rsort
asort
arsort
ksort
krsort
usort
uasort
uksort


- ,

void shuffle (array )

( )

PHP.
,
.
string trim (string )

\n, \t,
\v, \b

int strlen (string )

38

PHP MySQL
int strcmp (string 1,
string 2)

0,
,
( C)

int strcasecmp (string


1, string 2)

0,
,
( C),

void parse_str (string


)


"="
.

, URL.

array explode (string


, string [,
int ])

,
,

string implode (string


, array )


,
(

".")

int strpos (string ,


string [, int
])



( false,
)

int strrpos (string ,


string )



( 0, )

string str_replace (string



, string

_, string )
string substr (string ,
int [, int ] )

int substr_count (string


, string )

string strtolower (string


)

string strtoupper (string


)

string ucfirst (string )


39

..

string ucwords (string )

HTML .

40

PHP MySQL

3.

, web-,
web-, .

,
, .

include require.
include (string _)
include_once (string
_)

.

.
,

if-else,
<?
if ($user=="admin')
{
include("adminMenu.phtml");
}
else {
include("guestMenu.phtml ");
}
?>

, , ,
, , .

require (string _)

require_once (string
_)


- .
if
,
.
require,

.
,

41

..

,
- .
<? include("shapka.phtml"); ?>
HTML-
<? include("bottomMenu.phtml"); ?>

,
.

,
, .
, "Welcome!", "",
"" ...,
. PHP-

$color $title,

,
.
, header.phtml

42

PHP MySQL
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> </title>
</head>
<body background="EULA.jpg" style="background-repeat:repeat-y"
leftmargin="130" rightmargin="5" bgProperties=fixed>
<table border="0" align="right" width="90%" cellpadding="0"
cellspacing="0">
<tr><td>
<table border="0" align="right" width="100%" >
<tr>
<td align="center" bgcolor="#cccccc">
<form action="auto.phtml">
<table>
<tr><td align="right"><font size=-2>:</font></td>
<td align="left"><input type=text style="width:60; height:20;"
name=login></td></tr>
<tr><td align="right"><font size=-2>:</font></td>
<td align="left"><input type=password style="width:60;
height:20;" name=pass>
<input type=submit value=ok style="height:20;"></td></tr>
</table>
</td>
</form>
<td colspan="4" align="center" bgcolor="#ccccff">
<font face="Arial" size="+3"><i><b>
</b></i></font></td></tr>
<tr><td align="center" bgcolor="#aaddff" width="20%">
<a href="catalog.phtml"><b></b></a></td>
<td align="center" bgcolor="#ddaaff" width="20%">
<a href="basket.phtml"><b></b></a></td>
<td align="center" bgcolor="#aaaaff" width="20%">
<a href="reg.phtml"><b></b></a></td>
<td align="center" bgcolor="#ffaaff" width="20%">
<a href="order.phtml"><b></b></a></td>
<td align="center" bgcolor="#aaffee" width="20%">
<a href="exit.phtml"><b></b></a></td>
</tr>
</table>
</td></tr>
<tr><td align="center"
bgcolor=<?print $color?>><font face="Arial" size="+2">
<i><?print $title?></i></font><br>
</td></tr>

43

..

footer.phtml "
" .
<tr><td><center><hr><br>
<a href="index.phtml"> </a></center></td></tr>
</table>
</body>
</html>


,
.

<?
$title="Welcome!";
$color="#ccccff";
include("header.phtml");
?>
<tr><td>
<center><h2><font color="#555599"><br>
! <br><br>
.
!
, , ,

- !</font></h2></center>
</td></tr>
<? include("footer.phtml"); ?>

,
, ,
,
. ,
, , ,
.

44

PHP MySQL

4.
PHP MySQL
ySQL PHP .
, .
1.

int mysql_connect (string
,
_ [:] [, string
[, string ]]) , .

,
mysql_connect("localhost", "root", "") or
die (" MySQL!");

, , mysql_connect 0,
- die
.
2.
int mysql_select_db (string
_ [, int
_])

,
,
- .
,
.

,
mysql_select_db("mycross") or
die (" ");

, , mysql_select_db 0,
- die
.
3.
int mysql_query (string

,

45

..
[, int _])

-, .
,
.

,
$result=mysql_query("SELECT kod, nazv FROM cross")
or die(" !");

, mysql_query 0,
- die
.
4.
array mysql_fetch_array (int
_)



.
, .

,
while($row=mysql_fetch_array($result))
{
print $row["kod"].",".$row["nazv"]."<br>";
}

.
5. .

int mysql_close ([int


_])


.
,
.

,
mysql_close();

,
MySQL 30 .

46

PHP MySQL


, .
2 . 7 .
2.

,
, ,
,
.

47

..

(,
connect.phtml):
mysql_connect("localhost", "root", "") or
die (" !");
mysql_select_db("books") or
die (" !");

:
$strSQL1="SELECT * FROM publishers ORDER BY name_publ";
$result1=mysql_query($strSQL1) or
die(" !");
$strSQL2="SELECT * FROM categories ORDER BY name_cat";
$result2=mysql_query($strSQL2) or
die(" !");

.
HTML- PHP-.
<table border=0 width=100%>
<tr><td width="50%"><center><h3></h3></center><ul>
<?
while($row=mysql_fetch_array($result1))
{?>
<li><a href="show.phtml?type=1&id_publ=
<?print $row["id_publ"];?>"><?print row["name_publ"];?></a>
<?}?>
</ul></td>
<td width="50%"><center><h3></h3></center><ul>
<?
while($row=mysql_fetch_array($result2))
{?>
<li><a href="show.phtml?type=2&id_cat=
<?print $row["id_cat"];?>"><?print $row["name_cat"];?></a>
<?}?>
</ul></td>
</tr>
</table>

,
, :
<a href="show.phtml?type=1&id_publ=<?print $row["id_publ"];?>">
<?print row["name_publ"];?></a>

48

PHP MySQL


, show.phtml
type ( 1, , 2
) id_publ ( ) id_cat ( ).
catalog.phtml 1.



, ,
. :
?
. ,
. php.ini

register_globals = on

PHP-
, . ,

<a href="show.phtml?type=1&id_publ=2">BHV</a>

show.phtml $type
1, $id_publ 2.
(
, , , ),
(
).
.


register_globals = off
49

..


,
:

$HTTP_POST_VARS["__"]

,
POST

$HTTP_GET_VARS["___ ,
"]
GET
$HTTP_COOKIE_VARS["_"]

$HTTP_SESSION_VARS["_
"]

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


show.phtml .
, , :
$id_publ=$HTTP_GET_VARS["id_publ"];
$id_cat=$HTTP_GET_VARS["id_cat"];
$type=$HTTP_GET_VARS["type"];

,
type=1,
:

50

PHP MySQL

if ($type==1)
{
$strSQL1="SELECT name_publ FROM publishers
WHERE id_publ=".$id_publ;
$result=mysql_query($strSQL1) or
die(" 1!");
if($row=mysql_fetch_array($result))
$title=$row["name_publ"];
$strSQL1="SELECT id_book, image, author, name_book,
books.id_publ, name_publ, pages, price, books.id_cat, name_cat
FROM books, publishers, categories WHERE
books.id_cat=categories.id_cat AND
books.id_publ=publishers.id_publ AND books.id_publ=".$id_publ;
}

,
type=2, :
if ($type==2)
{
$strSQL1="SELECT name_cat FROM categories
WHERE id_cat=".$id_cat;
$result=mysql_query($strSQL1) or
die(" 1!");
if($row=mysql_fetch_array($result))
51

..
$title=$row["name_cat"];
$strSQL1="SELECT id_book, image, author, name_book,
books.id_publ, name_publ, pages, price, books.id_cat, name_cat
FROM books, publishers, categories WHERE
books.id_cat=categories.id_cat AND
books.id_publ=publishers.id_publ AND books.id_cat=".$id_cat;
}
$result1=mysql_query($strSQL1) or
die(" 2!");

HTML- .
, <img> :
<img src="images/<?print $row["image"];?>"
alt="<?print $row["name_book"];?>" border="0">

"
". dobasket.phtml,
.
type=1 id_book ( ).
<a href="dobasket.phtml?type=1&id_book=
<?print $row["id_book"];?>">
<font size=-1> </font>
</a>

, ,
,
.
<table border="1" width="100%" align="right" >
<?
while($row=mysql_fetch_array($result1))
{?>
<tr>
<td align="center"><img src="images/<?print $row["image"];?>"
alt="<?print $row["name_book"];?>" border="0">
<center><a href="dobasket.phtml?type=1&id_book=
<?print $row["id_book"];?>"><font size=-1>
</font></a></center></td>
<td>
<table>
<tr><td align="right"><i>: </i></td>
<td><?print $row["author"];?></td></tr>
52

PHP MySQL
<tr><td align="right"><i>: </i></td>
<td><?print $row["name_book"];?></td></tr>
<tr><td align="right"><i>: </i></td>
<td><a href="show.phtml?type=1&id_publ=
<?print $row["id_publ"];?>">
<?print $row["name_publ"];?></a></td></tr>
<tr><td align="right"><i> : </i></td>
<td><?print $row["pages"];?></td></tr>
<tr><td align="right"><i>: </i></td>
<td><?print $row["price"];?></td></tr>
<tr><td align="right"><i>: </i></td>
<td><a href="show.phtml?type=2&id_cat=
<?print $row["id_cat"];?>">
<?print $row["name_cat"];?></a></td></tr>
</table>
</td></tr>
<?}?>
</table>

1.

53

..

5.
3 . 8 .
3.


.
.
?

,
(cookie) .
Cookies
Cookies, , -, ,
, web-
.
. :
1. , :
, , , (
) HTML-,
(header).
54

PHP MySQL

2.
. ,
( ),
( ).
3. web- -

, .
4.
.

web- .
, , ,
.
, HTML-

.
. ,
, .
:

frameset
JavaScript VBScript.
, , ,
(
JavaScript .

Web-
(http://kek.ksu.ru/EOS/TESTS/index.html) ).

.
.

.
55

..

HTML- ,
cookies. .

, ,
.
, !
:
, ,
, . ,
.
header.phtml,
.
$id_bask=$HTTP_COOKIE_VARS["id_bask"];
if (!isset($id_bask))
{
$uniq_ID=uniqid("ID");
setcookie("id_bask", $uniq_ID, time()+60*60*24*14);
//
}
else
setcookie("id_bask", $id_bask, time()+60*60*24*14);
// , . .
// 2

. ,
,
. isset:
if (!isset($id_bask))
{ ... }

int isset (mixed _)

,
. ,
0.

, ,
.
uniqid.
56

PHP MySQL
$uniq_ID=uniqid("ID");

int uniqid (string [,


boolean lcg])


.
, "
".

:
setcookie("id_bask", $uniq_ID, time()+60*60*24*14);

int setcookie (string [,


string [, int [,
string [, sting [,
int ]]]]])

.

.
.
; ,

.
, , .
.
, .
/ ,
.
,
, .. <html>. , cookie
,
(
!).
57

..


(
):
setcookie("id_bask", "", time()-600);

basket.phtml
:
$id_bask=$HTTP_COOKIE_VARS["id_bask"];

, :
<?
$strSQL1="SELECT COUNT(*) as count FROM basket_books WHERE
id_bask='".$id_bask."'";
$result1=mysql_query($strSQL1) or die("
1!");
$row=mysql_fetch_array($result1);
if($row["count"]==0)
{
?>
<tr><td bgcolor='#ff9999' align='center'>
<b> !</b></td></tr>
<?
}?>
58

PHP MySQL

, . ,
. ,
+ -.
<?
else
{
$strSQL1="SELECT image, author, name_book, pages, price, kolvo,
id_bask, books.id_book FROM books, basket_books
WHERE books.id_book=basket_books.id_book
AND id_bask='".$id_bask."'";
$result1=mysql_query($strSQL1) or die("
2!");
?>
<tr><td>
<table border="1" width="100%" align="right" >
<tr><td align="right"><i>: </i></td>
<td align="right"><i>: </i></td>
<td align="right"><i>: </i></td>
<td align="right"><i>: </i></td>
<td></td></tr>
<?
$sum=0;
while($row=mysql_fetch_array($result1))
{
?>
<tr>
<td><?print $row["author"];?></td>
<td><b><?print $row["name_book"];?></b></td>
<td><?print $row["price"];?></td>
<td><?print $row["kolvo"];?>
<a href="dobasket.phtml?type=1&id_book=
<?print $row["id_book"];?>" title="">[ + ]</a>
<a href="dobasket.phtml?type=2&id_book=
<?print $row["id_book"];?>" title="">[ - ]</a>
</td>
<td> <a href="dobasket.phtml?type=3&id_book=
<?print $row["id_book"];?>"></a></td>
</tr>
<?
$sum=$sum+$row["price"]*$row["kolvo"];
}?>
<tr><td align="right"></td><td align="right"><i>:
</i></td><td align="right"><?print $sum;?></td><td
align="right"></td></tr>
</table>
<?
}?>
59

..



" ",
dobasket.phtml, type=1 id_book (
). ,
$id_bask, .
:
$type=$HTTP_GET_VARS["type"];
$id_book=$HTTP_GET_VARS["id_book"];
$id_bask=$HTTP_COOKIE_VARS["id_bask"];


. ,
.
(: MySQL CURDATE()
).
,
( , ,
WHERE) .
if($type==1) //
{
$strSQL="SELECT * FROM basket_books
WHERE id_book=".$id_book." AND id_bask='".$id_bask."'";
$result=mysql_query($strSQL) or
die(" 1!");
if ($row=mysql_fetch_array($result))
{
$strSQL="UPDATE basket_books SET kolvo=kolvo+1
WHERE id_book=".$id_book." AND id_bask='".$id_bask."'";
}
else
{
$strSQL="INSERT INTO basket_books (id_bask, id_book,
Kolvo, date_bask) VALUES
('".$id_bask."',".$id_book.",1,CURDATE())";
}
mysql_query($strSQL);
}

60

PHP MySQL


.
.
dobasket.phtml basket.phtml:
<? include("basket.phtml"); ?>


,
"" "".
" " "
".
"+" dobasket.phtml
type=1,
.
"" dobasket.phtml
type=2. 1,
. 1,
, .
if($type==2) //
{
$strSQL="SELECT * FROM basket_books WHERE
id_book=".$id_book." AND id_bask='".$id_bask."'";
$result=mysql_query($strSQL)
or die(" 1!");
if ($row=mysql_fetch_array($result))
{
if ($row["kolvo"]>1)
{
$strSQL="UPDATE basket_books SET kolvo=kolvo-1 WHERE
id_book=".$id_book." AND id_bask='".$id_bask."'";
}
else
{
$strSQL="DELETE FROM basket_books WHERE
id_book=".$id_book." AND id_bask='".$id_bask."'";
}
}
mysql_query($strSQL);
61

..
}


.
"",
dobasket.phtml, type=3:
if($type==3) //
{
$strSQL="DELETE FROM basket_books WHERE
id_book=".$id_book." AND id_bask='".$id_bask."'";
mysql_query($strSQL);
}

, ,
" ".
dobasket.phtml, type=4:
if($type==4) //
{
$strSQL="DELETE FROM basket_books WHERE
id_bask='".$id_bask."'";
mysql_query($strSQL);
}

1.

62

PHP MySQL

6.

5 . 9 .
5.

(reg.phtml).

63

..


, , .
, ..
. ,
:
<input type="checkbox" value="1" name="subscribe">
<i> </i>

""
reg.phtml, ,
type 1 ( ,

). :
$fam=$HTTP_POST_VARS["fam"];
$im=$HTTP_POST_VARS["im"];
$addr=$HTTP_POST_VARS["addr"];
$mail=$HTTP_POST_VARS["mail"];
$pass=$HTTP_POST_VARS["pass"];
$pass2=$HTTP_POST_VARS["pass2"];
$login=$HTTP_POST_VARS["login"];
$type=$HTTP_POST_VARS["type"];
$subscribe=$HTTP_POST_VARS["subscribe"];
// "" ?
if($type==1)
{
// ?
if($fam!="" && $im!="" && $addr!="" && $mail!="" && $login!=""
&& $pass!="" && $pass2!="")
{
// ?
if($pass!=$pass2)
{
$message="<tr><td bgcolor='#ff9999' align='center'><b>
!!!</b></td></tr>";
}
else
{
// ,
$strSQL1="SELECT id_cust FROM customers WHERE
login='".$login."'";
$result1=mysql_query($strSQL1)
or die(" !");
// ?
64

PHP MySQL
if($row=mysql_fetch_array($result1))
{
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> !!!
</b></td></tr>";
}
else
{
//
$strSQL1="INSERT INTO customers
(fam, im, addr, mail, login, pass, subscribe)
VALUES('".$fam."','".$im."','".$addr."','".
$mail."','".$login."','".$pass."','".$subscribe."')";
$result1=mysql_query($strSQL1)
or die(" !");
$message="<tr><td bgcolor='#66cc66' align='center'>
<b> </b></td></tr>";
$success=true;
}
}
}
else
$message="<tr><td bgcolor='#ff9999' align='center'><b>
!!!</b></td></tr>";
}

, - ,
:

65

..
<form action=reg.phtml method=post>
<tr><td>
<table border="0" width="100%" align="right" >
<tr><td align="right"><i>: </i></td><td>
<input type=text name=fam value="<?print $fam?>"></td></tr>
<tr><td align="right"><i>: </i></td><td>
<input type=text name=im value="<?print $im?>"></td></tr>
<tr><td align="right"><i>: </i></td><td>
<input type=text name=addr value="<?print $addr?>"></td></tr>
<tr><td align="right"><i>E-mail: </i></td><td>
<input type=text name=mail value="<?print $mail?>"></td></tr>
<tr><td align="right"><i>: </i></td><td>
<input type=text name=login value="<?print $login?>"></td></tr>
<tr><td align="right"><i>: </i></td><td>
<input type=password name=pass value=""></td></tr>
<tr><td align="right"><i> : </i></td><td>
<input type=password name=pass2 value=""></td></tr>
<tr><td></td>
<td><input type="checkbox" value="1" name="subscribe">
<i> </i></td></tr>
<input type=hidden value=1 name=type>
<tr><td align="right"></td><td>
<input type=submit value=""></td></tr>
</table>
</form>

,
:

1.

66

PHP MySQL


, . ,

. ;
, ,
. ,
, :
.
.

name.
bool session_register (mixed name [,
mixed ...])
.

.
bool session_unregister (string

name)
name.
.
bool session_destroy(void);
.
bool session_start(void);

php.ini
:
session.auto_start = 1

,
.

6 . 9 .
, ,

, .., .
. "ok"
auto.pthml,
.
67

..
6.

$pass=$HTTP_POST_VARS["pass"];
$login=$HTTP_POST_VARS["login"];
$strSQL1="SELECT * FROM customers WHERE login='".$login.
"' AND pass='".$pass."'";
print $strsql;
$result1=mysql_query($strSQL1)
or die(" !");
// ?
if($row=mysql_fetch_array($result1))
{
$start=session_start(); //
//
session_register("log");
$HTTP_SESSION_VARS["log"]=$row["fam"]." ".$row["im"];
// ID
session_register("id");
$HTTP_SESSION_VARS["id"]=$row["id_cust"];
$message="<tr><td bgcolor='#66cc66' align='center'>
<b> </b></td></tr>";
$success=true;
}
else
{
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> / !!!</b></td></tr>";
}
68

PHP MySQL
if($success)
{
include ("cabinet.phtml");
}
else
{
include("header.phtml");
print $message;
include("footer.phtml");
}

,
:

,
id () log (, ).
log
, id .

,


. ,


( header.phtml):
if(isset($HTTP_SESSION_VARS["log"]))
{
print $HTTP_SESSION_VARS["log"];
69

..
print "<br><a href='cabinet.phtml'> </a>";
}

, , ,
log (.., )
$log=$HTTP_SESSION_VARS["log"];
$id=$HTTP_SESSION_VARS["id"];
if(!isset($log))
{
$success=false;
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> !!!</b></td></tr>";
}
else
$success=true;

, ,
<form action=change.phtml method=post>
<tr><td>
<table border="0" width="100%" align="right" >
<tr><td align="right"><i>: </i></td><td>
<input type=text name=fam value="
<?print $row["fam"]?>"></td></tr>
70

PHP MySQL
<tr><td align="right"><i>: </i></td><td>
<input type=text name=im value="
<?print $row["im"]?>"></td></tr>
<tr><td align="right"><i>: </i></td><td>
<input type=text name=addr value="
<?print $row["addr"]?>"></td></tr>
<tr><td align="right"><i>E-mail: </i></td><td>
<input type=text name=mail value="
<?print $row["mail"]?>"></td></tr>
<tr><td align="right" colspan=3>
<i><input type="checkbox" value="1" name="subscribe"
<? if($row["subscribe"]==1) print "checked"; ?> >
<i> </i></i></td><td></td></tr>
<tr><td align="center" colspan="4">
<input type="submit" value=" "></td></tr>
</table>
</form>

:
<tr><td>
<h2> </h2>
<?
$strSQL1="SELECT id_order, date_ord FROM orders WHERE
id_cust='".$id."' ORDER BY date_ord DESC";
$result1=mysql_query($strSQL1) or die("
1!");
while($row1=mysql_fetch_array($result1))
{
$order=$row1["id_order"];
$strSQL2="SELECT author, name_book, pages, price, kolvo,
id_order, books.id_book FROM books,
order_books
WHERE books.id_book=order_books.id_book and
id_order='".$order."'";
$result2=mysql_query($strSQL2) or die("
2!");
?>
<tr><td>
<hr>
<b> <?=$order?> <?=$row1["date_ord"]?><br></b>
<table border="1" width="100%" align="right" >
<tr><td align="right" width="20%"><i>: </i></td>
<td align="right" width="50%"><i>: </i></td>
<td align="right" width="15%"><i>: </i></td>
<td align="right" width="15%"><i>: </i></td>
71

..
</tr>
<?
$sum=0;
while($row2=mysql_fetch_array($result2))
{
?>
<tr>
<td><?print $row2["author"];?></td>
<td><b><?print $row2["name_book"];?></b></td>
<td><?print $row2["price"];?></td>
<td><?print $row2["kolvo"];?></td>
</tr>
<? $sum=$sum+$row2["price"]*$row2["kolvo"];
}?>
<tr><td></td><td align="right"><i>: </i></td>
<td><? print $sum;?></td>
<td></td></tr>
</table>
</td></tr>
<?
}
?>

""
change.phtml,
:
$fam=$HTTP_POST_VARS["fam"];
$im=$HTTP_POST_VARS["im"];
$addr=$HTTP_POST_VARS["addr"];
$mail=$HTTP_POST_VARS["mail"];
$id=$HTTP_SESSION_VARS["id"];
$subscribe=$HTTP_POST_VARS["subscribe"];
if($fam!="" && $im!="" && $addr!="" && $mail!="")
{
$strSQL1="UPDATE customers SET fam='".$fam."',im='".$im.
"',addr='".$addr."',mail='".$mail."',subscribe='".$subscribe.
"' WHERE id_cust=".$id;
$result1=mysql_query($strSQL1)
or die(" !");
72

PHP MySQL
$HTTP_SESSION_VARS["log"]=$fam." ".$im;
//
$message="<tr><td bgcolor='#66cc66' align='center'>
<b> </b></td></tr>";
}
else
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> !!!</b></td></tr>";

,
.
, "".
exit.phtml,
:
session_unregister("log");
session_unregister("id");
session_destroy();

1.

73

..

7.
4 . 8 .
4.

,
"" " "
. order.phtml,
(
):

,
, . ,
- .
categories.
74

PHP MySQL

<tr><td><br><b> :</b>
<input type="radio" value=1 name="dostavka" checked>

<input type="radio" value=2 name="dostavka">
<input type="radio" value=3 name="dostavka">
</td><tr>
<tr><td> :
<select name="bonus">
<option value="0">
<? $strSQL1="SELECT * FROM categories";
$result1=mysql_query($strSQL1)
or die(" !");
while($row=mysql_fetch_array($result1))
{?>
<option value="<? print $row["id_cat"]?>" >
<? print $row["name_cat"]?>
<?}?>
</td><tr>

1.
" "
doorder.phtml. , , ,
:
$log=$HTTP_SESSION_VARS["log"];
$id=$HTTP_SESSION_VARS["id"];
$id_bask=$HTTP_COOKIE_VARS["id_bask"];
if(!isset($log))
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> !!!</b></td></tr>";

75

..

, , .

.
:
$order=uniqid("OR");
$strSQL="INSERT INTO orders
(id_order, date_ord, id_cust, dostavka, bonus) VALUES
('".$order."',CURDATE(),".$id.",'".$dostavka."','".$bonus."')";
mysql_query($strSQL)
or die(" 1!");


:
$strSQL="SELECT * FROM basket_books
WHERE id_bask='".$id_bask."'";
$result=mysql_query($strSQL)
or die(" 2!");
while ($row=mysql_fetch_array($result))
{
$strSQL="INSERT INTO order_books (id_order, id_book,
kolvo) VALUES ('".$order."',".$row["id_book"].
",".$row["kolvo"].")";
mysql_query($strSQL)
or die(" 3!");
}

:
$strSQL="DELETE FROM basket_books
WHERE id_bask='".$id_bask."'";
mysql_query($strSQL)
76

PHP MySQL
or die(" 4!");
$uniq_ID=uniqid("ID");

:
setcookie("id_bask", $uniq_ID, time()+60*60*24*14);

1.

77

..

: - XML
- ,
, XML?
XML- Internet Explorer.
<?xml version="1.0" encoding="windows-1251" ?>
- <->
- < ="2">
BHV
- < =" ., ." ="Microsoft Visual Studio 2008">
<>1192</>
<>400</>
<> </>
</>
- < =". " ="Microsoft Visual C#
">
<>314</>
<>140</>
<> </>
</>
</>
< ="5">Que</>
- < ="4">

- < =" , , "


="Ajax ">
<>640</>
<>200</>
<> </>
</>
</>
< ="3"></>
- < ="1">

- < =" " =" Ajax">


<>425</>
<>300</>
<> </>
</>
- < =". , . . " =" Rails">
<>720</>
<>400</>
<> </>
</>
</>
</->

78

PHP MySQL

, ,
XML-:
header ("Content-type: text/xml");

XML-
.
Windows , .
print "<?xml version=\"1.0\" encoding=\"windows-1251\" ?>";


.
:
$strSQL1="SELECT * FROM publishers ORDER BY name_publ";
$result1=mysql_query($strSQL1)
or die(" 1!");
print "<->";
while($row=mysql_fetch_array($result1))
{
print "<
='".$row["id_publ"]."'>".$row["name_publ"];
$strSQL2="SELECT id_book, author, name_book, pages, price,
name_cat FROM books, categories WHERE
books.id_cat=categories.id_cat AND
books.id_publ=".$row["id_publ"];
$result2=mysql_query($strSQL2)
or die(" 2!");
while($row2=mysql_fetch_array($result2))
{
print "< ='".$row2["author"].
"' ='".$row2["name_book"]. "'>";
print "<>".$row2["pages"]."</>";
print "<>".$row2["price"]."</>";
print "<>".$row2["name_cat"]."</>";
print "</>";
}
print "</>";
}
print "</->";

1.

79

..


1. ,
,

"".
, :
header("Cache-control: no-cache");


. .
2.
. ,
,
.
3.
, .
,
, - .

80

PHP MySQL

1.
(header.phtml)
<?
header("Cache-control: no-cache");
$id_bask=$HTTP_COOKIE_VARS["id_bask"];
if (! isset($id_bask))
{
$uniq_ID=uniqid("ID");
setcookie("id_bask", $uniq_ID, time()+60*60*24*14);
//
}
else
setcookie("id_bask", $id_bask, time()+60*60*24*14);
//
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> </title>
</head>
<body background="EULA.jpg" style="background-repeat:repeat-y"
leftmargin="130" rightmargin="5" bgProperties=fixed>
<table border="0" align="right" width="90%" cellpadding="0"
cellspacing="0">
<tr><td>
<table border="0" align="right" width="100%" >
<tr>
<td align="center" bgcolor="#cccccc">
<form action="auto.phtml" method="post">
<table>
<tr><td align="right"><font size=-2>:</font></td>
<td align="left"><input type=text style="width:60; height:20;"
name=login></td></tr>
<tr><td align="right"><font size=-2>:</font></td>
<td align="left"><input type=password style="width:60;
height:20;" name=pass>
<input type=submit value=ok style="height:20;"></td></tr>
</table>
<b><small>
<?
if(isset($HTTP_SESSION_VARS["log"]))
{
print $HTTP_SESSION_VARS["log"];
print "<br><a href='cabinet.phtml'> </a>";
}
81

..
?>
</small></b></td>
</form>
<td colspan="4" align="center" bgcolor="#ccccff">
<font face="Arial" size="+3"><i><b>
</b></i></font></td></tr>
<tr><td align="center" bgcolor="#aaddff" width="20%">
<a href="catalog.phtml"><b></b></a></td>
<td align="center" bgcolor="#ddaaff" width="20%">
<a href="basket.phtml"><b></b></a></td>
<td align="center" bgcolor="#aaaaff" width="20%">
<a href="reg.phtml"><b></b></a></td>
<td align="center" bgcolor="#ffaaff" width="20%">
<a href="order.phtml"><b></b></a></td>
<td align="center" bgcolor="#aaffee" width="20%">
<a href="exit.phtml"><b></b></a></td>
</tr>
</table>
</td></tr>
<tr><td align="center" bgcolor=<?print $color?>><font
face="Arial" size="+2">
<i><?print $title?></i></font><br>
</td></tr>
(footer.phtml)
<tr><td><center><hr><br>
<a href="index.phtml"> </a></center></td></tr>
</table>
</body>
</html>
(index.phtml)
<?
$title="Welcome!";
$color="#ccccff";
include("header.phtml");
?>
<tr><td>
<center><h2><font color="#555599"><br>
! <br><br>
.
!
, , ,

- !</font></h2></center>
</td></tr>
<? include("footer.phtml"); ?>

82

PHP MySQL
(connect.phtml)
<?
mysql_connect("localhost", "root", "") or
die (" !");
mysql_select_db("books") or
die (" !");
?>
(catalog.phtml)
<?
$title="";
$color="#aaddff";
include("header.phtml");
include("connect.phtml");
$strSQL1="SELECT * FROM publishers ORDER BY name_publ";
$result1=mysql_query($strSQL1)
or die(" !");
$strSQL2="SELECT * FROM categories ORDER BY name_cat";
$result2=mysql_query($strSQL2)
or die(" !");
?>
<tr><td>
<table border=0 width=100%>
<tr><td width="50%"><center><h3></h3></center><ul>
<?
while($row=mysql_fetch_array($result1))
{?>
<li><a href="show.phtml?type=1&id_publ=
<?print $row["id_publ"];?>">
<?print $row["name_publ"];?></a>
<?}?>
</ul></td>
<td width="50%"><center><h3></h3></center><ul>
<?
while($row=mysql_fetch_array($result2))
{?>
<li><a href="show.phtml?type=2&id_cat=
<?print $row["id_cat"];?>">
<?print $row["name_cat"];?></a>
<?}?>
</ul></td>
</tr>
</table>
</td></tr>
<?
include("footer.phtml");
mysql_close();
?>
83

..


(show.phtml)
<?
$id_publ=$HTTP_GET_VARS["id_publ"];
$id_cat=$HTTP_GET_VARS["id_cat"];
$type=$HTTP_GET_VARS["type"];
include("connect.phtml");
if ($type==1)
{
$strSQL1="SELECT name_publ FROM publishers WHERE
id_publ=".$id_publ;
$result=mysql_query($strSQL1)
or die(" 1!");
if($row=mysql_fetch_array($result))
$title=$row["name_publ"];
$strSQL1="SELECT id_book, image, author, name_book,
books.id_publ, name_publ, pages, price, books.id_cat, name_cat
FROM books, publishers, categories WHERE
books.id_cat=categories.id_cat AND
books.id_publ=publishers.id_publ AND books.id_publ=".$id_publ;
}
if ($type==2)
{
$strSQL1="SELECT name_cat FROM categories WHERE
id_cat=".$id_cat;
$result=mysql_query($strSQL1)
or die(" 1!");
if($row=mysql_fetch_array($result))
$title=$row["name_cat"];
$strSQL1="SELECT id_book, image, author, name_book,
books.id_publ, name_publ, pages, price, books.id_cat, name_cat
FROM books, publishers, categories WHERE
books.id_cat=categories.id_cat AND
books.id_publ=publishers.id_publ AND books.id_cat=".$id_cat;
}
$result1=mysql_query($strSQL1) or die("
2!");
include("header.phtml");
?>
<tr><td>
<table border="1" width="100%" align="right" >
<?
while($row=mysql_fetch_array($result1))
{?>
<tr>
<td align="center"><img src="images/<?print $row["image"];?>"
alt="<?print $row["name_book"];?>" border="0">
84

PHP MySQL
<center><a href="dobasket.phtml?type=1&id_book=
<?print $row["id_book"];?>">
<font size=-1> </font></a></center></td>
<td>
<table>
<tr><td align="right"><i>: </i></td>
<td><?print $row["author"];?></td></tr>
<tr><td align="right"><i>: </i></td>
<td><?print $row["name_book"];?></td></tr>
<tr><td align="right"><i>: </i></td>
<td><a href="show.phtml?type=1&id_publ=
<?print $row["id_publ"];?>"><?print $row["name_publ"];?></a>
</td></tr>
<tr><td align="right"><i> : </i></td>
<td><?print $row["pages"];?></td></tr>
<tr><td align="right"><i>: </i></td>
<td><?print $row["price"];?></td></tr>
<tr><td align="right"><i>: </i></td>
<td><a href="show.phtml?type=2&id_cat=
<?print $row["id_cat"];?>"><?print $row["name_cat"];?></a>
</td></tr>
</table>
</td>
</tr>
<?}?>
</table>
</td></tr>
<?
include("footer.phtml");
?>
(basket.phtml)
<?
$id_bask=$HTTP_COOKIE_VARS["id_bask"];
$title=" ";
$color="#ddaaff";
include("header.phtml");
include("connect.phtml");
$strSQL1="SELECT COUNT(*) as count FROM basket_books
WHERE id_bask='".$id_bask."'";
$result1=mysql_query($strSQL1)
or die(" 1!");
$row=mysql_fetch_array($result1);
if($row["count"]==0)
{
?>
<tr><td bgcolor='#ff9999' align='center'>
<b> !</b></td></tr>
<?
85

..
}
else
{
$strSQL1="SELECT image, author, name_book, pages, price, kolvo,
id_bask, books.id_book FROM books, basket_books WHERE
books.id_book=basket_books.id_book AND
id_bask='".$id_bask."'";
$result1=mysql_query($strSQL1) or die("
2!");
?>
<tr><td>
<table border="1" width="100%" align="right" >
<tr><td align="right"><i>: </i></td>
<td align="right"><i>: </i></td>
<td align="right"><i>: </i></td>
<td align="right"><i>: </i></td>
<td></td></tr>
<?
$sum=0;
while($row=mysql_fetch_array($result1))
{
?>
<tr>
<td><?print $row["author"];?></td>
<td><b><?print $row["name_book"];?></b></td>
<td><?print $row["price"];?></td>
<td><?print $row["kolvo"];?>
<a href="dobasket.phtml?type=1&id_book=
<?print $row["id_book"];?>" title="">[ + ]</a>
<a href="dobasket.phtml?type=2&id_book=
<?print $row["id_book"];?>" title="">[ - ]</a>
</td>
<td> <a href="dobasket.phtml?type=3&id_book=
<?print $row["id_book"];?>"></a></td>
</tr>
<?
$sum=$sum+$row["price"]*$row["kolvo"];
}?>
<tr><td align="right"></td><td align="right"><i>:
</i></td><td align="right"><?print $sum;?></td><td
align="right"></td></tr>
</table>
<tr><td><center><a href=dobasket.phtml?type=4>
<b> </b></a></center></td></tr>
<tr><td><center><a href="order.phtml">
<b> </b></a></center></td></tr>
<?
}
include("footer.phtml");
?>

86

PHP MySQL
(dobasket.phtml)
<?
$type=$HTTP_GET_VARS["type"];
$id_book=$HTTP_GET_VARS["id_book"];
$id_bask=$HTTP_COOKIE_VARS["id_bask"];
include("connect.phtml");
if($type==1) //
{
$strSQL="SELECT * FROM basket_books WHERE
id_book=".$id_book." AND id_bask='".$id_bask."'";
$result=mysql_query($strSQL)
or die(" 1!");
if ($row=mysql_fetch_array($result))
{
$strSQL="UPDATE basket_books SET kolvo=kolvo+1 WHERE
id_book=".$id_book." AND id_bask='".$id_bask."'";
}
else
{
$strSQL="INSERT INTO basket_books (id_bask, id_book,
kolvo) VALUES ('".$id_bask."',".$id_book.",1)";
}
mysql_query($strSQL);
}
else
if($type==2) //
{
$strSQL="SELECT * FROM basket_books WHERE
id_book=".$id_book." AND id_bask='".$id_bask."'";
$result=mysql_query($strSQL)
or die(" 1!");
if ($row=mysql_fetch_array($result))
{
if ($row["kolvo"]>1)
{
$strSQL="UPDATE basket_books SET kolvo=kolvo-1 WHERE
id_book=".$id_book." AND id_bask='".$id_bask."'";
}
else
{
$strSQL="DELETE FROM basket_books WHERE
id_book=".$id_book." AND id_bask='".$id_bask."'";
}
}
mysql_query($strSQL);
}
else
if($type==3) //
{
87

..
$strSQL="DELETE FROM basket_books WHERE
id_book=".$id_book." AND id_bask='".$id_bask."'";
mysql_query($strSQL);
}
else
if($type==4) //
{
$strSQL="DELETE FROM basket_books WHERE
id_bask='".$id_bask."'";
mysql_query($strSQL);
}
include("basket.phtml");
?>
(reg.phtml)
<?
$title="";
$color="#aaaaff";
$fam=$HTTP_POST_VARS["fam"];
$im=$HTTP_POST_VARS["im"];
$addr=$HTTP_POST_VARS["addr"];
$mail=$HTTP_POST_VARS["mail"];
$pass=$HTTP_POST_VARS["pass"];
$pass2=$HTTP_POST_VARS["pass2"];
$login=$HTTP_POST_VARS["login"];
$type=$HTTP_POST_VARS["type"];
$subscribe=$HTTP_POST_VARS["subscribe"];
include("connect.phtml");
if($type==1)
{
if($fam!="" && $im!="" && $addr!="" && $mail!="" && $login!=""
&& $pass!="" && $pass2!="")
{
if($pass!=$pass2)
{
$message="<tr><td bgcolor='#ff9999' align='center'><b>
!!!</b></td></tr>";
}
else
{
$strSQL1="SELECT id_cust FROM customers
WHERE login='".$login."'";
$result1=mysql_query($strSQL1)
or die(" !");
if($row=mysql_fetch_array($result1))
{
$message="<tr><td bgcolor='#ff9999' align='center'>
88

PHP MySQL
<b> !!!
</b></td></tr>";
}
else
{
$strSQL1="INSERT INTO customers
(fam, im, addr, mail, login, pass, subscribe)
VALUES('".$fam."','".$im."','".$addr."','".$mail.
"','".$login."','".$pass."','".$subscribe."')";
$result1=mysql_query($strSQL1)
or die(" !");
$message="<tr><td bgcolor='#66cc66' align='center'>
<b> </b></td></tr>";
$success=true;
}
}
}
else
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> !!!</b></td></tr>";
}
include("header.phtml");
print $message;
if(!$success)
{
?>
<form action=reg.phtml method=post>
<tr><td align="center">
<small> </small>
<table border="0" width="100%" align="right" >
<tr><td align="right" width="50%"><i>: </i></td><td>
<input type=text name=fam value="<?print $fam?>">*</td></tr>
<tr><td align="right"><i>: </i></td><td>
<input type=text name=im value="<?print $im?>">*</td></tr>
<tr><td align="right"><i>: </i></td><td>
<input type=text name=addr value="<?print $addr?>">*</td></tr>
<tr><td align="right"><i>E-mail: </i></td><td>
<input type=text name=mail value="<?print $mail?>">*</td></tr>
<tr><td align="right"><i>: </i></td><td>
<input type=text name=login value="<?print $login?>">*</td>
</tr>
<tr><td align="right"><i>: </i></td><td>
<input type=password name=pass value="">*</td></tr>
<tr><td align="right"><i> : </i></td><td>
<input type=password name=pass2 value="">*</td></tr>
<tr><td></td><td>
<input type="checkbox" value="1" name="subscribe">

89

..
<i> </i></td></tr>
<input type=hidden value=1 name=type>
<tr><td align="right"></td><td>
<input type=submit value=""></td></tr>
</table>
</form>
</td></tr>
<?
mysql_close();
}
include("footer.phtml");
?>
(auto.phtml)
<?
$title="";
$color="#aaaaff";
$pass=$HTTP_POST_VARS["pass"];
$login=$HTTP_POST_VARS["login"];
include("connect.phtml");
$strSQL1="SELECT * FROM customers WHERE login='".$login.
"' AND pass='".$pass."'";
$result1=mysql_query($strSQL1)
or die(" !");
if($row=mysql_fetch_array($result1))
{
$start=session_start();
session_register("log");
$HTTP_SESSION_VARS["log"]=$row["fam"]." ".$row["im"];
session_register("id");
$HTTP_SESSION_VARS["id"]=$row["id_cust"];
$message="<tr><td bgcolor='#66cc66' align='center'>
<b> </b></td></tr>";
$success=true;
}
else
{
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> / !!!</b></td></tr>";
}
mysql_close();
if($success)
{
include ("cabinet.phtml");
}
else
{
90

PHP MySQL
include("header.phtml");
print $message;
include("footer.phtml");
}
?>
(cabinet.phtml)
<?
$title=" ";
$color="#aaaaff";
$log=$HTTP_SESSION_VARS["log"];
$id=$HTTP_SESSION_VARS["id"];
if(!isset($log))
{
$success=false;
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> !!!</b></td></tr>";
}
else
$success=true;
include("header.phtml");
print $message;
if($success)
{
include("connect.phtml");
$strSQL="SELECT * FROM customers WHERE id_cust='".$id."'";
$result=mysql_query($strSQL)
or die(" !");
if($row=mysql_fetch_array($result))
{
?>
<form action=change.phtml method=post>
<tr><td>
<h2> </h2>
<table border="0" width="100%" align="right" >
<tr><td align="right"><i>: </i></td><td>
<input type=text name=fam value="<?print $row["fam"]?>"></td>
<td align="right"><i>: </i></td><td>
<input type=text name=im value="<?print $row["im"]?>"></td>
</tr>
<tr><td align="right"><i>: </i></td><td>
<input type=text name=addr value="<?print $row["addr"]?>"></td>
<td align="right"><i>E-mail: </i></td><td>
<input type=text name=mail value="<?print $row["mail"]?>"></td>
</tr>
<tr><td align="right" colspan=3><i>
<input type="checkbox" value="1" name="subscribe"
<? if($row["subscribe"]==1) print "checked"; ?> >
91

..
<tr><td align="center" colspan="4">
<input type="submit" value=" "></td></tr>
</table>
</form>
</td></tr>
<tr><td>
<h2> </h2>
<?
$strSQL1="SELECT id_order, date_ord FROM orders
WHERE id_cust='".$id."' ORDER BY date_ord DESC";
$result1=mysql_query($strSQL1)
or die(" 1!");
while($row1=mysql_fetch_array($result1))
{
$order=$row1["id_order"];
$strSQL2="SELECT author, name_book, pages,
price, kolvo, id_order, books.id_book
FROM books,
order_books WHERE
books.id_book=order_books.id_book
and id_order='".$order."'";
$result2=mysql_query($strSQL2)
or die(" 2!");
?>
<tr><td>
<hr>
<b> <?=$order?> <?=$row1["date_ord"]?><br></b>
<table border="1" width="100%" align="right" >
<tr><td align="right" width="20%"><i>: </i></td>
<td align="right" width="50%"><i>: </i></td>
<td align="right" width="15%"><i>: </i></td>
<td align="right" width="15%"><i>: </i></td></tr>
<?
$sum=0;
while($row2=mysql_fetch_array($result2))
{
?>
<tr>
<td><?print $row2["author"];?></td>
<td><b><?print $row2["name_book"];?></b></td>
<td><?print $row2["price"];?></td>
<td><?print $row2["kolvo"];?></td>
</tr>
<?$sum=$sum+$row2["price"]*$row2["kolvo"];
}
$strSQL3="SELECT name_cat FROM categories, orders
WHERE categories.id_cat=orders.bonus AND
id_order='".$order."'";
$result3=mysql_query($strSQL3)
or die(" 3!");
if($row3=mysql_fetch_array($result3))
{?>
92

PHP MySQL
<tr>
<td colspan=2> <b>
<?print $row3["name_cat"];?></b></td>
<td>0</td>
<td>1</td>
</tr>
<?}
?>
<tr><td></td><td align="right"><i>: </i></td>
<td><?print $sum;?></td><td></td></tr>
</table>
</td></tr>
<?
}
}
mysql_close();
}
include("footer.phtml");
?>
(change.phtml)
<?
$fam=$HTTP_POST_VARS["fam"];
$im=$HTTP_POST_VARS["im"];
$addr=$HTTP_POST_VARS["addr"];
$mail=$HTTP_POST_VARS["mail"];
$id=$HTTP_SESSION_VARS["id"];
$subscribe=$HTTP_POST_VARS["subscribe"];
$title="";
$color="#aaaaff";
include("connect.phtml");
if($fam!="" && $im!="" && $addr!="" && $mail!="")
{
$strSQL1="UPDATE customers SET fam='".$fam."',
im='".$im."',addr='".$addr."', mail='".$mail."',
subscribe='".$subscribe."' WHERE id_cust=".$id;
$result1=mysql_query($strSQL1)
or die(" !");
$HTTP_SESSION_VARS["log"]=$fam." ".$im;
//
$message="<tr><td bgcolor='#66cc66' align='center'>
<b> </b></td></tr>";
}
else
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> !!!</b></td></tr>";
93

..
include("header.phtml");
print $message;
include("footer.phtml");
?>
(exit.phtml)
<?
session_unregister("log");
session_unregister("id");
session_destroy();
include("index.phtml");
?>
(order.phtml)
<?
$id_bask=$HTTP_COOKIE_VARS["id_bask"];
$title=" ";
$color="#ffaaff";
include("header.phtml");
include("connect.phtml");
$strSQL1="SELECT COUNT(*) as count FROM basket_books
WHERE id_bask='".$id_bask."'";
$result1=mysql_query($strSQL1)
or die(" 2!");
$row=mysql_fetch_array($result1);
if($row["count"]==0)
{
?>
<tr><td bgcolor='#ff9999' align='center'>
<b> !</b></td></tr>
<?
}
else
{
$strSQL1="SELECT image, author, name_book, pages, price, kolvo,
id_bask, books.id_book FROM books, basket_books
WHERE books.id_book=basket_books.id_book AND
id_bask='".$id_bask."'";
$result1=mysql_query($strSQL1)
or die(" 2!");
?>
<tr><td>
<table border="1" width="100%" align="right" >
94

PHP MySQL
<tr><td align="right"><i>: </i></td>
<td align="right"><i>: </i></td>
<td align="right"><i>: </i></td>
<td align="right"><i>: </i></td></tr>
<?
$sum=0;
while($row=mysql_fetch_array($result1))
{
?>
<tr>
<td><?print $row["author"];?></td>
<td><b><?print $row["name_book"];?></b></td>
<td><?print $row["price"];?></td>
<td><?print $row["kolvo"];?></td>
</tr>
<?
$sum=$sum+$row["price"]*$row["kolvo"];
}
?>
<tr><td></td><td align="right"><i>: </i></td>
<td><?print $sum;?></td><td></td></tr>
</table>
<tr><td><br><b> :</b>
<input type="radio" value=1 name="dostavka" checked>

<input type="radio" value=2 name="dostavka">
<input type="radio" value=3 name="dostavka">
</td><tr>
<tr><td> :
<select name="bonus">
<option value="0">
<? $strSQL1="SELECT * FROM categories";
$result1=mysql_query($strSQL1)
or die(" !");
while($row=mysql_fetch_array($result1))
{?>
<option value="<? print $row["id_cat"]?>">
<? print $row["name_cat"];
}
?>
</td><tr>
<tr><td><center><a href=doorder.phtml>
<b> </b></a></center></td></tr>
<?
}
include("footer.phtml");
?>
(doorder.phtml)
<?
95

..
$log=$HTTP_SESSION_VARS["log"];
$id=$HTTP_SESSION_VARS["id"];
$id_bask=$HTTP_COOKIE_VARS["id_bask"];
$dostavka=$HTTP_POST_VARS["dostavka"];
$bonus=$HTTP_POST_VARS["bonus"];
$title=" ";
$color="#ffaaff";
include("connect.phtml");
if(!isset($log))
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> !!!</b></td></tr>";
else
{
$strSQL1="SELECT COUNT(*) as count FROM basket_books
WHERE id_bask='".$id_bask."'";
$result1=mysql_query($strSQL1)
or die(" 2!");
$row=mysql_fetch_array($result1);
if($row["count"]==0)
$message="<tr><td bgcolor='#ff9999' align='center'>
<b> !</b></td></tr>";
else
{
//
$order=uniqid("OR");
$strSQL="INSERT INTO orders
(id_order, date_ord, id_cust, dostavka, bonus)
VALUES ('".$order."',CURDATE(),".$id.",
'".$dostavka."','".$bonus."')";
mysql_query($strSQL)
or die(" 1!");
//
$strSQL="SELECT * FROM basket_books
WHERE id_bask='".$id_bask."'";
$result=mysql_query($strSQL)
or die(" 2!");
while ($row=mysql_fetch_array($result))
{
//
$strSQL="INSERT INTO order_books (id_order, id_book,
kolvo) VALUES ('".$order."',".$row["id_book"].
",".$row["kolvo"].")";
mysql_query($strSQL)
or die(" 3!");
}
//
$strSQL="DELETE FROM basket_books
WHERE id_bask='".$id_bask."'";
mysql_query($strSQL)
96

PHP MySQL
or die(" 4!");
$uniq_ID=uniqid("ID");
setcookie("id_bask", $uniq_ID, time()+60*60*24*14);
$message="<tr><td bgcolor='#66cc66' align='center'>
<b> </b></td></tr>";
}
}
include("header.phtml");
print $message;
include("footer.phtml"); ?>

- XML (price.phtml)
<?
header ("Content-type: text/xml");
print "<?xml version=\"1.0\" encoding=\"windows-1251\" ?>";
include("connect.phtml");
$strSQL1="SELECT * FROM publishers ORDER BY name_publ";
$result1=mysql_query($strSQL1) or die("
1!");
print "<->";
while($row=mysql_fetch_array($result1))
{
print "<
='".$row["id_publ"]."'>".$row["name_publ"];
$strSQL2="SELECT id_book, author, name_book, pages, price,
name_cat FROM books, categories WHERE
books.id_cat=categories.id_cat AND
books.id_publ=".$row["id_publ"];
$result2=mysql_query($strSQL2) or die("
2!");
while($row2=mysql_fetch_array($result2))
{
print "< ='".$row2["author"]."'
='".$row2["name_book"]. "'>";
print "<>".$row2["pages"]."</>";
print "<>".$row2["price"]."</>";
print "<>".$row2["name_cat"]."</>";
print "</>";
}
print "</>";
}
print "</->";
mysql_close();
?>

97

..

2. PHP

, ,
PHP UNIX Perl. ,
, , , .
- , 2001.
. PHP
- POSIX
Perl.
POSIX
| - - ,
, "cat|dog".
[] - ,
"[abcd]". [0-9] [az]. ^ - ,
, [^0-9] ' , '.
:
[[:alpha:]] [a-zA-Z],
[[:alnum:]] [a-zA-Z0-9],
[[:digit:]] [0-9],
[[:space]] - , \n, \t ..
+, *, ? {...} - ,
. ,
"+" - '',
"*" - '',
"?" - '',
"{3}" - ''
"{3,}" - ''.
$ - , , "$" - , ''.
^ - , , "^" - ,
''.
98

PHP MySQL

. - .
() - -
.
, ,
'\'.

. ,
"<h1>(.*)</h1>" - , HTML-
.
"(\.)(ru$)" - , .ru
"(^http://)(.*)(w{3})" - , 'http://'
'www'.
"^.{10}$" - 10.
POSIX- :

int ereg (string ,


string [, array
])

,
.
'',
,
-

string ereg_replace (string


, string , string
)

,
,

int eregi (string ,


string [, array
])

ereg,

string eregi_replace (string


, string , string
)

ereg_replace,

array split (string ,


string [, int ])

,

( explode)

array spliti (string ,


string [, int ])

split,

99

..

PHP .
- PHP - , -

. , .
PHP
. :

,
,
,
,
,
,
.

. " ".
Java:
class Animal
{ var $color, $weight, $height;
function Animal($c, $w, $h)
{
$this->color=$c;
$this->weight=$w;
$this->height=$h;
}
}
class Bird extends Animal
{ var $isSongBird,
//
$isMigrantBird;
//
function Bird($c, $w, $h, $isS, $isM)
{
$this->isSongBird=$isS;
$this->isMigrantBird=$isM;
$this->Animal($c, $w, $h);
}
}

.
array get_class_methods (string
_)
100

PHP MySQL
array get_class_vars (string
_)

array get_object_vars (object


_)

bool method_exists (object _,


string _)

string get_class (object _)

string get_parent_class (object


_)

bool is_subclass_of (object


_, string _)

PHP , C.
(
).
, , .


bool file_exists (string
)

bool is_file (string )

,
/

bool is_readable (string


)

bool is_writable (string


)

int filesize (string )

/
101

..

int fopen (string , string


[, int _])

int fclose (int )

-
,
(php://stdin,
php://stdout, php://stderr)
( http:// ftp://).
, C (r, r+,
w, w+, a, a+).
,
/.


bool feof (int )

string fread (int ,


int )

string fgetc (int )

string fgets (int ,


int )

;
,
,

string fgetss (int


, int [,
string _])

, ,
HTML PHP-,

array file (string )


(,
!)

int readfile (string [,


int _])



( , )


,
int fwrite (int ,
,
string [,int ])

,
int fputs (int ,
,
string [,int ])

102

PHP MySQL

, -
, , , ,
.
.

string exec (string [,


array [,int ]])



. (
)

.

PHP

PHP
php.ini, , , WINDOWS
PHP.
,
. .
, , ,
-
PHP .
,
.

register_globals = on | off

:
session.auto_start = 1

short_open_tags = on | off
103

..

/ <? ... ?> .


, <?php ... ?> <script>
... </script> .
asp_open_tags = on | off

<% ... %> .


precision = _

.
max_execution_time = _

- ( )
.
, .
memory_limit = _

, (
- 8).
error_reporting = 1 | 2 | 4 | 8

PHP - (1)
(8).
display_errors = on | off

.
error_log = _


display_errors.
magic_quotes_gpc = on | off


(,
).
safe_mode = on | off

104

PHP MySQL

""
.

safe_mode_exec_dir = _

safe_mode
, , , system().
disable_functions = _

, .
, ,
PHP. ,
.
,
PHP, , ,
. php.ini,
Paths and Directories
extension_dir PHP, ,
extension_dir = C:/PHP/Extensions

,
;extension=php_gd.dll

.., .
.

105

..

3. PHP MS IIS
PHP Apache.
PHP Microsoft Internet
Information Services ( Windows NT, 2000 XP).
-, IIS -
PHTML-. , .
, PHP .
, Windows XP.
- -
- Internet Information Services,
Web- .
IIS.
. ,
IIS. .
php.exe , ,
C:\php\php.exe. .phtml.
.
, Apache,
php.ini :\WINDOWS, php4ts.dll
Msvcrt.dll C:\WINDOWS\SYSTEM32.
- PHTML. .
, .
. IIS
. php.ini
, :
session.save_path = C:\tmp

. PHP
:
cgi.force_redirect = 0

106

PHP MySQL

1. . - : PHP 4. - , 2002.
2. . - 4. . - , 2001.
3. . - PHP Web-. -, 2001.
4. . - PHP Web- -, 2002.
5. ., . - PHP4. Web-. -
, 2001.
6. . - Web- PHP MySQL. ,
2001.
7. . - PERL, PHP, APACHE MySQL
Web-c. - , 2002.

107

..

108

Оценить