A d van
Pc e d
H P f or W Peb
B y C h r i st o ph
P ub
l i sh
P D ub
•
Index
•
T O C
er C os e r : P r en
er 29
I S B N : 0- 13-
I n t hi co s t e ch
nc
ye as ars t he
ap
pl i c at
nt i cat i on
0
, ha
nd
, 20
02
853
9- 1
s- on t ut ori
o r b ui l d i ng se
a P H P de
au
al s
: 368
i se
n i q u f es
on
t i ce H a l l P T R
at e: O c t ob
P ages
r of es i
e nt i no
i on
ve ; ge
s; an m d
l op ne
er, C os r at i ng dyn
uc h
al , P H P ex
r i o u Ws
m or e!
en am
pe
r t C hri
st op
e a b p p l i ca
t i on
t i no w al y ks
ou t hroug
gi c r ap
hi cs;
he
r C os
en
t i no de
s. T h r o u gh prof pa
h bu
e si
i l di ng f r i en
r si ng X M L do
c um
l i ve o na
r d s oz l - qu
dl i er, m u ore en
t s; bu
en o s f po
a l i t ex y
am sa
i l di ng da
w erf
ul ne
w
p l e draw s
bl e si t es t ab
ase
f n r o m h i si ; i m provi - i nd
ng us ep
en
de
x
er nt W eb
A d va
nc
P H Pe d
f o r W ePb
B y C h r i st o ph
P ub
er C os
l i sh
e r : P r en
Inde
•
T O C
Pages:
C o py
er 29
I S B N : 0- 13-
x
on
t i ce H a l l P T R
P ub D at e: O c t ob
•
r of es i
e nt i no
0
, 20
0
853
2
9- 1
3 6 8
r ig h t
T h eP
r ent
A b ou
t P r en
iH ce
al lP T R A dv
t i c e H al l P
W anced r of es
D eb
si on
ev l
al T ec
hn
opm i ca
ent
S er i es
lR ef ernc
e
P r e fac e G oa
lof T hi B s o
W Thi ho
s
o k
B I ok
For s
G et t i ng t he C od A ck now Fi The
ent
s
ne P r i nt
C h a p t e r 1 P. O ver PH
e
l edgm
H RP
evi
ew
vi ew Syn P
t a x
V ari
a bl es
O pe
r at or s
A r r ay
s
I f / T he S n
t at em
S w i t S ch
t at em
Fo
r Lo p
s
Fo
r Lo pseac h
en
ts
en
ts
W hi Lolps e D Wo
hi Lolps e
U se
r - D ef i ne
O bj ec t O
Fud
nc
r i ent
t i on
s
ed P r ogr
am
m i ng w i Pt h H P
p h p i n f o () A d
i t i on
C h a pt er Se 2. I n t r odu
al R es
ou
r ce
s i M on ang c t i on t S o es i
In i ti a l p h p. i ni S S t a r t i ng S a T he C on
t en ari
U nregi
st eri
M on
iP n H P 4 an
gem
ent
on on F i l es
a b l e ac r s ng S es
ng S esi
A S i m pl S e es i
m ent
or S es i
t o s f S es i
n Vg
r oyi
em ent on M an ge
et t i f ngs
e si
T r a c ki
D est
s
on on-
P os
ag d es
si on V ari
ab
ur i a ng
l es
s B S ased
hop
Ci ng
ar t
S
es i
on
al s
C h ap
t e r 3. M u l t i p l D e A dvan
c ed
D at ab
a t a ba
I se
D at ab
I se
nt er act
- S pe
c i f iF c un
ct
ase
DBX?PH
P S up
C r eat
Yi ng
our
U si ng P ea
C h ap
po
r t f M or
nt e r a ct i o n i on i n P H P 4 i ons
Pi n H P
ul t i pl D e
O w S n up
at ab
as
es
p o r t f o r M ul t i p l e D a t a ba
se
s
r::D B
e t t For er
m P r oc es i
I n t r o d u c ti o n t B o
t e r B4.
et t er F orm
P ost G and
ng s
et
S oup
i ng U t p he S cr i pt
F or m - F i el C d U si ng $H
he
ck i n g
T P_
G ET_
VAR
S a $ nd
HT P_ O
ST_
VAR
S
P u t t i n g I t A l lT o g e t h e r V ari
a bl e V ari
C h apt
er U 5.
a bl e s
si W ng
hat
Y H ou
Lear ve
ned?
SA
i m pl
S e hopi
C ng
ar t
I n t r o d u c ti o n F ea
t ur o es
f t he S ho
p
i ng C ar t
S e t t i n g I tU p Code The
C ha
pt er W 6.
orki
O ver
vi ew
O peni
and ng
w ng
i t Fh i l e s
C
l o si n g F i l e s
P u t t i n g I t t o U se D at M a
i ni ng
P arsi
C hap
ng L
t er P 7.
a r g Fe i l e s
H AP
ut he
U ser
A ut h
en
G en
er at i ng P
nt i cat
t i ca as w
or ds
t i ng U se
r A s ga
A ut he
nt i ca
A ut h en
t i ca
t Ui ng
A ut he
nt i ca
t i U ng
se
r Us
A ut he
nt i cat
i U ng
ser
D by s
C h ap
t er E 8. O ver
i ns
ser I by s
r r or M an
chem
ag
es
r vi e w
tT
e F xt
P A dr si H ng
e
ile s
es T T P A ut he
at ab Q ase
m en
nt i ca
ue
t i on
ry
t
vi ew
E r r o r R e p ort
C h ap
i S on
t i on O ve
t e r U 9.
in g
si n
Wg
hat
Y H ou
L ave
ear
ne
d?A
M et
i T ng
I n t r o d u c ti o n S e t t i n g I tU p Code The
C h apt
er PH 10.
X and P
O ver
vi ew
C r eat
X ian ng
P ar si an ng
M L
M P L ar ser T d r ansf
or m X i ng
M DL
oc um
e
n ts
r ac ker
A pl
i c at
i on
D um
C hap
pi D ng
t er 1 .
at ab
G en vi ew
Th G e
D Li br ar y
E nabl
G i ng
G en
er at i G ng
er 12. I nt r od I nst C r eat
ont
r at i D ng
O ver
C hapt
C se
i s nt X an o
ynam
D S up or r ap
ent
iG c
t hi w cs
i tG h
D
P H P G TK uc t
i t on
Po
H P G T K
al l i ng P H P G T K i ng B asi
Gc
T K O bj ec t
s
P u t t i n g I t A l lT o g e t h e r A S i m pl P e H P G TK
I nd
ex
A pl
i c at
i on
r ap
M FL i l e
hi w cs
i tP h H P
C o p yr i g h t A C I P ca
t al og r ec f ord
or t hi bo s
c ok
an be ob
t ai ne f d r om
t he Li bra
of y C on
gres .
C r e d its E d i t o r i al / P r o d u ct i o n S u p ervi
K at hl e n S en
M . C ar en
i or M an
ag
ei dha
rt
er D esi
g Dn
N John C ov
si o n :
i ng
E d i t or:
i r ect
or:
Je r r V y o t t a C over
D esi
gn
:
T a l a r A .B o o r u j y M an u
f act
ur
i n Mg
an ag
A l ex i R s . H ey dt - Lo M ar k et
B r yan
i n Mg
G am
ng
an a
ger:
b r el
E d i t o ri A al
B r and
er :
s
i st an
t:
t K en a
S e r i De s
esi
G ai lC ocker
gn
:
- B ogu
sz
© 2 0 0 3 P r e n t ic e H a ll P T R P r e n t i ce U pe
r S ad
P r en
dl R e
t i c e H al l bo
T he pu P ho
- H a l l , I n c.
ne
i ver
ok a s r w e
bl i sh of er
f di ers
: 80
2- 34
0- 38
, N 074 J
58 i de
sc o 19
l u y se un
; F 201 ax:
d by c o
r po
r at i on a s nd go
t o s n t hi b s o w k - 23
6- 71
he 41
n orde ; E - m ai l : c or
ve
r nm
en
t ag
i n bu
ql k ua
nt i t i es
psa
l es@
pr en
en
ci es f t or r ai ni ng . F m or ha
l l . c om
i ore
nf orm w ; or
, m arket at i on
r i t e: P r en
i ng , co
nt ac
, an
dr t : C orp at
es e S al es D ep
t i c e H al lP T R , C or p. S al es D ep
al e. art
m en
t . , O ne La
t, ke
S tre
t ,U p
er S ad
dl R e
A l l r i gh
t r s es
erv d
. N o pa
p u b l i sh
i ver
, N 07 J
45
8.
r t of hi b s o m k
ay be r ep
r od
uc
ed
, i n an f y orm
by or
an m y
ea
ns
, w i t ho
ut pe
r m i si
of arks
t he
on i n w r i t i ng f r om
t he
e r.
A l l produ
c t or c o
m pa n ny
am
m es
P r i n t e i d t n he U ni t ed S t a t o es
en f A m eri
t i on
ed he
r ei a n r t e he t r ad
em
or a ks
r eg
i st t er d
r ad
em
i r r es
pe
c t i o ve
w ne
r s.
ca
1 2 3 4 5 6 7 8 9 10 P ear
E son
duc at
LiT on
P ea
r so E n
du
ca
t i on A us
t r al i P a
P ea
r son
E du
c at
i on S i ng
ap
P ea
r son
E du
c at
i on N or t A h
P ea
r E son
duc a
t i on C an
P ea
r E son
duc a
c i d ón
Me
P ear
E son
duc at
— i on
Jap n
P ea
r so E n
du
ca
D .
t i on M al ay
T Y , Li m i t ed
or e, P t e. Lt d. si L a t d. da,
exi
Lt d. c o,
S . A C . de
.V .
si a, P t e. Lt d.
T o p
P re fa c e G oal
of T hi B s ok
W T ho
hi B s I ok
For s
G et t i ng t he C od A cknow
l egm
e ent
s
T he F i ne P r i nt
T o p
G o al o f T h i B s T he go
o o k
al of t hi b s o i k t s h o el y p ou ge
so m a e p l i ca t i on t s ha uste are t c o o de an e d asi er t u o se.
b t a et t gr er f ul i yo n
ur w or ork
as o p f P H P , t l o ea ho
b
i es
. I ho
r s n om
o e f t he l es co s
pe i t gi ve yo s
so u
m m on
m i e de o as
l u y se f d ea h n ow
tmo
ak yo e
t ures,
an t d h o el y p ou bu ow ur
an p
l i ca
t i on ea s
ild si er
T o p
W ho Th T hi bo s
Bi s o I k For s
i k f s or t ho w se
m ak a e p
l i ca
ho have
t i on ea s
don
som e
si er t u o a se
ba e nd ea
si P c H P pr og
si er t p o r og
r am
r am
m ia ng
w nd
i t sh l o ea
I r ec ei ve m d an e y m ai l f s r om ac r os t s eh gl ob f e r om r ea de r o s f m f y i r st bo ok P r en t i ce H al l ) , w ho l i ke d t he co cn i se st yl e an d am pl e ex am pl es I ha d provi t he h y ad r ea o d t he ha
p t y ha
t m ake
r P H P pr og ms fe e
T hi b s o i k f s t or ho do i es hel
you p
t c ove
r ev w i PH tyour h
se of yo r ad y
van P pr ogr
r am
l . I ho
m i ng bo
pe t d o t o he sam
u w ho r are c ed
asp am
ea ec t
oks,
bu we
t he d y i dn i t h hi bo s
dy t o t ak t e he ne of P H P . I t do
es,
r ab n
out
som
o e f t m he
or ad e
vance
t d echn
i que
ts o
.
' t r ea
de I d. r ec
l lg y r asp
ho
ei ve
w P H P w or ked
d l i t eral un
t i al P H P f W or dl y oz
en o s f em
t i lt he r y ea
d m by o
eb P r of es i
on
ai fl s r om
pe
op
k. I c an
' t el lyou
al s l e w ho sa ho
( a l so p ub
l i sh
e bd y
id
w
ok. xt st ep an l d ea
ho
E s en
,
w ev
r n l a i t t l e m a ore
r , st r et b c h
eyo
bo
nd t he ba
ut P H P . T hi b s o i k sn si an c s
i d nt r od
uc e
' t a r ef er n som
me
c e bo or c o e
nce
ok
, no pt t s ha
r t c an
m i ng.
T o p
G et t i n g t h C e A l lof t he cod Y ou c an
f e or t hi bo s do
T he W eb pa I f yo
c an
i ok av s
w nl oa a d l lof t he exa ge w i l la so ha a ve
u g r et e a l l s y t u c k w i t h so
l a o t o f e m a i l a sk i n for g ov
o d e
erw
he ' t al w ays
h e lwp
i l ab
lo e t n he A dva
m pl f es ny up
da
or ea c h c h t es er or
sw que your er
W eb S er i W es ap
t er on t he pa
r at a, as w el las an
i thi n
m e t hi ng
eb pa ge
sw
b s o o k,
st i on r s i gh
sn
ay.
I t r t y o an
w w w . ph
er t s f o r eq
ue
nt al y sked
f e el f r e t e o m a i l m e a t
' t ?), an I d m ay no t aw
ge at
t be ab
sw f as er
t r . c om
/ advnce
w eb/
ph
.
.
i t h P H P . I f i t ' a s si m p l p e r o b l e m , I c a u n su
l m ed w i t e h m ai l at el ( y w ho ha an
nce
a l l a y n sw
l t e resp o ast
as I c an
est
i on
s.
co se n t i n o @ d i g i t a l - sa l va g e . n e t . I sa y
i n t h ib s o o k
be
c au
I se ge
t
e r a n q y u e st i o n , b u t I ' ve b e e g n e t t i n a g l i t t l e
on t d q o ue , bu
qu
t som
st i on u s nrel
at ed t m o
et i m es t he t ur na
r ou
by o
ks.
P l ea
nd m ay be a f ew
se no da
t e ha
tI
ys.
T o p
A ck
now
l edgm
I w i sh t o g i ve a he
g t ha
l t so M o
I ' d al so l i ke t o t ha pu
r cha
S i nc t er
i c ah
ha
nk t s o Ja B r ow
n L k eo
, C or PH e
sed
nk an s
gu
ec i da
i al t ha nce
A nd of co ve a urse ho i urs
f n r on
F i na l l y, t ha bo h ok el yo ps
n S ch
n A t ki ns
PP
or on k
am
ec
i sdo
o o ut t A o t w i t h yo
r si y t of t he co
m , an f d hel or nc t er m pu
nk t s o t he r ea de a u w s el l .
ha t w er
so
r Jo
r o s ut t he
l l an B r um
f er hi or
n, Jr . , " ar t . T ha
md
uc l h ov t e m o ng on b a o
r e w ho se
nt em
l pf ul c o
nks,
U ncl
a r t , f o r t h ei r su
dva
nce
H P pr og m m en
p
o r t an
d pa
t i e n ce
. I ' d a l so
. Sd
er i o es
t o s f t h i b s o o k, a w s
ar t ed w i t P h he s
h n N e i dh ok
t an s
r am
f W eb de
e l l f w or
m i ng
t d es
si gn bo f oks
r om
r i t i n g t h e f i r st P H P bo
P r en
t i ce
o ev I k
r
.
t i ng of t he co
de on B S D . T ha
nk f s hel your o
p,
b e at .
hn R . N el so
orki
t i al an A d
m m e nt o s n t h e draf
l pe t d g o et m st e
u i n a h e art
m f y i r st bo
nd on t he E sen
pi ng m t e g o et m st y nk an s hi l w e
a ok
. I t he
e a n a n d Jo
c t i on w on ork
u g ht f u l co
m i ng
g d r at i t ud a e l g so
r produ
t hi bo s
on f o r hi t s ho
r ogr
nk g s oe o s ut t o P r of es , an w d
w art f z he or
f n or hi w s
A l l a n ! I ' d w o r o k n a n ot h e r proj A sp
s
a r t f el t t h a nk t s o t h e e d i t o r f s o r t h i p s r oj e ct , K a r en M cL
l i ke t o gi ve a bi great T ah a nks H a ll.
ent
i l m i g l i o f r a b b ro
da y
r l i ng S f arh
ai l j us
t t o l et m e kn
Jo e pat her or
hn
, f " r o m t h e U n i ve
r si t y M of
a sa
ch
u se
t t f s o hi r h s el p,
! i en a c e
nd su
p
ort w hi l I e sp
en
t , ye
t ag
ai n, ho up urs
on
k. ow
t ha
t m f y i r st bo
ok ha h s el pe
d t he
m . T ha
nk yo I u! ho
pe t hi s
T o p
T h Fe in Pe r in t W hat
f ol l ow
i s f s r om
T he progam
t he G N U W eb si t a e t
de s
P ub
l i L c i ce
ns
t ai l ed i t n hi bo s e as pu
bl i sh
a ok
ht t p : / / w w w . g n u . o r g /
r f e r e so
f t w are;
yo c a u
ed by t he F r e S of t w F are
ou
r n ed
nd
i st r i bu
at i on
—
t a e nd
ei t he
r ve
/ or m od
i f t y he
m un
r si on 2 of t he Li ce
de
ns
r t he t erm
of s t he G N U G en
e ( or op your at
t i on
eral
) an l y at versi er
on
.
H e r e 'ts h e f i n e p r i n t : G N GU
EN
ER
0. T hi L s i ce un
de
ns
PUBLI AL
LI C
e ap
pl i es t o an p y r og
r t he t er m o s f t hi G s
P r og
r am
" m ea e ns
C EN
en
i t he
M AN S
r am
er al P ub
ot or
A ct i vi t i e o s t h e t r ha
n co
py
r am
i n s r ot es
t r i c t ed
( i nd
nde
nt of havi
ng be
1 .
Y ou m c ay
eri
va
t i w ve
" , be
l ow
de
r co
un ork
N G D , I STR
t i c e pl ac
ed by t he co
py
r i gh
t l aw
: t ha
r am c o a
o py
t i o n a r e no r am
t pu
Y ou m ay c h exc h
an
f t hi Li s
t f r om
t he P r og
t ve e
r ba
t co
ic o s
ni ng t he P r ogram
arge
c en
a se
r i gh
t i t s sa o
MD
t ho
l de
r am w or
O D I FI CA
r sa
yi ng i t m ay be di st r i bu
or k, an
y, w a c on rk
TI O N
d "w a
or b k ase
t ed
o d n t he
t ai ni ng t he P r og
r am
a or
pi o es
u ". ve
ve
r e d b t y h iL s i c e
r ed on
li y f i t co s
t her
ha
t i s r ue de
f t he P r og
r am
) . W het
t i m co
l on w g
a f e f t or he ph
ge f or f a e
TI O AN N
py
pr og
' so s
ysi
i t h he P r og
ca
l ac t of r an
i o es
f t he P r og
r am
n se
nt en pen
; t he a y r e ou
t co s o ds
c o urc e
t si de i t s s c o
ns
t i t ut e a w ba ork
n w hat
t he P r ogr
am
ei i ve
t , i a n m ny
de y as
yo c u on sp i cu ou sl a y dn ap pro r i at el p y ub l i sh on ea c h c o py an ap pro i i n t a ct al l t h e n o t i ce t s h r at e f t er o t hi L s i ce n se an d t o t h e a b se cn e o f an w y P r og
I BU
, r ef er t s a o ny such
n se i e a s d d r e s e a d " s yo
st r i b ut i on a nd m o d i f i ca
d d i st r i bu
O PYI
nt ai ns a no
r am
d t he ou
en m ad b e r y un
op an y
hi ch co
CR
t i o n a s n d / o t r r a n sl a t e d i n t o a n o t h e l r a n g u a g e . ( H e r e i n a f t e r , t r a n sl a t i o n i s n c l u d e d w i t h o u t
t i o n " . ) E a ch l i ce
, an
I TI O N FO S
T he " P r og
r am d any or
i n di g,
t he P r og
O ND
r w w ork se.
t i m o w r i t h m o d i f i ca
l i m i t a t i o i n t n h t e e r m " m o d i f i ca
CD
he
l i L c i c en
r t he P r og
p o r t i o n o f i t , e i t h e verba r
ep
TER SE
ou r ec
se
pe
. T h e a ct o f r u n ni n g
d on t he P r og do
r am
es. ed
i um
, provi
de t d ha
at e co py r i gh t no t i ce an d d i scl ai m of er w ar a r r a nt y; a n d g i ve a n o y t h e r r e ci p i en t o s f t h e
t
an
t y; ke
ep
.
sf er
i ng a co
py
, an
d yo
u m ay you at
r op
t i on of f w er
ar
an
t p y r ot ec
t i on i n
.
2 . Y ou m m ay
od
an
d di st r i bu
co
n d i t i o n s:
i f you y t e su
r c op
Y ou m us
a .
or y c op
c h m od
i f i ca
t ca
us
r am
t i on o s r w un ork
e t he m od
or an po y
de
r t i on of i t , t hu f s or m i ng w a
r t he t erm
i f i ed f i l es t o c a
o s f S ec
r r p y r om
t i on 1 ab
i ne
ov pr e,
nt no
t i c e st s
b l i sh
,t h a tiw n
or ba k
ov
sed
i de
at i ng t ha
on t he P r og
d t ha
t yo
t yo
r am
u al so m e
u ch
an
ge
, an c o d
t al t lof he
d t he f i l es an
py se
d t he da
t e of an
y
change. Y o mu
b .
c .
u st c a
us a e n w y t ork
ha
t yo d u i st r i b u t o e r pu
P r o g r a m o r a ny p a r t t he Li c en se.
r e o f , t o be l i c e
I ft h e m o d i f i e d p r o g
r am
no
ns
h o l o e r i p n a r t co
nt a i n o s r i d s e r i ve f d r o m t h e
ed a a s w h o l e at n c o h a r g t e o al l t h i r d p art
r m al l r y ea
ds
c om
m an
ds i nt er act
i vel
wy
i e u s n d t er h e t e r m o s f t h i s
he
n r un
f suc or i h tn e r a ct i u ve se i t n h m e os t o r d i n a r w y a y, t p o r i n tdi or sp l a a y a n n no u nc em co p yr i gh t no t i ce a n a d on t i ce t h a t h i er n s w o a r r a tn (or y e l se , sa yi n t g h at yo u prov m ay r ed ( E xc e
i st r i bu pt i on
on t he P r og T h es req e P r og
r am
do no
t ap
pa w ho
r t of w a se pe
t e t he progam
: i f t he P r og r am
un r am
ni s ot r eq
i t se
de
r t he
d c an
be r ea
pl t y t o ho se se ho
son
ab
clo y
c t i on w s
lw e
hi ch ia s w ba ork
r m i si
on f s ot or
he yo n se
he
nsi
r l i ce
de
d u i st r i bu
d on t he P r og ns
e e s xt en
no
ep
en
t t e he r am
i t i on t do
un
w ho
r ed i nd
nd
i ve bu
ui r ed t o pr i nt an an
ui r e m e n t a s p p l t y t o he m o d i f i ed w a as ork , an
se c o
l f i s nt eract
c em
t i f i ab
l s e e ct i on o s f t ha
pa
r at w e
orks.
n t e st yo
an an
n t he
c au
a co no
se i t , w he
py t of hi L s i ce
un
ce
m en
B ut w he yo n
t w o r a k r n e ot d eri m sel
d t hu t s o ea
u r r i g h t ts o w o r wk
ves,
t he
d u i st r i bu
t i on of t he w l e, an
m ust
n st ar t ed r un
ni ng
ns
t , yo w ur
e. ba ork
se
d
t.)
ar at e w or i ks
t i r e w ho
w t o vi ew
r m al lp y r siuch nt
d sep
, t he di st r i bu
T h u s, i t i n s o t t h e i n t e n t o f t h i s s e c ti o n t o c l a i m ri g h t o s r c o
d t el l i ng t he us ho er t no
nt an
m se as
d t o he en
en
l e. I f i d en de
s, an es no
, you
e tn i n cl u di gn a a n p pro r i at e i d a e w ar an t y) a n t d h at u se r s
t t e he sa hol
c h an
d ev pa ery
ve f d r om
n t hi L s i cen
me r t r eg
ust ardl
r i t t e n e n t i r e l b y y o u ; rat
m se e be
t he se,
an
d i t s er m s,
c t i on as s o n t h e t e r m os ft h i s
es o s f w ho w r ot i e t . h e r ,t h e i n t e n ti s
L i c en
se,
t e o xe
3 .
r c i se t h e r i g h t t o c o
n t r o l t h e d i st r i b u t i o n o f d e r i va
Ia n d
i t i on
, m er a e g
r eg
P r og
r am
) on vo a
o e st f a
Y ou m ay c op t he t erm
l um
an y
at i on of an
d di st r i bu
of s S ec
t i on a 1 s
t e he P r og
pa i ny
A co yo
si c a
on
ec de w f a or
e d o n l f y o r n on
l e f orm
w i t h su
m ork
ea
r S ec t
i on i 2) n ob
u r d ce
i ng
i ne
om
i t a h w or ba k
j ec t
r t he sco
c od
- r ea
,c o a
sed
on t he
pe of t hi Li s
e ex c u or
t ab
da
bl e sou
r c e c od
f sof or
ce
ns
e.
lf e or m un
e, w hi ch m ust
t w ar i e nt er cha
a r s, t o gi ve an t y h i r d p art
i st r i b ut i on
r t he t er m o s f S ect
( w or de
de
r
:
ar i ul y sed
t h r e e ye
r am
r w un ork
m pl e t m e
i on 1 s an 2 d ab
a ch
ove
i ne
ng
y, f o r a c h - r e a da
on a m ed
i um
be di st r i bu
arge
no m o r e t ha
b l co e
p of y t h c o e
om
ar i ul y sed
c ust
t ed un
de
e; or , n
r r es
po
n di n g
f or
g e; o r ,
t i ve i a s l l ow ut ab
de
c ust
l i d f o r a t l e as
de
w i t h he P r og
di ng m ach i um
a se o d n t h e P r o g r a m .
ng t he ot he
o o ne of t he f ol l ow
r esp
r f o r m i n so g
r am
ot bri
d on i t , un
m p a ny i t w i t t h h i e nf o r m at i on yo rec u
a l t e r na
T he so co urce
an
do n es
ve on a m ed
t ed un
l l e c t i ve w o r b ks
on t he P r og i um
t yo a u l d so
pl et e c or d a 2 bo
l l pe y
sed
or b k ase
i de t d ha
e, t b o d e i st r i bu
f t w a r e i n t erc h
A co ex
w ( a or
r ov
i on 1 s an
st of p hy
r c e c od
so
r am
t ba
t i on m ed
m p a ny i t w i t h a w r i t t e n o f f e r , va u r co
sou
c .
r w or no k
t w i t h he com
t he t er m o s f S ect b .
ot he
o e r di st r i bu
nd a 2 bo p ve
A c om
a .
orag
t i ve o r c o
co
i ve a d t s t o h o e f f e r t d o i st r i b u t c e o r r e sp
m m e r c i al di st r i bu
c h an of f er, i n ac
ns t he pref
er
co
ed f orm
rwd
t i o n an
i t h S ub
of t he w f ork
se
m or
d on
l i y f yo
c t i on a b bo ak
i ng m od
ve
u r e ce
o n di ng so
i ve
u r ce co
de
.( T h i s
i n ob
j ec
t co
d t h e p r o g r am
d e or
.)
i f i ca
t i on t s i o t . F e an or
xe
cu
t ab
lw e
ork,
c o m p l e t e so urc e co d e m e an a s l l t he so u r ce co de f al or l m o d u l e i s t co n t ai ns , p l us a n a y so ci a t e d i n t erf a ce d ef i ni t i o n f i l e s, p l u t s he scri p t u s se d t o co tn r o l co m p i l a t i o n an d i n st a l l at i on o f t h e e xe cu t a bl H e. o w e ve r , a a s sp e ci a l e xce p t i o t n, h e so u r ce co
d e d i st r i b ut e d ne
co
m po
ne
ac om
nt ( s co
pa
ni es t he excu
I f d i st r i b u t i o o n f ex
4 .
eq
ui va
pa
r t i es n are
e d n o t i nc
l en
t ac
t ab
ec
t co
m pe py
e r t hi L s i ce
l i ce 5 .
ns
l , an s d o o of n)
j e ct co
l l ed t o c o
, m od n se
d ie ms
ot r eq
i f y, su
bl i c e
p y, m od
. H o w ev
ui r ed t o ac
ns
e, di or
i f y, su
ce
6 .
by m od
L i ce
n se t o d s o o, a nd a l l i t t s erm
E ac
h t i m e yo
u r ed
f r o m t he o r i g i na
7 .
i st r i bu l i ce
c h pa
st r i bu
j ec
t t e he P r og
r t i es r em ns si e,
r am
e yo
u ha
r am
( an or
r am
w y ba ork
ns ) , co
eq
u en
ce o f a co
u r t j u dg
n d i t i on a s r i e m po
m en
am
i nt en
de t d o ap
c t i o i n h s e l i d n va
pl a y nd t he se
alt or
l e ga h e t he
i m pl em
c h c l a i m s; t h i se en
t ed by pu
d i st r i b u t e throu d o r sh i e w s T hi se s
t co
m po
ne
nt i t se
lf
a t ed p l a c e
, t h e o n f f eri de
, ev
n g
en t ho
ug t h hi r d
pt as ex
pres l
p y r ov
i de u d nd t er hi L s i ce
yo u u n de
r t h i L s i ce
ns
e. A ny
l lt y e r m i n at e yo
u rr ig h t s
n se w i l l n ot h a ve t h e i r
e. ev
er, no
t hi ng el se grant
d on t he P r og
d on t he P r og
r am
r a m su
yo s
r o hi bi t ed b l y a w i f yo r am
) , yo
) , t he r ec
i pi en
t au
u pe
u d o no
u i nd
i ca
r m i si
t ac t e yo ac e ur
pt an
r a m o r w b orks t om
at i c a
b j e ct t t o h e se t e r m a s nd co
on t o
c e t pt h i L s i c e
n se
.
ce of t hi s
a se o d i n t . l lr y ec
ei ve a s l i c e
n di t i o n s. Y o m u
ay no
ns
e
t
o n si b l f e o r e n f o r c i n g
l d n pe ot
l e i s nt en
de
en
n se . I f yo i ga t i on
r m i t r oy
t o r f o r a n o y t h e r r e as
r e e m e n t o r o t he
al t y- f r e e r ed a yo y
u co
l i y n ot he
on ( n ot l i m i t e t d o pa
) t h a t co
n t r a di ct t he co
t en
t
n di t i o n o s f t h i s
u c a n o t di st r i bu t e so a t s o sa t i sf si y m u l t a n eo u sl y s, t he n as a co sn eq ue cn e yo u m ay on t di st r i bu t e t eh i st r i b u t i o n o f t h e P r o g r a m b a y l l t h os
u l d sa
t i sf b y ot h i t an
a b l u e n d e r a n p y a r t i cu d ta o p
r w i se
r ci r cu
l a r ci r cu m st an
ce
d t hi L s i ce
m st a n c e
ew h o
n se w o u l d b e t o
, t h b e a l a n ce o f t h s e e ct i o i n s
s.
u t o i n f r i n g e a n p y a t e n t o s r o t h e r p r o p e r t ri y g h t c l a i m o s r t o c o
n t e st va
l i d i toy f
c t i o h n a t s h s e o l p e u r p o se o f p r o t e c t i n t g h i e n t e g r i t o y f t h f e r e s e o f t w a r d e i st r i b u t i o s n ys t e m , w h i c h i s bl li c i cen
se pr ac t
iM c es.
g h t h a t sy st e m i rel n
de
si gn
t i on of t he so co urce
r a m iv s o i d , a nd w i l l a ut o m a t i ca
ed i t . H ow
u r t o r d e r , ag
an p y eo
i a n ce o n co
pl e ha
d t o m ak
e t ho
r ou
gh
lc y
ea
ve m ad
n si st e n t a p p l i c a
i l l i n t g d o i st r i b ut s e o f t w a r t e h r o u gh a ny ot h e r sy ct i on i s nt en
l es t s ha
r c i se o f t h ri e g h t g s r a n t e h d e r e i n . Y o a u r n e o t r e sp
r b co y
l i o d r u n e n f o r ce
I t i n s o t t h e p u r p o se o f t h i s s e c t i o n t o i n d u c e yo a n su y
p f y r o m a de
t i o n of p a t e n t i n f r i n g em
n se w ou
ct i on as a w ho
ce
se
r e c e i ve c o p i e d s i r e c t l o y r i n di r e c t l t y h r o u gh yo u , t h e n t h e o n l w y r e f r a i n e n t i r e l y f r o m d i st r i b u t i o n o f t h e P r o g r a m . I f a n p y o r t i o o n f t h i se
s, un
.
se o d y n o (w u
pl e , i f a p at e n t l i c e
ex
t si gn
L i c e n se , t h e d y o n exc u ot se yo u f r om t he co nd i t i o ns t of ih L s i ce yo ob ur l i ga t i on u s dn t er hi L s i ce sn e an d an o y t he r pe r t i en obl nt P r o g r a m a t a l l . F o r ex
l e r un
.
w y ba ork
se
n se
es
ut ab
yi n g, d i st r i b ut i ng o r m o d i f yi ng t he P r og
r e c i p i e n t s' e xe
i su
de
t i o ns p are
( an or
co
I f , a a s co
t co
T h e se ac
y, d i st r i b ut o e r m o di f t y he P r og
i es t o t h iL s i c e
o co
nt a s d s i st r i bu
m p l i a nc
ve no
t i ve w o r ks.
a s n c d o n d i t i o n f s c op r
r t c o op
e b t y h i r d p art
ec
i ve c d o p i e s, o r r i g h t s, f r om a i n f n u l l co
nc
ts
i st r i b u t e t h e P r og
i m p o se a n f y u r t h e r r e st r i ct i o n o s the n m p l i a nc
r ce o bi r n a r f y o r m w ) i t h t he m aj or
on w hi ch t he ex
n a g ce
i t h t he ob
n se d or
t i ng t he P r og
t e t he P r og
n so
t ed ( i n e i t h e sou r
em
m p e l ac c e ou
ho h av rec e
pt t hi L s i ce
i f yi ng di or
t he sa
st r i bu
b l i ce
m o d i f o y r d i st r i b ut e t he P r o g r a m o r i t d s e r i va r ef ore,
i ng syt
l on w g
er, p a r t i e w s
T he
erat
a d b e o y f f eri
de f r om
py t he so a urce
es t e r m i n a t ed so l o n a g su s
Y ou n are
t he op
l e.
ut a b l e ob or
a t t e m p t o t h e r w i se t o c o u nd
r ne
ce t s c o op t y he so co urce ot c o
Y ou m ay no
l u d e a n yt hi n g t h i at n s o r m al l y di st r i bu
m pi l er, ke
r w ha
e ge
t e m a n a d l i ce
t i b s el i ev
ne
r ou c o s
nt r i bu
t i on t s o t he w i de r an
t i o o n f t h a t sy st e m ; i t i u s t o p
ed t o be a c o
n se c a e ns
n n ot i m p os t e h at c h eq
ue
nc
e t of he r es
ge of sof
t w ar e
h e a u t h o r / d o n o r t o d e ci d e i f h e o i ce
t of t hi L s i ce
. ns
e.
r
8 .
I f t h e d i st r i b u t i o n a n d / o r u se o f t h e P r o g r a m i res s o r i g i n a l co e xc l
ud
L i ce 9 .
p yr i gh
i n g t ho
t ho
l de
se c o
n se i n c o
u nt r i es
r t a i n co
u n t r i e e s i t h e r b p y a t e n t o s r b c y o p yri
u n d t er h i L s i c e
ns
e m ay ad
ve
r si on w s
d an ex
, so t h a t d i st r i b u t i o n i p s e r m i t t e d o n l i y n o r a m o n g c o
r p o r a t e t s h e l i m i t a t i o n a i s f w r i t t e n i n t h e b o d o y f t h i L s i ce
T he F r e S of t w ar e F ou S u c h n ew
t r i ct e d i n ce
r w h o p l a c e t s h e P r o gram
nd
at i on m ay pu
bl i sh r evi
i l l b e si m i l i ar n sp
sed
an
i r i t o t he p r es
en
d/ new or t ve
n se
ver
r si on
pl i c i t g eo
u n t r i e n s t ot h us e xc l
g h t e d i n t e r f a ce
i ca
l di st r i bu
u d ed
. I n su
s, t h e
t io n lim it a t io n
ch ca
se
, t hi s
.
si on o s f t he G en
, b m ut
g r a ph
er al P ub
l Li c i cen
a d y i f f e r i n d et a i l t o a d
r e ns
se f r om
e w prob
t i m e t o t i m e.
l e m os r
c on ers. E ac
h ve
a p
l i e t s o i t a n d " an l y at e versi r
r si on ig s i ve
l at versi er you 1 0 .
m c h ay
on pu
bl i sh
o se
any
i ng ve
o n", yo
r si on nu
m be
u h a ve t h e op
si on publ ev r
ou
i shed
nd
t by
r . I f t he P r og
r am
sp
ec
i f i es a ve
r si on nu
t i o n o f f ol l o w i n g t h e t e r m a s nd co at i on
. I f t he P r og
r am
he F r e S of t w ar F e ou
nda
do
es no t i on
m be
r of t hi L s i ce
n di t i o n e s i t he of r t h a t ve t sp
ec
i f a y ve
r si on nu
ns
e w hi ch
r si o n o or
m be
f a ny
tr of hi L s i ce
ns
e,
.
I f yo u w i sh t o i n c o r po r a t e p a r t o s f t h e P r o g r am i n t o o t h f er r e e prog r a m w s h o se d i st r i b u t i o n c o n d i t i on a s r e di f f e r e n t , w r i t e t o t he au t ho r t o as f k pe or r m i s i on . F sof or t w w are ih ch ic s op yr i gh t ed by t he F r e S of t w F are ou nd at i on , w r i t e t o t he F r e S of t w F are ou dn at i on ; w so e m et i m m es ak e e xc e pt i on f s t or hi s. O dec ur i si on w i l lbe gu i de b d t y eh t w g o oa l of s pres r vi gn t he
W NO
AR
BECAU
L ED AN RS R ES
AN D
FI FO TNES
PRO
G RAM ED AP LI BY
WI S
S AR
O EV N
UN T
HO
L DER,
O OR AN Y
n d o f p r o m ot i ng t he sh
TO ABLE
N S EQ UE N TI L T I M LO TO I TED RD PARTI O ES O O R PA THER
O FRE
CH F
L AR RE ,
EQ
a r i n g an
PO OR CR
UI RE AP BY D U FO
R DA
CA
M M AY
M AG
DAM AL AG AR ES I SI N G O S O DAT F D R BEI AT A R AFI L UR O E PRO THE F AD E N
HEN
d r eu
se o f so
f t w g are
ES,
EC
NI S
e ne
IS
r a l l y.
RI AS SK
TO Q THE
DEFCTI VE
UALI
VE,
YO
A RA
SE
G RA M " I AS S" W I THO W UT TO THE, I M PLI ED W AR
AR
N
TA E
T PROG THE Y FOR
D IN
RA O N TY KI AN Y F TI ES O M F ER
R AN AN D TY
PERFO
AS U U
M C THE E
RI TI N G
W I L AN
R AM
W R I TI N G TH ND AN C
O
T, THE O
P Y R IG H T
EI , THER
C H AN
RM
CE
TABI
LI TY
O E THE F
ALO OF ST
TI O N .
L BLE
AW
O AG R
O DI AND/ FY
RE
TO ED
O R REDI
I N C LUD
I N G AN
GY
O O UT US THE F O E I R NA N G REN EDR I ED N AC G RAM O TO W PERAT VI O SED
W O
O THERW
TI RE PRO
O R PLI
HO
B HAS RTY
SE. EN THE G RAM
PAI
E, THER
WT
O VI TH DE PRO E BU , N T O LI T M I TED
PUR
W PARTY THER YO
ARG
EXC P .
PRO THE ULD
VI CI N G L R ES
SED
PAR TI PR ES I , N C LUD I NG
U. SHO
SER Y
CEN
TI CU
YO I TH
NI N
VE, LI BE
f t w a are
LAW CABLE
PAR A
G RAM
L DER
LI S
D/ O O R THER O R I M PLI ED
CE
HO
RO M IT ED
NE
ABO
t i ve o s f o u r f r e e so
Y
P THE SE
HO EXP
CO NO THI
r i va
NT
PER EXT N
1 2 .
ui sh
ed by t he F r e S of t w F are ver
f r e e st a t u o s f a l l de
1 1 .
n a di st i ng
T F PO HE
SI
WI N STRI
EN
ER
PRO THE BUTE AL,
BI LI U TO TY CU O RATE AN I TH OY BI L SUC OF I TY
SPE
C I AL, P THE SE LOS R
I N C I D EN
O TAL
PRO DH
AM
PYR PERM AS
SU TAI ES
THER
CO Y
G RAM
RO
G RA
AG
ES.
IT
EN D
ED
R
M ( I NC N ED S) EV N ,
G RAM
I G HT
O T F ERM
LUDI YO BY
NG OU SUC I F
BU
R
T
H AN D S
C O N DI TI O N S.
T o p
T h P e r ent
i H ce
al lP T R A d vanced
W D eb
ev l
o p m ent
S e r ie s A dv
an
A d van
ced
Java
S cr i p t : I n s
ced
M acr
om
A d van ced A d va D evel
ed i
P H P f or W Peb n ce op
Sd
O A f P o r W D e v eb l
i ng
S V G - B aW s e d
Fa
i gh l ash
t s an
ov
M X : A ct i on
r of es i
on op m
A eb
d In
p
l i cat
i e s Li , vi n g ston
ni qu
, S ec
S cr i p t i n A ct i on
a l s , C os en t
at i ve T ech
en
on
d E d i t i on
, Li vi ng
st o a n n J d us
t in ia n o
t in o
Li , vi n g ston i on
s , P ear
l m H and an
ouse
T o p
A b o u tP r e n t i c H e R ef er en
ce
W i t h o r i g i n r s e a ch R ef ernc i n 19
86
, ou
i n g ba t c k
o t he i n d us
(P e
H P T R ) ha d s ev
r ed
i t no ors
w pu
el op
m pu
H andb
t i ng an
ok
P H P T R ac i n pu
b l i sh
d en
gi ne
, H or st m an kn
ow
l ed
eri
ng cl as
n' s
ge i s t a s us
i n g by p r o vi di n g t o da
t r y' f s i r st c o
m p ut e r sc i
ed i nt t o he l ea
di ng provi
0 bo
ok a s n
ua
i l t ha
t ga
ve r i se t o t h e t e c h
si c s:
K erni
bl i sh ov 20 er
O u r r o ot a s r e f i r m lp y l a n t ed i n t h e so co
a l lP r o f e s s i o n a lT e c h n i c a l
C or Jav e pi c i ou b s eg y' s p r o f es
gh , an Jo d in
i ng w s
r of t ec
l l y, au
an an hn
e nc p e u bl i sh de t ho no
l o g i ca i e' s
's
H i gh
l r e vo
- S pe
hi l i e t l o t ks t o he f ut f ure
si o n al s w i t h t om
or
ow
' s so
i ng p r og
i ca
r ed by l ea
d R i t ch son
hn
l bo
r a m i t n h e 19
ok i s t n he w orl t d od
de
r i s n t he f i el ds of co l u t i o O n.
u bo r
C P r ogr am m Lanigue ng ed D i gi t al D es i gn i or ns
pi r at i on
o ksh
6 0s
, P r e nt i ce H a l l P r o f e si
ay
. F orm
m pu
t i ng
e l f co
al l y au , en
gi ne
n t a in ms
nc eri
ng
, an
d bu
a n o y f t h e i n du , N em
on
a l T e ch
n i ca
he a d i s t o s w i n m pri
et h' s
si ne
l
nt
s.
st r y' s
U N IX S
yst
em
A dm
i ni st
r a tio n
. . W c e on
t i nu t e e o vo
l ve an b d r ea n k ew
grou
nd
l u t i o n s.
T o p
C h ap I T n hi C s
ha
t er 1. P H P R evi
ew
pt er O ver
vi ew
PH
P S yn
V a r i ab O pe
t ax le s
r at or s
A r r ay
s
I f / T he S n
t at em
S w i t S ch
t at em
Fo
r Lo p
s
Fo
r Lo pseac h
W hi Lol e
en
ts
en
ts
ops
D Wo
hi Lolps e
U se
r - D ef i ne
Fud
O r i ent
P ed
O bj ec t
nc
t i on
s
r ogr
am
m i ng w i t P h H P
p h p in f o ( ) A d
i t i on
al R es
ou
r ce
s
T o p
O ve T hi bo s
r vi ew a ok
s um
t es
hat
bu t i s ns t ea a d bo o ok Wt he eb. H av
i n s g ai t d h a t , I am
w i t a h si m i l ar l an
gu
you
so n
ha so ve
m e e xper
st i l l p r o vi di ng h a er ag
i enc
m o e f t he m ad ore
e, suc h
P as
va
bri
nc
w i tP h H P . T hi bo s ed us f es
e f i n t r od
or P H P t ha
i ok no s t yo w u
t m ean on
u c t i o n t o P H P f o r t h os w e
' t f i nd i m n
h mo
t b o a e i n nt r odu
c t or t y ext
an of y t he i nt r od
ay n e e a d qu
i ref c k
uc
t bo ry
r e sh ar or er
on P H P pr ogram ok t or s
ut ori
m i ng al on s
e al r e ad f y a m i l i ar
E R L.
T o p
P H SP
ynt
P H P l ai s ang
ax uag
t e ha
t w d as
esi
gn
ed t b o e e asi
eml y
bed
de
i nt H o
T M p L age
pa ge ah s P ve H P cod a e dn H T M i L tn er m i xed . W eh a n W eb ser ver r ea P a ds st ar t r ea di ng t he pa ge P as H P r at eh r t ha H n T M L, t eh st ar t an e d nd P H P t ag I f yo
u ha
ve c o
i n st e ad de
f au
nf i gu
l t , an i d t o s nl r y ea
H T M L, i w n
hi ca ch
A br i ef exam el c om
T he code
ab ne
l pu
t se
ove,
di ng bracke
Fo
r exam
ca
n co
r po
se se
he ed
w hen i vi du
vi ew
tO e
em
d ( t hi w s
t s b o t e a o l l ow gl t e he cod
TM
i l l m ak
you
do
, i til s o
n' t have
t d o i o t ha
ce
r t ai H n
T M e L di t t ors
b e i y m po
si ng i t ow s
rec o o
se n
a bl ed b d y ef a u l t ) , t he gn
i ze t he i n-bet
t of H T M syn L
t w ay)
ki ng f or t w t o hi ng t s l o et i t kno , r e sp
t r ax
. M ost
P H P
w i t sho ul d e c ti ve l y.
n yo c u a n us t e h s e yn
ta x
< % and
% > . T h i fea s
w e c n od a e so s
m et hi ng ot he
ul u es
po t n he cod
< ? and t u r e i turne s r t ha
? >
d o f fb y
n
e.
L:
$com echo
f
ver
de sh e se
ugh ge
p h p . i n fi i l e so t h a t i t a c e p t A s S P st yl e t a g s,
ur
ed vi a a W eb ser
al l i ne o s f P H P co
t i u s se
r e yo
' t m an Hn
Si eb
s:
. i n fi i l t e o ac c e pt " sh ort t a gs " ( w h i c h a r e en
nf i gu
i t or w on i bed
W The To e
r al , i nd
en
ou ns
, si m pl pr y l d en
e w he
d w i t h a se n yo
pany;
?>
i nt ou s
t he nam
m i co
u l o a k t i f / t he
l on
! o e f t he com , al t ho
n st at em
ug
h i t ni s nec ot en
pan
i y p n l ac e es
sa
of t he P H P code r t y o us
e se
m i co
. l on i s f a be
gi n
i ng an or
t s) .
pl e:
< ? ec ho " < p> l a i ne of co ec h
p hp
ur
pl of e P H P em
W
I n ge
r ed yo
. A d d i t i o n a l l you y,
( s al t ho H P pa
o "
>a
no
t he
de
";
r l i ne of cod
e;
? >
T o p
V a r ia b le s Y ou c a a n l e so
1>
T oda
T he " < ?= Y c a ou c od
as
gm
t ax i n t he ph
n f ol l ow
ude
c om
p, w he
m ent
i s you n
t a o br ow
ser
en
ed by a va
r P H P sc r . T he
t of s P H P i nt H o
r i ab
T M L, su a c h
l i e, u s se
i pt s. C om
m ent
r a e r t e hr e f or m of s com
d as sh
ort
he p n r i nt i ng ou
ha
ar s i e gno m en
ws
r ed t by
nd f t or he ec
ho
he W se eb
r ver
t he va
( ) f un
l ue of va a
c t i on
, an an d
r i ab
l e:
. c om y
m ent
cont s
ai ned
w i t hi t n he P H P
t s:
# —
U s e d ju s t lik e it is u s e d in P E R L ; c o m m e n t s o u t t h e r e m a in d e r o f t h e lin e a f t e r t h e # s y m b o l.
/ /—
U s e d ju s t lik e it is in J a v a S c r ip t ; c o m m e n t s o u t t h e r e m a in d e r o f t h e lin e a f t e r t h e / / s y m b o ls .
/ * and
pl of es
al l se
t ? e >. h1>
a e r n e ot sen
E xam
w i ne sm
y' D s at i e < s ?= $da " syn
i n ncl
i l i y nt ert
* /—
c om
m ent
C o m m e n t s o u t a n y th in g in b e t w e e n t h e t w o s e t s o f s y m b o ls . T h is is t h e s a m e s y n t a x u s e d in C t o c o m m e n t c o d e .
i s P n H P c ode:
< ? e ch
o "H
e l l o " ;# p r i n to s u t" H e l l o "
e c h o "H e l l o "; / / p r i n t o s u t "H / * T h e f o llo w in g p ri n t s o u t "H ec
e llo "
e l l o *" /
ho " H e l l o " ;
? > Y ou w i l lm ost
of t en se
c om
m ent
de s
not
ed usi
ng t he
/ / ch
a r ac
t or ers
h e
/ * and
* / ch
a r a c t e r s. T h # e c h
a r a c t e r i ra el s
sy e e n ,a l t h o u g h i ti s
s ti l l v a l i d . V a r i ab
l e is Pn
H P d are
$a = " H el l o W orl S t r i ng m s
us
e no
t e b d t y he " $". T a o si
g t n h v e al ue " H e l l W o
orl
d " t t o h v e a r i a b l $ e a , yo s u i m p l c a y
l l i t i y n o c od ur
e :
d"; t be en
c l os
ed q by
uo
t es
, bu
t he ca y
co n
nt ai va n
r i ab
l t es
he
m se
l ve
s:
$a 4 = ; $s
t r i n g = " T h e va
l u o e i f a $ s a";
/ / $ s t r in g = " T h e V a lu e o f a is 4 " ; P H P va r i ab l d es n o ot ah t ve b o d e ec l a ared eh ad of t i m e, on r do t he r y eq ui r a e t yp d e ef i ni t i on . N ot t e ah t yo m u g ay et w a arni gn ab us i ng un de cl ared va r i ab l es i f yo t u r t y o us t e eh m be f g ore i vi gn t he m a va l ue ( de pe dn i ng on oh w yo u se t up er r or ep ort i ng i n C hap
t er 8
) . F exam or
ou
t
p h p . i n i , se
pl e:
$a 4 = ; $b; + $a = $c / / $ c = 4 , b u t a w a r n in g a p p e a r s " W a r n in g : U n d e f in e d v a r ia b le .." . W arni
ng d s o no
t st op a sc r
i f pt r om
co
nt i nu
i ng
. I f yo
e r r o r , w h i c h p r o h i b i t t s h e sc
r i p tf r o m r u n n i n g .
S i nce
t ype
C .Fo
P H P var r exam
i ab pl e:
l es ar e no
d, you
do
n' t ha
u f t org t
o ad
d a se
m i co
l on t at he en
ve t o w or r a y bo
ut pe
r f or m i ng m at he
d of on
m at i c al
e of t he l i ne
eq
ua
s, t he
n yo
u w ou
l d ge
t a P arse
t i on o s n t he w r on
g t ype
, as you
m i gh
ti n
$a 4 = ; $b = " 5"; $b; + $a = $c // $ c = 9 ; P H P al so su
p
ort b s o
l ea va n
r i ab
l es
, w hi ch ca b n a e si
gn
ed ei t he
or a ne ze a or
r o, t or he w t ords
r ue f or al se
:
$a = t r u e ; 1; = $b //$ a = $ b $c = f al se 0; = $d
;
//$ c = $ d
T o p
O p er at o r s P H P su
p p ort f o r o pe
r a t i ors
n c l ud
e t s he f o l l o w i n g :
A r i t h m et i c O p er at o r s P H P sup
po
r t s he st an
da
rmd
at he
m at i c al
op
er at or s:
/ /M o d u lu s ( r e m a in d e r o f $ a / $ b ) : $ a %
$ b = 0
$a 4 = ; 2; = $b / /A d d it io n : $ a + b = 6 //S u b tr a c tio n : $ a - $ b = 2 / /M u lt ip lic a t io n : $ a * $ b = 8 / /D iv is io n : $ a / $ b = 2 / /I n c r e m e n t : $ a + + ( w o u ld e q u a l 5 s in c e $ a = 4 )
A si
g n m en
T he t w m o
ai a n s i
gn
t O p er at o r s m en
t op
erat
i ors
p n hp " are
= " an ". d " . T he eq
ua
l si s
gn sh
ou
l b d o e bv
i ou
s; i t as
$a 4 = ; $a; = $b // $ b = 4
C om P H P sup
par po
i son r t t s he st an
O per da
r c om d
at or s pa
r i o son
pe
r at or s, sh as
ow
in n
T ab
l1 e - 1
:
si gn v a s
al ue t a o va
r i ab
l e:
T ab
l 1- e
1. C o m p ar i so O n
p er at o r i s P n
O P E R A T O R $b = $a $a ! $ = b
t es
t i f t w o va
l u e a s r e e q ua
l
t es
t i f t w o va
l u e a s r n e o t e q ua
l
$b < $a
t e i st f t h e f i r va st
l u e i l s e s t h a n t h e se
$b > $a
t e st i f t h e f i r st va
l u e i g s r e a t e r t h a n t h e se
$b <= $a
t e i st f t h e f i r val st
u e i s l e s t h a n o eq r
$b >= $a
t e i st f t h e f i r val st
u e i s g r e a t e t r h a n o eq r
P H P al su so
p
H P
D E S C R IP T IO N
or t t s he st an
da
r i d ncr
em
en
t an de d
c r em
en
t op
co
n d co
n d
u a l t o t h e se
co
u a l t o t h e se
n d co
n d
er at or s:
$a 5 = ; $a+; // $ a = 6 5; = $b $b- ; //$ b = 4
C o n ca T he " . " op $se $s $sen
en
t en erat
c on or
nt en
c e_
t en
ce
t enc
at i n g S t r i n g s ca
"Th = a
t en
at es t w v o al ue
qu e
i br c k
ow
_b = " f ox j um
pe
d. . . " ;
= _c
s:
"n ;
. $a $b;
//$ s e n te n c e _ c = " T h e q u ic k b r o w n fo x ju m p e d ..." ;
T o p
A r r ay P H P su i ndex
s p
ort b s ot h nu nam by
$ a = a r r a y(1,
keys) ed
m eri
ca
l ar
ay (ar s
r ay i t em
a s r e i nd
ex
ed by t he
i r nu
m eri
ca
l orde )
as w el l as as
so
c i at i ve ar
ay (ar s
r ay i t em
as r e
.
2 ,3 ,4 ) ;
//$ a [0 ] = 1 //$ a [1 ] = 2 //$ a [2 ] = 3 //$ a [3 ] = 4 $b = ar r ay(" an m e"=> " F r ed / / $ b [ 'n a m e '] = " F r e d "
" , " ag => e"
30
);
/ / $ b [ 'a g e '] = 3 0
T o p
I f / T h en S t at em O ne of t he m os ev
t co
en
ts
m m on P H P l an
al u at a e e n xp
r e si
on a nd t he
gu
ag c o e
n , de
p en
ns
t r uc
t t s ha
t yo w u
i l l en
co
un
d i n i g f i t i t s r u o e r n o t , t a ke c a ou
t i er t s he i f / t he st n r se o f a c t i on
at em
en
am
p le :
. F o r ex
t . T he i f / t he st n
at em
en
t al l ow
yo s
tu o
$a 1 = ; i f ($ a { ) ec
ho " T r ue
!" ;
} S i nc
e $ a = t 1, h en P H P i n t e r p r e t i s t i n t h e c o
n t ex
t o f t he i f st a t em
m e s a g e . L i t e r a l l yo y
u c a rea n
A no
hi t s i m e w i t h an " el se cl " au
t he
r ex
am
pl t but e,
e t nt o b e a b o ol e an t yp S e.
i d t a "I s f T r u e , t h e n p r i n t o u t "True se
i n c e 1 = t r u e , t h e i f st a t e m en
t p s r i n t o s t ut h e
! ".
:
$a 5 = ; $b "10 ; = i f ( $ a > $ b ){ ec i"$aho s great
er t ha
$b n
";
} e l se { ec i"$aho
not s
great
er t ha
$b n
";
} P H P d o es t h e e xp
n' t ca
r t e h a t $ i a a s i n n t e g e r an $ d i b a s st r i ng
a l so i m p o r t a n t t o n o t tha e se
co
. I t r ec
og
n i ze t s h a t $ a b l so m a ke p a s
r e s i o n , " I f $ a i g s r e a t e r t h a n $ b t h e n p r i n t o u t t h a t $ a i g s r e a t e r t h a n $ b ; i f n o t ( e l se nd p art o f t he e xp
N ot t e he us o e f bracke O n e f i n a l e xa
t yo r es
u d o n ' t sa
si on
y, "$a
i l s e tha s
, t h e el se st a t e m en
t t s e o nc
l os t e he ac
m p l e i t s h e i f / e l se
t i on
$ n b , " si n ce i t i p s o s i b l tha e t , i t s h e p a r t t h a t r un
s. A l so no
t t e he l ac o k f se
r e t t g y o i d n t eg
e r as w e l l . I t t h en e va
lu a te s
) t h e n p r i n t o u t $ a in s o t g r e a t e r t h a n $ b . I " t ' s
t $ c a o u l d b e e q u a l t o $ b . I f t h a t i t s h c e a se
,t h e n t h e
s. m i co
l on w s
he
r t e he bracke
t a s r u e se
d.
i f / e l se st a t e m e n t :
i f ( $ a = = $ b ){ / / d o s o m e t h in g el } se
i f( $ a > $ b { )
/ / dos m
et hi ngel
el } se
if ( $ a < $ b {)
/ / do ye } e l se
t so
se
m e t hi n g e l se
{
/ / i f n o t h i n eg l se w de to h i s.
.
}
T o p
S w i t ch S t at em I t n he C progam co da
en
m i ng l an
m p u t at i on t a, ev en t oh
st at em
en
$a "10 =
gu
ts
ag
e, sw
i t c h st at em
en
t su
p
ort arose
ou
t of t he ne
ed l f a or
i t t l e so
m et hi ng ex
t r a w he d n oi ng i f / t he t n yp
es of
. W i t h t he i f / t h en st a t e m en t , yo u a r e l o cke d i n t o a si ng l e co n di t i o n . S w i t ch st at e m e n t a s l l ow f a or d d i t i o n al ev al u at i on o s f t h e ug o h en of t he ca se m s h ay av b e e m n et . S w i t s ch t at em en t ca s a n l s so av yo e f u r om t yp i ng m an i y f / el se i f / el se i f / …
t s. P H P f ol l ow
Cs
' use s
of sw
i t st c h
at em
en
t s.
0";
sw
i t ch ca
( $ a {)
se(
10
ec h br ea c ase
):
o " T he val
ue i s 10
( 10 ec h
0) : o " T he val
c ase
";
k;
( 10 ec h
0
o " T he val br ea
ue i s 10
0<
br >";
ue i s 10
0
";
):
k;
d e fa u lt : echo"
>A
r e you
sur
e you
en
t er ed a nu
m ber?"
;
r ba
si p c ar t s:
} A yo s
u c an
se
, sw
i t c h st at em
en
i t ch—
T he sw
T he sw ab
ov you e,
T ca he
t h s ave
i t c h i de
t el l t he sw se—
T ca he
f ou
nt i f i es w ha
i t c h st at em st se
at em
en en
t eval
w ay yo
u ' d u se a n i f st a t e m e n t . I f t he ca
en
nt er a s br ea co k
c ou
B r ea
kp
oi nt s—
m m an
t ed w he a n case(
D ef au
l t — T he de
ex c u
t ed
) mi s f au
l t ai s sp
t va
l ue exp or
t yo
u g are
oi ng t o ev
t es va he
r i ab p l you e
uat se ho
co
r es
si on i g s oi ng t b o e e va al ua
i nt ex
m m an
c ut
t e t he va as ed
l d t s r u e , t h e n e ve
d, at w hi ch po
D ef i ne b d t y he break
ex c u
t t ha
f r om
i t t he pa
r se
r f r om
t he sw
t ed ie n ac o h f t he ca
l e $a i n t he su
t sw he
bs
i t c om c h
r yt h i ng af t e r t he ca
i on st op a s nd t he sw
d, ex
l ua
r i ab
eq m an
se st a t em
i t ch ei s xi t ed i t ch
. B r ea
r ca
se st at em
ue
en
se nt ca
d. Y c a ou t i e s xe
s. I t n he ex se c a use n
cu
am
pl e
s.
t e un d,
se(
) t sa he
m e
t i l t h e p a r se
r
. kp
oi nt no are s
r m al l pu y
t af t st er
at em
en
ts
et . ec
i al ki nd case of
. I t ie s xe
cu
t ed i f no
ne t of he ot he
en
t i s n t he sw
i t ch ha
ve be
en
.
T o p
Fo
r Lo
op
s
F o r l o op a s r e us
ef u l c o
n st r u c t i on t s o l o op t h r ou
f o r( $ i = 0 ; $ i < si ze
o f ( $ a r r a y); $ i + + { )
g h a f i n i t e se
dat of
t a , su
c h a d s a t a i n a n a r r a y:
/ / d o s o m e t h in g w it h a r r a y [ $ i] ; } F l or o
ps r eq
ui r e t hre
t hi ng w s
he
C ou
nt er — I t n he ab
f st or
at e m e n t .
T h c e o n d i t i o n r eq c on
t i nu
S t at em lo
tmo
ov e e xa
f i ne
d:
m pl e, $i 0 = . Y ou c a p n as i s a n a n l r ea a dy
u i r e d t c o o n t i n u t e h f e o r l o o p—
es t o be ex en
n t he a y r e de
c ut od
ed
i f t y he cou
I n t h e ab
o ve ex
si
am
gn
ed va
r i ab
l o e r as
p l e ,w h i l$ e i l s e t s
si gn va a
l ue t t o he va
h a t n h e si ze o f t h e $a
r i ab
li e t n h e
r r a y, t h f e o r l o op
. nt e on er
ac h
pa of s
t he l o
p—
I t n he ab
ove
exa
m pl e, $i + i ncr
em
en
t s he cou
nt af er
t eac h er
p.
T o p
Fo
r eac
F oreac $a
Lh o h lo
r r ay = ar
f orea
ps al l ow
yo
( " na
m = e"
ay
c h ( $ ar echo
"
ay as $ va
>$
ps
val
";
H y unt
er
u t o qu
i c kl t y r av t ers
> " Je
t " , " oc
cu
pa
hrou t i on => "
gh an ar " B ou
nt H y
ay
. un
t er"
l ue i s n t he ar
ay
);
l ){
} P r in ts o u t:
Jet
>B
ount
Y ou c a
n al so us
f oreac
h ( $a ec h
e f orea
r r ay as $k
"
>$ : key
$va
ch l o
ps t o ge
ey = > $v
al ) {
t he ke o y f t he va
:
l" ;
} P r in ts o u t:
>nam
>o
: e Jet c upa
t i on : B ou
nt H y
unt
er
T o p
W hi lLo e W h ile o ev ex
op
s
p a s r a e n ot h e r us
ef u l c o
n st r u ct t l o o op t hrou
g d h a t a .W h i l e o
al ua t es t o f al se . A co m m on us e t of eh w hi l e l o p it s o r et t urn ec ut e u nt i l a l l o f t he r o w h s a ve b e n r et u r n e f d r o m t h res e
w hi l e ( $ r o w = m ysq
l _f e t ch
_ ar
ay
( $ r es
he r ow i s n an ar ul t se t :
p co s
n t i n ue t l o o op un ay f r om
a r es
ul t se
t i l t he e xp
r es
t . T he w hi l e l o
si on i n t he w hi l e l o o p p co
nt i nu
es t o
ul t ) { )
/ / d o s o m e t h in g w it h t h e r e s u ltin g r o w } Y ou ca a n l so us t e he co w hi l e ( $ r o w = m ysq i f ($ro co nt i nu
nt i nu c e om l _f e t ch
w [ ' n a m e ' ] ! = "Je
_ ar
m an t d s o ki o p ve ay
( $ r es
r t he cu
r r en
t i t erat
i on of t he l o
p, t he c n on
t i nu
e. F exa or
m pl e:
ul t ) { )
t ") ) {
e;
} e l se { / / do s m
et hi ngw
i t h t her
ow
}
T o p
D Wo
hi Llop e
D o w hi l e l o ev
al ua
s no
t he
t es t he w hi l e ex
ps a are
pres i
r us
ef ul l o
p co
ns
on af t er he l o
t r uc
t . D o w hi l e l o
p ha c s om
pl et ed
ps w exa ork , i ns
t ea
ct lt y he sa d bef of
t ore
m e as no
he l o
p ex
r m al w hi l e l o ec
ut es
, as i n a no
ps
, ex
ce
pt t ha
r m al w hi l e l o
t he scr
i pt
p.
T eh i m po r t an t di f f ern ce be t w e a n do w hi l e o a p dn n a orm al w hi l e o i p t s ha d t a w o ih l e o i p a s l w ay e s xe cu t ed at l ea st on ce . A no r m al w hi l e l o m p ay no t be ex ec ut ed at al l , de pe dn i ng on t he ex presi on . T he f ol l ow i ng do w hi l e l o p ie s xe cu t ed on t e i m e, pri tn i ng ou
t $ i t o t h e sc re
n:
$ i= 0 ; d o { p ri n t $ i ; }w h ile ( $ i> 0 ) ; W h er a
t s h f e o l l ow
i ng i n s o t ex
ec
ut e a d t a l l :
$ i= 0 ; w h i l e ( $ 0i > ) { p ri n $i; t } Q ui t e f r an
kl y, I ne
ve
r f i nd m uc
h us
e f do or
w hi l e l o
ps
, bu
t yo
u m ay f i nd an od
d probl
em
t ha
t r eq
ui r es i t .
T o p
U se
r - D ef i n ed F u n ct i o n s
I a n d di t i o t n o P H P ' b s ui l t - i f n u n c t i o n s, yo c u an c r e a t y e o u r o w n f un of t h f e u n c t i o n , t h e y n o m u
u st d ec
f un
ge
c t i on c h i f ( $a
ec
k_
ag
e($a
l a r t e h e m a g s l o ba
l va
r i a bl e o s r as
c t i on
s. R e m e m b e r t ha
si g t n h e m a a s r g um
t i f yo w u en
a n t o us v e ari
t t s t o h f e un
c t i on i t se
a bl es t h a t ex
i st o ut si d e
lf.
){
g >e 2 1 ){
re tu rn 1 ; } e l se { re tu rn 0 ; } } //u s a g e : i f ( ch
e c k_
e"cho
a g e($a Y mou
g e) ay ent
{
er ! " ;
} e l se { ec h
o " A c es
N ot A l l ow
ed
!" ;
e x it; } T h e f u nc $age
t i o n w o ul d b e c a
l l ed f r o m w i t h i n yo sc ri ur
at pt
t h e ap
p r o pri
a t e t i m usi e,
ng t he f o l l o w i n g syn
t a x:
1 = 0;
che k_age($ ); / / p r in t s " A c c e s s N o t A llo w e d ! " t o t h e s c r e e n
T o p
O b j ect P H P sup ex
O r i ent po
t en
r tO s
bj ec t
de f d gr or
ea
T o c r ea
t e an ad
c l as ad s
r es
ed P r o g r am O r i en
t r er
eu
dr es s_
en
bo
t ed P r og
se of c o t r cl y
ok
_e
r am
de
as
m in gw ithP H P
m i ng ( O O P ) it n he f or m of cl ase
s. Just
l i ke o n t he
r O O P l an
gu
ag
es,
t he cl ase
c an s
.
t ha
t c on
t ai ns a pe
r son
f ' s i r st an
d l ast
na
m e an
d ph
on
e nu
m be
r:
h at h as t h s e a m f e un
c t i on
a l i t o y f t h o e l c d l as
nt r { y
v a $ r f i rst; va
r $ l a st ; $num ber
var
;
f u n ct i o sen
t _ n a m e ( $ f i r st , $ l a st ) {
$ t h i s -> f i rst = $ f i rst; $ t h i s->
l a st = $ l a st;
} f un
c t i on set
_n
$t hi s- >nu
um
m ber
be
r ( $n
um
= $num
be
ber
r ){
;
} f u n c t i o n d i sp e ch
l a y_
e n t r y() {
o " < p > N a m e : " . $ t h i s->
ec h }
o "
r >N
um
be
f i rst . " " . $ t h i s->
r : " . $t hi s- >n
um
be
l a st; r;
} //U s a g e : $en
t &r = y
new
ad
r es_b
o k_
$e
nt r y- > se
t _n
am
e("
Ja
$e
nt r y- > set
_n
um
be
r("5
$ e n t r y->d
i sp
l a y_
en
ne
t r y;
" , " S m i t h") 5- 5
e n t r y()
5- 5
; 5
");
;
/ /d is p la y s : N am
e: S Jane
N um
ber
m ith :5-
5-
5
A d d i t i o n al l y, yo c u a e n xt e n a d e n xi st i ng cl as t s c o r ea f u n c t i o n a l i t yo y
au d d :
c l a as
bo
va
d r $e
f un
r es _
ok_
en
t r e y2
xt en a ds
d
r es _
m ai l ; c t i on se
t _e
m ai l ( $ e m a i {l )
$t hi s- > em
ai l = $e
m ai l ;
} f u n c t i o n d i sp l a y_ e n t r y2 ( ) { e c h o " < p > N a m e : " . $ t h i s-> f i rst . " " . $ t h i s-> l a st; ec h o "
N um be r : " . $t hi s- >n um be r ; e ch
o " < b r > E m a i l : " . $t h i s->e
m a il;
} } //U s a g e : $en
t &r = y
new
ad
r es_b
o k_
$e
nt r y- > se
t _n
am
e("
Ja
$e
nt r y- > set
_n
um
be
r("5
$e
nt r y- > se
t _e
m ai l ( " j sm
$ e n t r y->d
i sp
l a y_
e n t r y()
en
ne
t r y2;
" , " S m i t h") 5- 5 i t h@ ;
5- 5 co
m . co
; 5
"); m ");
t a e n ew
bo
ok_
cl a t s
en
t r{y
s, pl us an n y e w
be
/ /d is p la y s : N am
e: S Jane
N um
ber
E m ai l : sm
m ith :5-
5i t h@
5 c om
. c om
T o p
p h p i n f o () ph
p i n f o ( ) i a s ve
se
t t i n g t s h a t a r e e n a b l e i d tha n
r u y se
f u l f un
T h r ou g oh u t t h i b s o o k, t he f o llo w in g :
c t i on t h at a l l ow t ve
yo s
u t s o e e w h a t ve
r si on of P H P i r s u n n i n o g n yo W ur
e b se
r ve
r ,a w s
e l l a a s l l o f t h e sp
ec
if ic
r si o n .
r e a r e se
ct i o ns t h a t a sk yo
u t o ve
r i f y y ou
r se
t t i n g s. O ne w ay t o d o t h i s t s o crea
t e a sc ri
t pt ha
t i n c l ud
e j s us
th e
e c i a l l u y se
f u l i f yo
u a r e w o r ki n g o n
< ? p h p in fo ( ) ; ? > U po so
n e xe
cu
t i on t of h e sc ri
m e b od e y l se
' se s
r ve
pt , t he b r ow r a n d a r e no
se
r d i sp
t q ui t e su
l a t ys
h e cu
r e o f i t ca s
pa
r r en b i l i t i es
t P H P se
t t i n g s. T hi f s u nc
t i o n i e s sp
.
T o p
A d d i t i o n al R es
o u r ce
s
I f yo s u t i l l n e e a d d d i t i o n a l i n f o r m a t i o o n t n h b e a si o c s ut m ost
P H P begi
ner
C or P e H P P r ogr E s en
f P H P , t h fol e
l o w i n b g o o fr ks
o m P r e n t i c e H a l l p r o vi d m e
a t e r i a l su
i t a b l fe o r t h e
:
am
m i ng:
t i al P H P f W or [1 ]
S
sa
U si P ng
eb P r of es i
ha
m el p es
H P Bt o ui D l d ynam on
al s
C by
l ug f or m ow y
i t d he b o r k e a l l h y el pe
bn o
W i c S eb hr i st oph
k, I kno
w , bu
i t es
(
er C osen
t I ' r ve
ec
2nd
E di tLe byi on)
t i no
. I S B N 013
08
i ved
l a ot of em
ai lf r om
on A t ki nso
903
np
308
93
86.
[1 ]
2.
no
. I S B N 01
r og
r am
m er w s
ho
d !
T o p
C h apt I T n hi C s
ha
er 2. S es i
o Mn
an g
em
ent
pt er I nt r od
uc t
i on t S o
In i ti a l p hp
t en
t o s f S es i
U nregi
st eri
M on
Pi n H P 4 an
age
m en
t
on F i l es
l es ac r
ng S es
ng S esi
A S i m pl S e es i
ent
si o n
ng V ar i ab
r oyi
gem
et t i ng f s or S esi
T r ac ki
D est
on M an
. i n Si
S t a r t i n a g S es T he C on
es i
P ag
si on V ari on
on-
os
ab
es du
r i ng S a
es i
on
l es
s B ased
S hop
i ng C ar t
T o p
I n t r o d u ct i o n t o S esi T hi cha s S es
pt er i nt r od si on m an
ag
uc e em
you s en
t se o
t al l ow
si
so
S es
si on t are s
vi ew
i n yo sc r ur
S om
u e se
usi
t ng
ci a t e w d yp
he co
s ay
i ca
ke b d P y H P p by
l l i ng t he $P
et up t he
ki m e
t t o r ac vari k
r.
l l t y r ac
et ho
ag
em ab
ag en
l a es
em
en
ti n P H P 4
t usi
ng P H P 4' bu s
i l t - ise n
so
ci at ed w i ut a h
se
si
r f or sp a
i r brow
l ac
i ng co a
H P S E S S I D va se
r t so s
ha
t he do y
ok r i ab no
i o e t n he us
er' brow s
ow
er, us
lH e. t ac
ce
ev pt c o
ok
i es
se i ng co
on m an ec
t e us i ng t he sa m e brow se r i ns t an ce . I f t he us cl er os o l on ge r as so ci at ed w i t h t ha t us er, un l es yo s u provi
i t t h he u se
i pt b s c a y r ms
on m an
you s
us spe er dn o s n pa ge o s n yo si ur t he n t he se si on va r i ab l es n are r e as
o n M an
i f iWc
em
ok
se
s, yo
si
t ec h
ni qu
on
es.
. A W eb se
si
on i t s he t i m t e ha
ta
se
r ( you or ex pl i ci t le y dn t he se si on ) , ay t ha t he va r i ab l es ca n be sa ve d an d l at er
i r e ef ernc
a es
l pro
f m et ho
i es i n s ot a f o
. I t n he ca se
en
eb se
es t he brow de w f a or
r . T he co ok
ag
ur se
si
on va
se r i ab
si
on I D , w hi y ch
d t o t r ac se k l c a es
n
si
ou c a on va
ot be t r ac
n
r i ab ke
l es
.
d
d.
P H P su p p ort l s i n rew k r i t i n g, w ih ch g et a s r o un d t he p r ob l em i s n u si n g co ok i e t s s o t se ore si o i n nf o r m at i on . W i t h l i n r k e w r i t i n g , P H P a l t e r s an l y i nk o s n yo pa ur ge so t ha t he a y ut om at i ca l l i y cn l ud e t he $P H P S E S S I D va r i ab l e. T hi d s oe m s ak e t eh l i nk l s o a k l i t t l m e es t sy o t eh us
er, b u t i s n om
c e a se i s t i t s h o e n l w y
a t y b o s e u r t e h a t yo a u r a e c u
r at e l t y r ac
ki n a g u se
r ' se s
si
o n.
T o p
I n i ti a l p h p .in i B ef or yo e co
u ge
S
et t i n g f s o r S esi
t s ar t ed w i t h t hi ch s
ap
t er , you
m ay ha
o Mn
an
ve t m o
ake
a c ou
pl o e f m i no
H P , t he f i r st t hi ng yo
u ne
ed t o do it s o ed
ag
em
r cha
ng
en
es t y o ou
t p h p. i ni f i l e so t h a t se s i
r
on w s
o rk
r e c tl y .
OWn I f yo
i nd u u are
w i l l no
ow
s
si ng a W i nd t w c or ork
ow
ec
ve s
r si on P of
t lu y nd W er
i nd
ow
p h p. i ni f i l e , w h i c h i fou s
O your pen se i
on
C ha
. save
ng
se i
_p
. save ul a d l so
ex
pl e, i f yo
am
t he se
si
A go
od i nd
se i
on
t i ory
_p
Y ou c o
n w hi ch yo
at = h C : / t em
ea t ve
he va
ur W eb se
o n. sa
ve
i ca
t i on t ha
- en
ab
p hp
ur
. i n if i l e . T h e d e f a u l t se s i o n se t t i n g i n
p hp
n d i n c : \ w i n d o w o s c : r \ w i n n t , i n a t e ed xt
i t o an r
d se
a r ch f o t r h e l i n e :
at h = / t m p
e i t t o a di r ec on
i t yo
s.
l ue / as
r ve
po
r f ary
t m a p nd cr ea
r w l as
oc
i l es
si
on
t a e di r ec
at ed i D n
, f exa or
m pl e:
: / ap
ac
he
t na ory
m ed " t m at p"
/ bi n, t he yo n
co u
en se
r r ec
t he r o
ul c rea d
t of t he dri o ve t t e he di r ec
wn
hi y ch
t d: ory
ou
r W eb se
/ t m a p nd yo w u
r ve
ou
r r es
i de
s. F or
l n d ot ha t ve ch o
an
ge
p h p . in i.
ttin g in
t he se ge
ep t em
p
_ p at h se
l pa ed
u ke
. sa
ve
_p
at h h n as
ot be
t co
t l on y
W i nd
ow
i s i s f A pa
c h c rash e
w es
he yo n
t u r t y l o oa a d
.
O L n i nux I f yo a u r u e si ng Li nu T yp
i ca
x, yo n u e t d m o
l l t y h i s t s h u e se
ak su e
r n ob
o dy
,a n m d
si
o n se
t t i ng sh s
o f t h d e e f au
G en
er al C o n si d er at i o n s ou
l d no
t st t ore
be an d y i r ec
t un ory
W eb se
r i b s ec
se
si
r ve
on i s t n hi m s
he se de ne
o u l d w f ork
on f i l es i n an d y i r ec
r t he ht do d cs
au an
si
i r ec
t ory.
se m al i c i ou u s se
rms
r.
t yo / ur t m d p i r ec t e m s, by d e f au
T h rest e
Y ou sh
l t se
r t e ha o st sy
t w ory
T he r ea ay be ab
t b c an ory
we
l t , a l l ow
i n f e o r yo i u t n h e e xa
hi ch iv s
ew
so y n ou do no l t e o o pe t n ho
ab t w an
r i t t en t b o t y he us w er
t h n e o bo
d u y se
m pl es i n t h i c h s
l e f r om
yo W ur
se f i l es an v d i ew
ap
eb se
t t p o l ac s e es i nd
ho r un t s he W eb proce
se
s.
e, t he
n t ha
r t o w r i t e t t o h / e t m p d i r e c t o r y. te r.
r ve
r . I f yo
u u are
si on i vi du
si ng A pa
ch
f i l e s i n a d i re al se
si
on da
t a, an e d ve h n i j ac u k se
t w ou
ld
c t o r y t h a t i s vi e w a b l e r 's
f r om
your
. in i
T o p
S t a r t i n gSa Y ou c an
no
t r ac k
e s s io n vari
ab
va
r i a b l e s. S t a r t i n a g se
se
s i o n _ star
se
si
o n_
t em
l es ac r
um
st a r t ( ) t a ke n s o a r g um
t es
he cu
r r en
si
on
t se
si
r e g i st e r e u d si n g t h e se si
on
_reg
i st er(
be ac es d
pa
you
st ar t he se i
on on ea
c h pa
ge on w hi ch you
w an
t o use
al or
t er ho
se
ha
i n a g ne
on
ge ha ac s
w se
es t s a o va ny
, yo n u e ed t reg o
si
nd by t he f un
o n, t h en t he f un c t i on
r i ab
i st som er
, ei t he
l t es
v e ari
ha
ct i on i n i t i a l i ze t s he se
r by a c o
t ha b ve
a bl e w s
ok
si
o a n n c d r ea
r i ab
l e, t he
n t he f un
t o he se
si
on
on w i l l n ot t r a v c k
ari
a bl es un
i Ge a or
e r n eg
E T va i st t er d
i t i h t . T h s e e si
t e t s he n ec
es
c t i on
. t i l t h e h y av b e e en
s i o n _ r e g i st e r ( ) f u n c t i o n :
t t s o es
an os
si on
se i y
on-
t e.
st er( abl
on an
S c ri
p t 2- s 1 es
_regi en
ve st ar t ed t he se i
ge o s n yo si ur
S cri
l es
H P S E S S I D i f s ou
on an t d he pa
en
ac r you
on un
S T R IN G );
T he S T R I N G argum
O nce
r se i
e nt s. I f yo a u r e st art
. I f a $P
O n c e yo h u av s e t a r t e t d h s e e s i
se
a use
();
p f i l es t o t r ac t k he se
r es
os
s i o u n se t s h s e e s i o n _ st a r t ( ) f u n c t i o n :
d r eg
p t 2 - 1 , se
) sh
ed pag
si
ou
l b d t e he na
m o e f t he va
r i ab
l t e ha
t yo w u
an
t regi o
st w er
i t t h he se
si
on so t ha
t i t m ay
on en
ab
l ed
d r e gi st e r i n g v a a r i ab
l e.
es.
i st er ed on o e r m or e var o n . ph
p , provi
i ab
l es,
d es a si m p l e e xa
you
c an
use
t ho
se var
m p l e o f st a r t i ng s a es
i ab
l es ac r
si on an
os
an se y
si
si o n . p h p
1 . < ? 2 . se s i o n _ star
();
3 . i f (! i s s e t ($c 4 .
se
5 .
$c ou
o u n t) {
s i o n _ r e g i st e r ( "c ou
n t ") ;
nt 1 = ;
6 . } 7 . ? > 8 . Y h ou
b ave
e t n t o hi pag s
< e ?=
$c ou
nt ?> t i m es.
9 . < ? 10.
$count
1.
+
;
? >
S cri
p t 2- 1. se
s
i o n . p h p L i n e- b y- L i n E e
L IN E 2
S t ar t se i he
3
T he i f st at em as
4
xp
l an
at i o n
D E S C R IP T IO N or on
su
m es t ha
I f t he $co
un
va
r i a b l $ e co
en
cont t che
e i an nue t c ks
t hi i s a s co t var
i ab un
l h e n as t.
xi st ise i ng se o
i e f t he $co
nt i nu ot be
on. un
t var
i ab
l h e b as
on an
d t ak
es no ac
i pt as u
m t es
at i on se a of
si
en set
, t he t n he scr
e se n
t . I f t he $co t i on an ha
un d t he scr
t hi i s t s he be
t var
i ab
l h e b as
e se n
ip gi n
t , t he t n he scr t co
i ng of n a ew
se i
nt i nu
on an r d eg
i pt e os
n t o lin e 7 . i st er t s he
sa
ry
L IN E 5
D E S C R IP T IO N S i nc $c o
e t he scr un
i pt ha j s us
8
D i spl l a ay
10
I ncr
em
iof ne ent
R un t hi scri s
pt an c d l i t c k
ea t c h
i m yo e
rel u
r e se
t t s he $c
t ext
i st er d
st at ti ng nu he
t$coun he
tvar
t he va
m ber
i abl on by e
he r el oa b d ut t on se
oa t d he pa ou
t r eg
r i ab
l e $c
ou
nt i n t he prec
di ng l i ne
, i t us
es t hi l s i ne t o as
si gn a de
f au
l t va
l ue of 1 t o
t.
ge
.
F i g 2 ure
n t t o ' 1' , as cl o si ng t he b r o w se
of t i m t es pa he
ha ge
vi be n s
ew
ed.
e.
ve
r al t i m es - 1 sho r e f f ec
. N ot i ce t ha w an s
t i ve
exa
t he nu
m be
r of t i m es t he pa
m pl o e f t hi s. C l osi
l e y n d t s h e se
si
ng t he br ow
ge ha b s e v n i ew t ser
he rel n
oa
ed i nc
r ea
di ng t he pa
se b s o y ne ge ia n ne
w br ow
ser
o n .
F i g u r 2 e - 1. se
s
io n .p h p
T o p
T h Ce
o n t en
Y o u ca
n vi ew
t o s f S es
t h e a c t u al c o
si o n F i l es
nt e n t o s f se
si
o n va
r i a b l e b s l y o o ki n g i n t h e di r e c t o r sp y
f i l e. I t n ha t di r ec t ory, yo sh u ou i m po r t a n t p a r t it s h t at h e f i l e an
l se d f a e i l n e am ed so m et hi gn al on t g eh l i ne of s " se m e b eg i ns w i t h " se s_ . Th " e r an d om st r i n g cha of
as
u o are
si gn t s o ea
c h se
l i ke P H P se gi ve yo co
va
on f i l es
. I f yo
n a sh
. T r t y o f i nd t he on si
on va
ared
si t e you or
ha
e w i t h t he t i m es r i ab
ve r un an se y
t am
p c l os
l e a s r e st o r ed
es
. O p en
si
t t o w he
c4
a9
u ac
i ng t he f i l e i n a t ex
si
2c
17
o n . sa 45
30
r a ct e r a s f t e r t h i at t s he un
on i s n t he pa n yo
72
st , t he
ce
se
n t he
r e m ay be se
d t he ex
t e d i t o r di sp
ve
am
_ p a t h se
t t i n g i n yo
u r
p hp
. in i
45 4 dc 5c b c1 3e 08 9 6. " T he i qu e i d en t i f i t er h a t P H P ve
pl e, bu
r al f i l es t ha
t op
en
tl o
k
i ng an o y f t he f i l es w i l l
l a ys t h e f ol l o w i n g:
u n t |i: 6 ; t ua
l nu
m be
l a t y h e va l u e o f t he va
t orde se i
on
u a n i d ea o f h o w t h e se
T he ac di sp
si
si
e c i f i ed i n t h e se s_
r di sp
, $c o
ed i n t he f i l e w i l lbe di f f ern
pe
nd
i ng on ho
w m an t y i m es yo
r i ab
u h a ve m u l t i p l e va
r i a bl es r eg
se b s s y em
s. F exa or
l e f o l l ow
e d b a y se
st sep er d, un
t , de
b ol , f o l l o w e d by t h e va
he w y regi er on
l ay
r i a bl e n a m e , f ol l o w ed b a y p i p e sym
t an
d $d
m i co
ar t ay,
t he
l o I n. f yo
ed i n m os
n t he w y
ou
t ca
la d p
ea
r as f ol l ow
i co
l on
r i a b l e t yp
u r el oa
de
e id e n tif ie r — i st er d
i n t he se
m pl i e, f yo
u ha
d t he pa
ge
. T he co
nt en
i n t hi c s a se " if " o i r n t eg si
t o s f t he f i l e
e r—
an
d f i n al lt y he
o n , t h en t h ey w o u l d be l i st e d i n t he
d t w o i nt eg vari er
ab
l es r eg
i st er d
i n t he
s:
c o u n t |i: 6 ; d a y |i:7 ; T ab
l2 e - 1 d
et ai lso s
m e t of he co
m m on va
r i ab
l e t yp
es yo
T a b l e 2 - 1 . V ari S Y M B O L i
u m i gh
t se
e i n a t yp
i ca
l se
si
a b l e T y p e I d e n t i f i i ers
on
. f i l e.
n S es
s io n F ile s V A R I A B T LY EP E In te g e r
s
S t r in g
b
B o o le a n
d
F lo a t
a
A rra y
O
O b je c t
N
N U L L
T o p
T r ac N ow
ki n g V ar i ab t ha
t you
kno
se si o ns r eg i st er d c an
ose i ca
t o en
l l y, yo
t rem o
em
as u
be
ab
t sh ures
da
t ab
ne
si
ag d es
on an t d r so ac k
ase
sab
m va e
r i ab
u r i n g S a es l es,
ho
w ab
ou
he
se va n' t w an
ng co
se pref t se o
l d be en
ab
ernc
you , or ds c an
i es f eac or
f h ea
t op ure
one
er' b s r ow
se
o l n i n r k e w r i t i n f g ea
si
I n t h i n s e ex t t he se
si
se
r , el i m i na
ge as s
ul d st t ore l ea
3 . se s i o n _ reg
l ue w s
s. I f us do ers
t o se a e P ol l f ea
w el l . Y ou c ou
l q d ue
t i nf orm
at i on i n c a o
e ser i c kl
t i ng t he w or o y f ex
u 'll o
s ad
_p
i ou se s
t y i urns
r r ver
nt a o co
ce
ed
n' t w an
r t y he da
t ab
om
de
S c ri
or
e f a u l t va
a y bo
"l a st"
di ng ni gh
t m are:
6 . se s i
w s_
_ r e gi st e r ( " ne
pref
s")
;
7 . ? > tm l>
9 . 1 0 . < t i t l e > W e l co m e < / t i t l e > 1 1 . < st yl t e yp e = "t e xt / c s s"> p , u l , h 3 { f o n t -f a m i l ve y:
r d a n a , h e l ve
t i ca
, sa
1 3 . . e n a b l e d { f o n t - w e i g h t : b o l d ; co l o r : g r e e n ; } 1 4 . . d i sa b l e d { f o n t - w e i g h t : b o l d ; c o l o r : r e d ; } < / styl
e >
16.
hea
d>
17.
18.
< ?
19.
f un
c t i on l o a d_
u se
r _ da
ta (){
20.
g l o b a l $ f i r st , $ l a st , $ e m a i l , $ n e w s_
21.
$ f i r st = "F a ye
2.
$ l a st = " V a l e n t i n e " ;
23.
$em
ai "f =l aye@
"; be o
p. c om
";
p r e f s;
n s- e
cork of
l em
t o ure
n on
i m t e he use
r a e r e draw
o ea
f s l or ar ge si t es.
A co
W he y n ou ha m ve
e pa
r l oa a ds
ba t c ks
ri f ; }
s ed on
f se
or t us
ers
t ore
ge pa
, t he
n i t 'sa s
ge t se o
ch m et ho ki e c an
we
hi ch
d. Q ue on
r yi ng t he
hl y ol d on
ha o n ne t or w f o ea
ay
ft e o
e val
t ures,
ue yo
, u' d
ac r m os an pa y ge s. Y ou ke t p eh da t ab ase , an y d ou on l n y e t d w o or a y bo ut st ori gn on c e o ki o e n i es an o y ne si t e ca
n st o ore
n a brow
r c om e
i ng
se
r . I f yo
u us
e P H P 's
ki e !
s i o n a is ft h e wy
. p h p . T h e r e su
); a i l ") ;
m be
r i a b l e i s n t o a se
p t 2 - 3 , t r a c k - p r e f s2
") ;
5 . se s i o n _ r e g i st e r ( "em
15.
ea t c h
t he
ur c e pr ob
u t h a to n c e o
(); r( "f i rst
12.
ase
ki e, bu
eso
i ng t he f i ni t e nu
r e fs 1 .p h p
4 . se s i o n _ r e g i ster(
8 .
t l u es
ed w a
as a e nd l oa t d he va
t u r e, yo d u o n ' t e ve h n a ve t w o
i ste
on
un
he t n he us l er og i s nt t o he si t e. Y ou ne
po
ew
1 . < ? 2 . se s i o n _ star
r a e r co e
t h as ha
t ab
ha
d t o som t i on qu
a bl es w o r i k n
S c r i p t 2 - t 2 r a ck
T he
r ve r . T h i n o k tf a yp i ca l si t t e ha dn t o, an d va r i ou o s t he r f ea t t ures
!
a m p l e , yo o v n ari
m u e se? eb se
t he us vi er
T ih i s w s eh r se e si on can s eh l p. Y ou can st or m e ul t i pl va e l ue t s ah t can be ac e qu eri t es a o m i ni m um by l oa di gn t he us pr er ef er n ce a s t he st art of t he se si t he us
t t i ng t hi t s so o
a nd yo W ur t us c an ers r es
s e ort of da
ge t ha
r pa co
ge l oa
f e or eac h
es i s n om h pa
i e t on ot he l ed
c h t i m e a pa ok
t pu
si o n
l e.
l ue a s c r os e s ac
ea
a d c o ki
l e di or
u' s d t t ore
ou
so st ori
ar se t a
r t he
m t e he do y
f ea
w ts o
r o Ps
, b u t h rea e l b e ne f i t o f se si on i s t s red o u c e t h a e m ou n t o f w f ork you r us ers. T hi si s t e m ay ah ve m es sa ge bo ards, f ea t st ure ori es t ah
cho
T yp
w ho
l es ac
e
l t w i l la p p e a i r n
F i g 2 ure
f r om -2 .
d a at ab
as q e ue
r an y
t d he v n eri
f t y ha
t
24.
$n
ew
s_p
r ef ar = s
25.
" Lo
26.
" N at i on
27.
" W or 1 l=> d"
28.
" C om
29.
ca
r ay(
l "= 0> , " = 1> , , i c s"
=> 0,
);
30.
}
31.
l oa
3 2 .?
d_
us
er_da
t a()
;
>
3.
W
34.
35.
36. 37.
< bod
38.
< / h tm l>
el c om W el c om >Y
set our
e
h3>
e < bac k t i ng ha s
a rh ef =t r ack_ y>
b>< b ve
?=$
f i r st ?><
en
pr ef s2.
l oa ph
de p>
/ b> .
V i ew
Y ou
r S et t i ng
s
a>
.
F i g u r 2 e - 2 . t r a c k _p
r e fs 2 .p h p
S cri
p t 2- 2. t r ac
k_
p r ef s1
. p h p L i n e- b y- L i n e E xp
L IN E 2 3–
S t ar t se he 6
R egi P r i nt out
19
D ec l
20
A l l ow va 23
9
6
ni
f es
of ng
t H he
i on,
l oad_use
f unct
t he f un
c t i on t u o a se
m st e
r i t ngs
or t use
i gn
t em
us
tH he
ut t se i he
on
l i es t n he gl ob
al sc op
page. L
nd m od
er _dat ha
a( ) .
i f var y
i ab
e a rl i e r i the n s i va on
sc
r i abl
ivar on
i abl
a( )f unc
t i on
s i o n _ star
$new e
s_pr
t he
i r se
t t i ng h s av b e e l n oa
de a d nd provi
r e fs 2 .p h p
();
tm l>
5 .
6 . < t i t l e > V i e w S e t t i n g s< / t i t l e > 7 . < st yl e t yp e = "t e xt / c s s"> 8 .
p , u l , h 3 {f o n t - f a m i l ve y:
9 .
. e n a b l e d { f o n t - w e i g h t : b o l d ; co l o r : g r e e n ; }
r d a n a , h e l ve
t i ca
, sa
n s- e
1 0 . . d i sa b l e d { f o n t - w e i g h t : b o l d ; c o l o r : r e d ; } 1.
< / styl
e >
12.
hea
d>
13.
14.
3>
V i ew
15.
>H
el l o < b>
16.
>E
m ai l :
17.
< p > Y ou
18.
< ?
19. 20.
w h i l e ( l i st ( $ ke i f ($v a l u e { )
21.
$v
24.
=$
=$
s
h3
>
f i r st ?> < ?=
em
$l ast
?>
b>
,
ai l ?>
t t i n g s: < u l >
y, $ va na
l u e = ) e ac
bl ed
";
bl ed
";
h($n
e w s_
p r e f s) { )
al ue = " D i sa
}
25. 2 7 .?
l ue "E =
et t i ng
} e l se {
23.
26.
r se
$va
2.
Y S our
p r i n t ( " < c l i a s = $ va } >
28.
< / u l>
29.
bod
30.
< / h tm l>
y>
r i ab
l c o es
ef s.
3 . ? > 4 .
i pt . T he va se
es.
1 . < ? se
o e f t he scr
r ip t.
f L or ptage. he
_p
.
r ay.
TM
S c r i p t 2 - t 3 r a ck
gho
r _dat
t o se he
t s t o ar he
oad_
C oult ose
2 .
at i o n
i on.
hr ou
TM
r t ay t o se he
N ot i f t y he us t ers
37– 8
i abl
ar new a e
R t un l he –3
st sei ng
r i a b l e t s h a t w e r e r e g i ster d
A si
31
exi ain nue
var on
A s ar ian gn
25–
cont
t begi he
A s i so gn
24
3
ori on
st er se i
8–17
21–
l an
D E S C R IP T IO N
l u e > $ ke $ y:
va
lu e < / li> " ) ;
r if ; }
de l a i nk t v o i ew
t he se
t t i ng
s.
r r esp
on t d t o he se i
on
S cri
p t 2- 3. t r ac
k_
p r ef s2
. p h p L i n e- b y- L i n e E xp
L IN E S t ar t se he
4–13
P r i nt out
19
17 –2
G re 6
E xe
ori on t begi he
cu
30
End
t h HTM e
cont ni
t he user
t o t h e sc re on t he scr 2 7–
at i o n
D E S C R IP T IO N
2
14–
l an
exi ain nue of ng
and s
show
t a e w hi l e o t p ha
st sei ng
t H he
TM som t go t es
i on.
page. L o e f t he
i r c ur
ho
ug t h he us
n . I f t he va l u e t of h e cu r r e n t ar e n. I e n i t he r ca se , t he va l ue de p L ag
r ent
set er' se s
t i ngs. t t i ng i s t n he $n
ew
s_
pref
se s
si
on va
ay i t e m ie s n a bl ed , t he n pri n t " E n a bl e o d" n t he scre t erm i ne w s ih ch C S S cl as sh s ou l d be us ed t o di sp
r i ab
l e. P r i nt t he ke of y t he ar n ; ot h e r w i se , pri l ay t he se t t i ng .
n t " D i sa
i ay
t em b le d "
e.
T o p
U n r eg
i st er i n g S es
Y ou m ay f i nd t ha
t som
un
r e g i st e r t h es
e va
se
si
on
_u
nregi
e of t he se i
e sn
se
st er(
on on
t i t s he na
r exam
e on
nl y e
d w i t h t h e se
m o e f t he va
r i ab
l t e ha
t yo w u
t he se
ec t k o se
e i f t he va
t t o f i r st c h
Fo
i st ar er
l et ed f r om
i st erd(S
r eg
r eg
e r t r a c ke
n de
ce i t ha b s e
_i s_
t you
t o s f t h v e a r i a b l o e t n h c e u r r e n t pa
se
on
l es t ha
t en
Y o u m a a y l so w an si
i ab
l es de
si
d on a f ew
pa
ge a s nd no
t ac r
os
o n . T h i s d s o ne u si n g t h e se
an en
si
o n_
t i r e si t e. Y ou c an
u nreg
i st er(
) f u n c t i on
:
S T R IN G ); en
' t d e l e t t e h c e on
si
on var
r i a bl es so t h a t t h e a y r e n o l o ng
T he S T R I N G argum do
si o n V ar i ab
si
t u o nregi
st f er r om
g e. H o w e ve
an
r , t he va
t he se r i ab
si
on
. N ot t e ha
l v e a l ue w i l l no
t us
i ng se
t b p e a se
si
on
_u
nreg
t d o o t h e r p ag
i st er e i s t n he
on f i l e. r i ab
l e i e s ve
n r e g i st e r e d b u y si ng t he se
si
o n_
i s_
r eg
i st er d
( ) f u n ct i o n :
T R IN G );
pl e:
/ /I f $ n a m e h a s b e e n r e g is t e r e d w it h t h e s e s s io n . i f ( se
s i o n _ i s_
unse
t ( $n se
si
am
on
r e g i st e r e d ( " n a m e " ) ) { e) ;
_u
nregi
st er(
" na
m e")
;
} T h i h s a t s he ef f e ct o f d e l e t i n g t h e va t u o ns
et t he va
se
si
o n_
se
si
on
se
si
on
se
si
o n_
un
t o uc
r i ab
l o es
u ns
et ( ) ;
_u
ns
et ( t ) ak
_u
nregi u ns
ha
r i a b l e f r om
t he se
ne at t a i m e. Y ou ca u n ns
et al l se
es no argu
st er( and ) et ( ) i f yo
b l b e se y
m en se
si
t s an
on
_u
u a l so w a t nt o u n se si
on
_ u ns
si
o w as n, si
el l a d s el et i ng t h e va
on va
r i ab
l b es
d si m pl d y el et es t he va ns
et ( ar ) t t h e va
e i nd
ep
en
l u e o f t he va
et ( ) , f o r i t i n s l o o n ge
rs a e si
l ue
de of nt
us y
s any of ea
r i ab
i ng t he co
va
ch ot he
l e f r o m t h e cu
m m an se d
si
r i ab
l es c u
r r en
t rleg y
r . H ow
ev
er, do no
t ca
r i ab
l e yo
u a r e u nreg
i st eri
on va
r i ab
l e. T h p e r o pe
n U g.
nreg
r o r d e r t u o ns
r r en on
t p ag
_u
ns
i st er d l l se
si
i st eri
e . A l so
, yo
u d o n ' t h av
si
on
e
et ( ) :
w i t h t he se on
n g t h e va
_u
nregi
.
st er( bef )
r i a bl e m a ke t s ha
et t h v e a r i a bl $ e n am
e ,a w s
ore t va
r ia b le
e l la s
u n re g i s t e i r t , i s : se
si
o n_
se
si
on
Y ou c ou
u ns _u
nregi
et ( ) ; st er(
la d l so do t he op
" na po
m e")
;
si t e i f you
w an
t ed t o m ake
sur
e t ha v t a ar i ab
lw e
as r eg
i st er ed an h d ad a val
ue
:
/ /I f $ n a m e h a s n o t b e e n r e g is t e r e d w it h t h e s e s s io n . i f ( ! se
s i o n _ i s_
se $nam
o _n r e g i st e r ( " na = e " S pi ke" ;
si
r e g i st e r e d ( "na m e")
m e " {) ) ;
}
T o p
D est
r o yi n g S es
io n s
I f yo h u av b e e en l o o ki n a g t t h c o e ah b ve no t de ha
n t en
t o s f t h s e e si
e b n ui l di ng up ti n eh r e, de pe nd l et ed w he t n he use r en t ds eh se i
ve t e o xp
l i c i t l d y e st r o se y
l o n u g se
r ms
si
ay be i s n e s i
o ns f o r t h s e es
o ns
on f i l es i y n o se ur
si o n . sa
si o n f i l e t s o be d el et e d . T h e r e as
. I t i p s e r f e c t l f y e a si b l f e o r us t ers
s o t a r t se
si
an co d m b e ac t k he en xt da w y i t t h eh brow se r st i l lsi t t i ng op en on t he de skt w ou l d n ' t w a t nt o d e l e t e t h e i r se si o n a s f t e r a se t f i n i t e a m o u of tn t i m e , preci T h a er
r e t w o w a t ys
se i
on
o co
m b a t h e bu
_p
e o f t h e se
se
si
o n_
d es
t r oy
();
se
si
o n_
d es
t r oy
( ) t ak n es
r e m o ve a s ny se w i t h i t s va
si
i l d up o f f i l e i s n yo
si
on
_ d es
a o r gu
t r oy
u r t e m po
m en
( ) f un
t s. se
si
on f i l es c r e at e d by t h s e es
l u e i n t a on c t
T h i n s e xt sc ri
o ns op
r a r d y i r ec
no
pe
t o r y, yo m u
a h y a n ve
d. T eh r ea son t he f se i la es r st e t m ad a e e n f f or t d o est r t oy eh se i u ha
ve n rea o
, t h e g n h o o m f e t or h e e ve
l w a o y f kn
n i n (or g
. I f us ahv ers b e e d n oi gn so m sh e se l f y o r t h e r e a so n a s b o ve . t t ory
o t i ce t d ha
ne
on f t or h i s t s h at yo
h a t w i l l n o t , i n m o st c a
curent
th e
pt d e m o ns
p t 2- 4 se
o n_ si on
se
s, ad
ve
ev
t so
m f e i l es
i l lt he r a e nd on . Y ou
o w i n hg o w
en l a o ng w e
op
pi ng
, yo su u
r se
l a y f f e c t yo
ke
n d! )
r el y
u r us
ers'
:
d e st r o y( ) u nreg . R e m em
i st al ers
l se
si o n _ de
st r o y() f u n ct i o n .
i o n 2. p h p
2 . se s i o n _ star
();
3 . i f (i s se t ($d
e str
4 .
se
d es
5 .
unse
si
o n_ t ( $n
o { y) t r oy
am
();
e) ;
6 . } e l se { 7 .
i f ( ! se
8 .
se
9 .
$nam
10.
s i o n _ i s_ si
o n_
r e g i st e r e d ( " n a m e " {) )
r e gi st e r ( " na
= e " S pi ke"
m e")
;
;
} }
12.
? >
13. 14.
SE
N am
SI D =$: e: =$
15.
i on
16.
17.
< i np
18.
< / f orm
=s
PH es i
e= >
" su
bm
ES
SI D ?>
e?> on
="subm
ut t yp
PS
nam
2. ph
mp
i tnam "
e=
i t " na
m e=
et ho
d=
po
" r el oa val d" " de
st r oy
st > ue
" va
="R l ue
si
o va n
b t er h a t e ve i n vf a a r i a bl i e u s nreg
page.
t r a t e t s h u e se o f t h s e es
s
c t i on
1 . < ?
1.
a t d h i r ec
s.
T h e f i r st i t s o m a ke us
S cri
ve
i ng on oh w m an se i y on exa m pl y es ou ha o ve on c l by osi gn t he br ow i ser be s cau w se h e ave
el oa = " D es
d S es i t r S oy
on es
" >< si on
br > ">
r i a b l e as
so
c i at e w d
i st e r e d w i t a h se
si
i t t h h u e se
r se
o n, t he va
r i ab
si
o an n d l s e t i l l e xi st s
S cri
p t 2- 4. se
s
i o n 2. p h p L i n e- b y- L i n E e
L IN E
xp
l an
2
S t ar t se he
ori on
cont
3–
5
C he t ck se o
i e f t he $d
6–
10
I f $d
n as
13
–1
4
P r i nt ou
15
–1
8
D i sp
est
r h oy
l a ay
exi ain nue es
ot be
t he cur
t h e cu
t r v oy
ari
en set
r en
f orm
st sei ng
t se
t se i
si
on
l i e se s
, t he r n eg
t . I f i t i s, t he t n he us
i st er se a
on I D an t d he val
t t o he us t er ha
r r en
ab
i on.
t al l ow
. I f t h e us r er
hi s
e l oa
si
on vari
ab
ue of t he $n
m her or
am
t rel o
d t s he p ag
er ha pres l n e am va e
ed $n
r i ab
oa t d he cu e ( b cl y
t d he " D es
i c ki
am
a e nd asi
ge des or
t r t oy
t r oy
" bu
t t on
gn t ha
t var
. i ab
N ot t e h f e i l es i y n ou " D e st r o S y e s i f " R e l o a Sd
T he ot he
e s i o n " ca
r w t ay m o
an
; P e r ce
hi l c e l i cki
si o f n i l w e
u se t s h f e i l t e b o rec
ag t e he or ph
an
s i o n i n i t i a l i za
i o n . g c_
; A f t er hi n s um
r r en
t pa
n g " R e l oa
he se
si
d " o r u si n g t h e brow
se
on va
r i ab
r ' rel s
o a d b u t t o n ) , t h e n t h e se
ne u d b p t y he ga
se
si o n . g c_m
T h e f i r set st
r ba
axl
t i n g , se
nd
s, st ored
ge c o
l l ec
on f i l i es t s m o
r o l l d o w n t o t h e [ se
s i o n . g c_ e - p erc
T h e se
si
co
n d se
t t i n g , se
o n " a nd " D e st r o S y
i n s g e si
ake
use
es
on I D i d s el e t e f d r om
of P H P 'au s
t om
t t i n g Lo s.
o t for k
s i o n ] se
l l e c ti o n ' p r o c e
da
on
4 0 " m e a n t s ha
t a w i l l be se
t i on proc e
i f et i m = e 14
m e a ns t h a t t h e r e i a s on
T h d e ef a u l t o f " 14
o nd
t t o n , t h e the n
c i at ed w i t h
se
si
on
s io n file
si o n " b ut t o n s. E a c h t i m y e o c u l i c k yo
u r se
si
on
. sa
ve
_ pa
t d h i r ec
t ory.
E a ch
at i c
" g a r b ag
h e f o llo
e " cl e a n up of t he
w i ng t w o se
tti
se se
si
o
fi l e s . O pe
n
n g s :
s i s t a rt e d
ility= 1
secro of
; c l ea
e l o ad S e s i
r r e sp
l a e so
t io n .
p r o b ab be
n t g h "R e
i t t h he co
ue " S pi ke".
r e a t e i d t n h a t d i r e c t o r y.
ed se i
i t o r a n d sc
n t i l e p r o b a b i l i t t y h a t t h e ' g a r b a g e co
; o n e ve se ry
s
r e ct o r w y
t i c e t h a t h s e es
p h p. i ni f i l e i n a t e ed xt
your
se
r t e m p o r di ary o n , " no
lt e he val
l e.
va r i a b l e a s r e r e se t a n the d va l u for e se s i o ID n i d s i sp l a ye d . I f t h e u se r c l i c k t s h "D e e st r o bu y" a so ci a t e d w i t t h h p e a g i e d s e l et e d, w h i ch i n t u r d n e l e t es t h e va l u o e f t he se si o v n a r i a bl e.
cl i o ck
at i o n
D E S C R IP T IO N
r ba
ge
'an
d
0
p r o b a b i l i t set y, pr nt . g c_
en as ' ga
s.
o ba
h e p e r ce
b i l i t y h al at
m a xl i f e t i m e , se t ev se ry
si
n t a g e p r o b a b i l i t tha y
l o f t he i t e m i s d en t t s he l i f et i m e , i n se
o f n i l t e h a t i o s l d t er h a 2 n m 4
t t h e f i l e i s d e n t i f i e d a g s a r b a g e a r e d e l e t e d .T h e d e f a u l to f " 1 "
t i f i ed a g s arb co
nd i nu
s, t h se a at t es i c o s
g e a r e de
l e t e d f o r ev se ery
si
on f i l e c a
n ex
n si de
r e j d u nk
.
si
o n st a r t e d.
i st b e f o r e b ei ng l a b e l e d a g s a r ba
g e .
T o p
A S i m pl S e esi T he f ol l ow T he ap pa buton.
i ng ex
pl i c a
ge w he
t i on
am
on
- B S ased
pl e i a s si m pl e se , as sh
r e t he ca y
ow n ad
in n d r or
em
ov
si
ho on
- ba
se s d ho
p
p
i ng C ar t
i ng ca
r t ha
F i gu
r 2 e - 3 , f i r st as f ks t or he us
e i t em
f s r om
t he
i r ca
r t by m od
T hi i s sh s
ow
r ha s in n
a ve
d
ed at l ea
st on i e t em
, t he pr are y
es
er' n s am
u s se
s
r t s o ad
a e nd em
i f yi ng t he qu
F i g u r e 2- 3. se
W he t n he use
t al l ow
an
i o n _c
nt ed w i t a h " C he O ck
t i t y ex
d r or
ai l ad
em
dres .
ov i e t em U se
t f i el d f ea or
f s r om
4. se
s
i o n _ca
i r ca
r a s r t e he b n r ou
c h i t em
an
d c l i c ki
rt. gh
t t o he m ai s n ho
ng t he " A d I t em
s"
ar t . p h p S i g n - I n S cren
ut " bu
t t on
. T he ca y
co n
nt i nu sh e
F i g u r 2e - 4 .
F i g u r 2- e
t he
r t . p h p S h o p p i n g S cr en
op
pi ng o che k or
ut .
p
i ng
W he ch
n us c l ers o i c e o f f i n i sh
" A d M or e I t em
i "C c k
he O ck
ut " , t he a y r e broug
i n t g h o e r d e r b cl y s" bu
t t on
i c k i n t g h "F e
. T hi i s sh s
ow
n in
ht t o a co
nf i r m at i on pa F i gu
p t 2- s 5 es
si o n _c
[ V i e w f u l lw i d t h ]
art
.p h p
, w hi ch di sp
l ay t s he co
nt en
t o s f t he
i r ca
r t . T he t y he
n a d d d i n a g d d i t i o n a l i t e m t s the o
r 2e - 5 .
F i g u r 2- e
S cri
ge
i n i sh O r d e r " b u t t o o n r g o i n b g a a c k
5. se
s
i o n _c
ar t _c
h ec
ko
u t.p h p
i r ca
r t b cl y
n ha
ve t he i ck i n the g
1 . < ? 2 . se s i o n _ star
();
3 . $i n ve nt o r ar=y
r a y(
4 .
"0
1" => " T o
5 .
"0
2 " = > " F a c i al T i s u
6 .
" 03
t h P ast
e", e",
" => " C ot t on S w abs",
7 .
" 0 4"
=> " S ham
8 .
"0
5 " = > " C o nd
i t i o ne
9 .
" 06
" => " D eod
or ant
1 0 .
po "
, r", "
);
1 1 . f u n ct i o p n o p u l a t e _ ca r t ( ) { 1 2 . gl ob
al $n
am
e, $e
m ai l , $i t em
s;
1 3 . $ i t e m a =s r r a y(0, 0 , 0 , 0 , 0 , 0 ) ; 1 4 . se si o n _reg i st e r ( " n am e " ) ; 1 5 . s e s i o n _ r e g i st e r ( " e m a i l " ) ; 1 6 . s e s i o n _ r e g i st e r ( " i t e m s")
;
1 7 . } 1 8 . f u n c t i o g n e t _ u se r _ i n f o ( ) { 1 9 .
? >
2 0 .
< h3
> P l ea
p se
2 1 .
>N
am
2 3 . < br>E 2 4 . < p>
i de w us
= se i
e:
t ype= ut t yp
ut t yp
i t t h he f ol l ow
on
m ai l : < i np < i np
2 5 . < / f orm 2 6 .
r ov
i on
e=
_ca
r t . ph " t ext
" na
" t ex
t " na
m e=
i t " na
m e=
" i nf os
s, $i nv
en
e=
" su
bm
i ng be
p m et ho m e=
f c on re
d=
t i nu
po
i ng
: < / h3
>
st >
" nam
e" >
" em
ai l " > ub
m i t " va
d=
po
l ue
= " S ub
m it " >
>
< ?
2 7 . } 2 8 . f u n c t i o shn 2 9 . gl ob
al $n
3 0 . ? > 3 1 .
S
hop
o p ( ){ am
m ai l , $i t em
B el ow
3 2 .
e, $e
t i on
t ory;
:
= se i
on
_ca
r t . ph
p m et ho
st ><
p>
< ?
3 4 . $ t o t a l= 0 ; 3 5 . f o r ( $ i 0= ; $ i s< i ze o f ( $ i n ve n t o r y); $ i + + ) { 3 6 .
? >
3 7 .
I t em
I D : < b>
< ?=
$ i n ve
n t o r y)]
?>
3 8 .
Q t y: < i np m axl
3 9 .
en
u t t yp gt h=
ke
y( $i nv
e = " t ex " 2"><
t ory)
; ?>
< / b> D es
c r i pt i on
: < b>
< ?=
t " n am
e = " i t e m s_
i n [ < ? = $i ?>
] " va
< ? ne xt ( $ i n ve
4 1 .
$ t o t a l = $ t o t a l + $ i t e m s[$i
4 2 .
}
4 3 .
? >
n t o r y);
4 4 .
> Y ha ou
ve
4 5 .
>
ut t ype
4 6 . < / f orm
=$
];
t ot al i ?>
="subm
t em
i t " na
s i you n m e=
r c ar " ad
t.
di t em
s" >
>
< ?
4 8 . i f ($ t o t a l > 0 ) { 4 9 .
? >
5 0 . < f orm
ac
t i on
5 1 .
ut t ype
5 2 .
f orm
>
5 3 . 5 4 . 5 5 . }
< ? }
= se ="subm
$i nv
en
t ory[
l u e = " < ? = $ i t e m s[ $i ] ?>
br >
4 0 .
4 7 .
en
ke
y(
< /b >
si
on
_c i t " na
art m e=
_c
he " che
c ko
ut . ph c kou
p> t " val
ue
= " C he
c k O ut ! " >
" si ze
= "2 "
5 6 . / *M A I N * / 5 7 . i f ( i s e t ( $ a d d i t e m s) { 5 8 . $i t em 5 9 . ec h
s = $i t em o( " < h3
s_i >C
n; ar t U pd
at ed
6 0 . sh op
();
6 1 . } el
if ( ! is e t ( $ n a m e ) ){
se
! h3
6 2 . ge t _ u se r _ i n f o ( ) ; 6 3 . } e l se i f (i s e t ($i n f o s u b m i t ) { 6 4 . po p u l a t e _ c a r t ( ) ; 6 5 . sh op
();
6 6 . } e l se { 6 7 . sh op 6 8 . } 6 9 . ? >
();
> ");
S cri
p t 2- 5. se
s
i o n _c
art
. p h p L i n e- b y- L i n E e
L IN E
xp
l an
at i o n
D E S C R IP T IO N
2
S t ar t se he
ori on
3–10
C r eat
a e ar n
r t ay be o
used
t as i he
t em
av i s
1
D ec l
ar e n a ew
f un
c t i on po
pul
at e_
c ar
12
D ec l
ar so e
m g e l ob
al vari
ab
l f es
13
Z er
out o
ti he
14
–1
6
R eg
18
–2
7
D ec f l a are
cont
t em
st sei ng
i s t n user he
i st er t he var un
exi ain nue
l t es
ha
l ab
i on set
r . T he $i t em
car ng
t ha b ve
li e t n he st or e.
t ( ) . T hi f s unct
or t he use
shop'i s
i ab
i on.
up s
t he user
var s
i ab
sho ' s
pi
l i e t s he i t em
ng car
t.
i s t n he use
r 'sho s
p
i ng car
t.
t.
e d n ec l
ct i on t g o et t he us i er nf w o
ar w ed
i t t h se he
si
he t n he us f er i r st ar
on
.
i ve a s t he sh
op
pi ng ca
r t . T he f un
ct i on as f ks t or he us
er' n s am
e
an e d m ai l . 28
D ec l
ar t e he shop
29
A l l ow
t f he
32
C r ea
t e he s ho
34
A si
gn va a
ca 35 37
l cu
8
unct p
l t ay
U t se
41
A d t he cu
42
Exi
4
D i spl
t ay cur he
45
D i spl
an ay
–5
4
he ne
t em
r r en or l o
or ar y
t he ne
i t em
g ti n hm e
t on.
ec ko
61
I f t " he
A Id
si on va
I utseid s
–6
5
I f no
t d sh o
t he ca
) f or ea i c h
t he user
t or var y
i abl
shop' s
pi ng car
t.
es.
ow
ho
w m an i y t em
i are s
t n he use
r 'c ar s
t , w hi i ch
s
l h ay
m an i y t em
rt.
t em
i t n he st ore'
i s nv
en
t ory.
A t he sa
m t e i m e, di sp
r h a n s o t a d d e d a n i y t e m i s n t o t h e ca
r t , t h e n a l l va
i l ab
ed
l u e rea s
ow
s
d a 0 s , w h i ch i s
rt. l t e he ne
xt t i m t e he l o i p ex s
r t f t or hi l s o t p t o he r un
te o xec ut
it n he ca
s" but
s" but
r i ab
t e he adi
r t , t he d n i sp
c ut
ni ng t ot al of i t em
.
s.
t em
c l s ause
l ay t he " C he O ck
t i n he m ai p n r ogr ut " bu
t t on
am
, w hi ch bri
.
ng t s he us t er t o he
e.
t on has
l e ui s pd
t on has
es ag
be
t e t o u he p( ) f unct
t em
s" but
ne of t he ab
ove
i n f o r m a t i o n . E xe
ser
t sio on t h on
no as
p n ushe
, bu t the
d. D i spl
ed,
t he repl n
at i c a
l l u y pd
t ca he ser ad c an
t be
pu n
m es ag
ac e
up n
dat
or d r em shed
t he $i nf osu p o p u l a t e _ ca
and
bm
t he se i
t e t o he t user
on var
at ed w he y n ou su
r t ha be s
t u he
a ay
hat
t he car
t has
be
en upd
at ed af t er
.
f i r t st i m e t h e u se ha r
ti s r ue cu
be
at ed
en push
t hat hat
f u n ct i o n , si n ce t h i s i the s 63
$i nve
f s r om
.
T eh se si on va r i ab l i e n s ot au t om va l ue t o t h e se s i o n va r i a b l e .
R t un sho he
l ue
er' c a s
ut . ph p p ag
i e f t he " A d I t em s s es
I f t he " A d I t em
60
s, and
ng i t em
a i np r o g r a m .
t se o
D i spl m a ay
l i e use s
f s r om
av s
t ot al t o user he
st on i e t em
r t _ch
Be
59
ovi
r ay.
xt i key
i s t n he us
at l ea _ca
r em
m ai l , $i t em
i ab
t em
c r i pt i on ( va
ha
s" but
5 6
58
e, $e
l e. T hi var s ov i es
d t o i n i t i a l i ze t h e c a
" A d I t em
dt h ef u n c t io n .
t he $i t em
nam
di ng and
p. r ent
I f t he us has er
C heck
es
t ot al of i t em
En
59
i ab
nvet
c t i on t so
5 5
57–
i f t y $ he
em
i s t n $i he
y) an D d
xt ( ) f un
on
t s he w or of k ad
r ' c s a r t i n a t e xt i n p u t f i e l d . I f t h e u se
f t he
se i
od
r or s
l u e t h a t w a u s se
40
48
m nd
he us ad er
he I D ( ke
f t r om
c t i on doe
i ng f or m .
i he
a r e i n t h e u se t h e va
T hi f s un
l ue of t 0 t o he $t ot al var s
hr t ough
D i sp
i on.
i t on a c es o
l at ed t as
t Lo p –3
f unct
a ed
di t i onal nam
i abl
e $i t em
i t va
var e
i t em i abl
ha e
ws
r i ab
l es f r om
se i s
va on
f t er t he $i t em
ad ove t $ he
bm
i t h he i t em f a orm
r i abl
f s r om
t he f or m $i t em
. Y ou ne
ed t e o xp
i e upd s
at ed.
i t vari
ab
l e ha b s e
n set
s_i
n. gn n a ew
s. not s
be
set n
, t hen
ex c u
t e g he
et _u
s vi si t e d t h e p a g e .
r t ( ) f u n c ti o i to n
l i ci t l a y si
, t he w n k e no
n i t i a l i ze t h c e a r t .
w t he use
r ha j s ust
en
t er ed t he
ser
_i nf o( )
L IN E 6
D E S C R IP T IO N
–6
8
I f no
t hi ng el h se
kn
S cri
ow
h as
ap
t he us ha er
p t 2- s 6 es
pe
ne
d, j ust
e s nt erd
si o n _c
ex
c ut
t he i nf orm
ar t _c
t e he sho
at i on an
h ec
ko
f p un
c t i on
d t he ca
. S i nce
t he se i
r t ha b s e i n ni t i al i ze
on var d, bu
i ab
l f e or $n
t no i t em
h s av b e e
u t . p hp
[ V i e w f u l lw i d t h ] 1 . < ? 2 . se s i o n _ star
();
3 . $i n ve nt o r ar=y
r a y(
4 .
"0
1" => " T o
5 .
"0
2 " = > " F a c i al T i s u
6 .
" 03
t h P ast
e", e",
" => " C ot t on S w abs",
7 .
" 0 4"
=> " S ham
8 .
"0
5 " = > " C o nd
i t i o ne
9 .
" 06
" => " D eod
or ant
1 0 .
po "
, r", "
);
1 1 . i f ( ! i s e t ($n 1 2 .
a m e ) ){
? >
1 3 .
2>
che
S or r y, n you ou c k
1 4 .
ed
t < o hr a
ef =se
si
on
_car
t . ph
p>
ad
som
i e t em
s
a> bef
or c a you e
n
t.
< ?
1 5 . }e l s e i f (i s s e t ($ f i n i s h ) { 1 6 . ? > >O 1 7 .
r der
C om
pl et e!
>
< ?
1 9 . / / se n d em
a i l co
n f ir m a t io n ...
2 0 . / / se n o d r d e r t o r d e r p r o c e s i n scg 2 1 . se s i
on
2 2 . se s i
_u
ns
o n _d
r ip t ...
et ( ) ; e st r o y( ) ;
2 3 . } e l se { 2 4 .
? >
2 5 .
2 6 .
C heckout
>T
2 7 .
han
>
h3> f you k
or shop
l e bo
r de
pi w ng
i
$na
m e?
>, your
or der
i bel s
ow
:
r = 1>
< ?
2 9 . $ t o t a l= 0 ; 3 0 . f o r ( $ i 0= ; $ i s< i ze o f ( $ i n ve n t o r y); $ i + + ) { 3 1 .
? >
3 2 . < t r > < t d > I t em
ID :
< b>
< ?=
ke
3 3 . < t d > D e scri p t i o :n 3 4 . < t d > Q t y: < ?= $i t em
< b>
< ?=
$i nv
3 5 .
y( $i nv
en
en
t ory[
t ory)
; ?>
< / b>
ke
y( $i nv
en
< / t d> t ory)
] ?>
< / b>
< / t d>
s[ $ i ] ? > < / t d > < / t r >
< ?
3 6 .
ne xt ( $ i n ve
3 7 .
$ t o t a l = $ t o t a l + $ i t e m s[$i
3 8 .
}
3 9 .
? >
4 0 . < t r > < t c od
n t o r y);
l sp
a n = al 3
];
i g n = r i gh
t > T o t a l : < ? = $ t ot a l ? > < / t d>
< /tr>
4 1 . t a b le > 4 2 . < p> af
A co
nf i r m at i o n
t e r yo h u a ve f i n i sh
f yo
ur orde
e y d o or ur
w i l s l be d e r.
en
t to eh
m ai l ad
dres :
< b>
< ?=
$e
m ai l ?>
< / b>
,
am
me
ust
n ad
de t d o t he ca
be set
t he
n, w e rt.
4 3 .
< p >
4 4 . < f orm 4 5 .
ac
t i on
4 6 . < / f orm 4 7 . < f orm 4 8 .
t i on u t t yp
4 9 . < / f orm 5 0 .
si
on
="subm
_c
art
i t " na
. ph
p>
m e=
" c on
t i nu
e" val
ue
="A
d M or e I t em
s" >
> ac
< i np
= se
ut t ype
= se
si
on
e = " su
_c
art
_c
b m i t " n am
he
e=
c ko
ut . ph
" f i ni sh
" va
p> l ue
= " F i n i sh O r de
r">
>
< ?
5 1 . } 5 2 . ? >
S cri
p t 2- 6. se
s
i o n _c
art
_c
h ec
ko
u t . p h p L i n e- b y- L i n e E xp
L IN E 2
S t ar t se he
3–10
R ec r
1
V er i f t y ha
12
–1
4
15
ori on
eat
a e ar n
I f t he $n
–2
0
p r o ce
ab
21
D el et al e
2
D est
i ab
at i o n
ge t so
r " bu
t t on ha be s
ltse i he
or t y se i he
t on r o em
en
es,
si w nce
sam 23
t e hi ng
I f t o he
r der
w t ha
t he
t he t he
r e ei s xi st i ng se i
r i e n s s o es
i st t er he
i r na
she
si on da
m a e nd em
d, t he n n ot i f t y he use
d i n e g m ai l o r se
se he
T h i h s a t s h a e d de b d e n ef i t o f no
n w e kno
eg
en pu
t ove
li e t n he st or e. on da
t o a r t ha
t a.
t i t i s nc
ai l an a d d so
om
m i e t em
pl et e. R ed
i r ec
t s t o he
rt.
i r ca
t us ba ers
t ck
o
pushed.
c h s as i abl
l ab
w t ha
re n
ben " has
, su
var on
t . I f i t i s, t he
t he ca y
r der
i r ed
av i s
t , t he w n k e no ha
Fi ni O sh
ng i r s e qu
i on.
t em
l e sie s
l i e n s ot se r t pa
r de
si
t as i he
e var
ft" he
I f t he " F i ni O sh
st sei ng
used
am
pi ng ca i t se o
exi ain nue
r t ay be o
v e ari
op
C heck
cont
t he $n am
t he sh
16
l an
D E S C R IP T IO N
no e
l onge
f on
i l f e r om
si
r ne
t al l o w i n t g h u e se
r t ha
t he or de
r ha be s
n di ng t h o e r d t er a o o n r d ert d d he
en c om
pl et ed
es
si n s g c r i p t .
proc
. T he d n w o
ha
t ev
r
at a.
t serv he
er 'di s
sk.
r t c o l i "R c k
el o ad
nam
i abl
" o r t h "B e
a bu c k"
t t o a n n p d r o du
c e m ul t i p l o e r de
r f s o r t he
. n has
ot be
f n i nal
i a zed
w nd
kno e
w t $ he
var e
ha e
be s
set n
it n se he
si
on,
t hen
ex c u
t e r he
pi ng ca
r t . T hi t s ab
em
ai nd
er
o f t h e sc ri p t . 25
–4
1
D i sp
l ay t a ab
t o t h e on 42
l u e si ng t he da
e us
D i spl m a ay
ed i n t he se
si
es ag
p e r ovi ha
43
–4
6
P r ovi
de b a ut t on t so
47
–4
9
D i spl
ay t he " F i ni sh O r de
C l ose
out
51
t he i f / el sei
t f a r om o n_
f / el st se
t he $i nv
en
t ar ory
r ay an
d f r om
t he $i t em
r t . p hp scri
p t t h a t di sp
l a ys t h e sh
di ng det
ai l t s use o
r of s w ha
pe
r c an s
go ba an c k
e d di t i t em
t use r " bu
ca
t t on so t ha
at em
en
t use
r ca s
n c on
t s ar t ed on l i ne 1
t ha
i s t n he f i r m t he
w ns
hen i r c ar
i s t n he us
o p p i n g f o r m , e xc e t he cl y
i t ck
er' sh s
op
p t t h a t t h e f i e l d a s r e n o t ed
he " F i ni O sh
r de
r " but
t on
l i e si s
m i l ar
it a b le .
.
t. i r or de
r.
.
T o p
C h a p t e r 3 .M u l t i p l e D a t a b a s e I n t e r a c t i o n I T n hi C s
ha
pt er A dvan D at ab D B X — C r ea U si P ng
c ed
D at ab
I se
- S pe
c i f F i c un
ase
P H P S up o t i ng Y ou
rO w S n
nt er act
i on P i n H P 4
c t i on i s n P H P
r t f or M ul t i pl D e up
po
at ab se
r t f or M ul t i pl D e
s at ab
ase
s
E A R ::D B
T o p
A d van I f yo
ced
u ha
ve be
D at ab I ase
en pl ay
i ng w i t P h
M ost of t he P H P o boks al m os t he sa m su e
H P w f a or
—
mSQL
w w w . m ysql
—
f i l eP
c om
O r ac l
O vr i m os—
w w w . ovr
as
e—
bu
D BM
— f l at f
Post
gr eSQ
T hi ca s i nsi
d i t e s xc e
l l en
t su
p
ort f c on or
ne
ct i ng t o M yS
Q L da
t ab
as
es
tm s m any or d e at ab se as i es o n en f orm or an ot he
.
w it h
r:
em
onl s
y)
.com m
c om
m
i m os.
co
m
. c om al —
w w w . co
w w w . p g sq
m
l . co
o ug b h u i l t - i s n u p po r ac up
c t i on
m ysql
t you
l n y ot i c e
nc
ep
t - as
bl o e m n
a. de a ny f l a vo
r o s f *ni
x
w w w . f r o ntbase.com
t el y, e ac s h
us p es st t s ha
se.
ila
O as
na
sy t
w w w . i nf o r m i x. co
i l d e a t a b a se a s va
base—
t s, suc h
i f f ernt
; on W i n32
e. c o
i m ent
L—
l l y, P H P h as en
t ha d ve
)
w w w . syba e
+ — e xper
Fr ont
ver
w w w . i nt er ba w w w . or ac l
DB+
yo u u se t he f un
m I BM
e—
Syb
U nf o r t u na
t l i ke
. au
l y) — w w w . f pt ec h
(fr o
I nt er B ase—
ei gh
t S Q ser L
r o ( R e a d on
I nf o r m i x—
avyw
e m os
. c om
w w w . huges.
M S S Q ( L M i c r os f
he
hi l e, yo h u av
io ninP H P 4
t n eh m ar ket descr i be P H P dat ab se sup or t onl w y i Mt h yS Q L. B ut P H P supor p ort i t provi de f s or M yS Q L. A of s ve r si on 4. 1, P H P su p ort t s he f ol l ow i ng da t ab
M y SQL
B a si c a
n t er act
po
m es
.
f as s
c od as ar
r ob
l em
use
M i c r os
l e, S yb r t d ed
r t f o rm a
as at ab
_co
n
f o r m i x, an
as
ec t
p e ort
ab
nd t co o
i l i t go y
n
es
he da
t f un
ec t
a se ne
, f exam or
ase
ba
e ds
, e sp
e c i al l si y
ct i on t s d o t o he sam
t e hi ng
ru you ver
m se
s. F exam or s ql
en
nt a i n su s
p p ort f o r t he co
d. H ow
ev
r , you
pl e, t o c on
_co
pl e, yo h u av a e ki l l er ap t p ha c k-
n ce i t co
m m e r c i al
ft.
t a o M S S Q se L
. S ay t ab
t ab
d M i c r o so
e ha d s i f f er en ,a
f t S' s Q L ser t as ver
as w e l l , an t d he a y r "f e r e da e" t a ba co ul d co de i t on ce , t he n r un yo ap ur
aj o r i t o y f yo da ur
e, I n
kno
w t ha
se t s h a t r u o n t n h l e ov el L y i n ux se r ve r yo h u a ve ih d i n u g n de r yo pl i ca t i on us i ng an o y en t of eh se da t ab as es w i t h on lt y he f l i vap a of
n
ec t
ne
. T he t w f o un
t yo w u
an
t M yS
Q L P or
t c rea o ost
c t t a o M yS
Q L da
c t i on al are s
t ab
ase
m ost
ag
em
i de
t e, bu
t m an
gr eS
Q L w i l ldo t he j ob j ust
u r d es k. W ou l dn ' t i t b n e i c e i f yo u r i ab l e t o t el l P H P w ih ch da t ab as
en
nt i cal
,
t
e
itis t a lk in g t o ? T he P H P t ea al l o w yo s Y ou c ou T he
m ha el s
i m i na
t ed som
o e f t he pr ob
t u u o se on f e u n c t i o t n h a t c a l d al so c r ea
r e i a s l so g a r ea
t e you t da
r ow t ab
l em
n, f o r ex
n set
of c ust
as a e bs
t r ac
om
am da
t i on l ay c al er
ws
i tm h
pl e , c o t ab
ase
ul t i pl d e at ab
n n ec " w r ap
t t d o i f f er n pe
r t s" o al l ow
ase
c reat by s
t t yp o es you
l ed P E A R : : D B . P E A R i a s se
i ng d a at ab f d at a ba t o sup t of l i bra
po
se
ase
ab
st r ac t
i on l aye
r t m ul t i pl e da
t ab
ase
o w yo
u a l i t t l e b i t o f a l l t h r e e so
l u t i o n s. T h e b o t t o m l i n e i t s h a t yo
u r co
l ed D B X . D B X
s. i es f P or
l i b r a r y, a l t h o u g h n o t a e s xt e n si ve a t t h i t s i m e . T h i c s h a p t e r w i l l sh
r c al
s.
d e w i l lb e m o r e p o r t a b l e .
H P th
a t i s i m i l a tr o t h e P
E R L CPAN
T o p
D at ab
as
T hi sect s
e- S p ec
i on pr es
nt som s
i f i F c u n ct i o n i s n P H P
b e asi
i cs t n hr e of t he m or p e r om
ah so ve m e e xpe r i en w c e i t d h at ab ase an s P d H P ( no t ab t of eh di f f ernc es be t w e n t he f un ct i on a s cr os d s i f f ern
i ne lM y
nt da yS
t da
t ab
ase
t s ha
t you
c an
use
w i tP h
Q L) . T hi i s fn or m at i on i s ncl t ab as es . T eh da t ab as es are:
ud
ed a as
H P . T hi bo s
a ok
br i ef ove
s um
t es
r vi ew
ha
t you
an t d p o oi nt ou
t som
e
M y SQL P ost
gr eS
Q L
M S S Q ( L M i c r os f
C ha av
nce
ar s
g e o t d ha
ai l a b l e f f or r e e do
T he
Le
r a e r f e ou
w i l lha a ve ).
si c on c
1 .
C on
ne
2 .
S el ec
3 .
Q u eryi
4 .
O b t ai ni n g t h e r e su r t he
on
m ys ql _c
onec
onec
t ab
ase
r da
t ab
n t g h d e a t a ba
r c on
c ep
e t d o ac
as
t ab
ert
e r i e t s o pres
e-bac
ke a d p da
— ctone o
at o M ySQ
m s ql
_cone t
— tcone t o
M ta o
ne
c t ( ) an
n
I e n ac f h un
c t i on
t w i ork
gr eS
de
Q S L er ver
l ( ) co
t ( S ER
VE
R ,U SE
R P, AS
SW
O R D );
t ( S ER
VE
R ,U SE
R P, AS
SW
O R D );
en
t t s ha
t ne
ed t o be de
t i on
S L er ver
d m sq
, t he argum
f eac h or
se d s i sc u
nt i ca
l l y:
a n d m s ql _c
( u ver
go y
od si nce
M yS
Q a L nd P ost
gr eS
Q aL r e
:
t t o t h e u se
S S Q S L er ver
t a o P ost
ec
l i ca
t a ba
_cone t
ec t
es
l t e yo o
r. da
t ab
ase
.
S er ver
F o r t he t hre
— t c on o
en
c t i on u s sed
m ysql
nect
as
i l ab
, r e a d, o r d el et d e at a .
ase
as
av s
.
i t h t he P H P f un
s.
ase
e.
u r qu
at ab
ce
ver
se t i o ns
tw s
at ab
al i ng w i t d h at ab ser
l t o s f yo
yt hi ng ia n da
u ne
st on o e f t he d se
H P f or de
in g to th De
se t h at yo
l _c
pt i s P n
ct i ng t o t he da
pg_con
m ysq
t l ea
t i ng t he proe
c u an do an
t a ba
ce
se f ou
C o n n ect
da
t you w n l o ad
r ba
t g ' s o ove
B ef yo ore
t)
f i ne
d are:
, yo n u e t d c o on se
d ea
ne
ct t t o he da
r l i e r , t hi t s r a ns
t ab
as s e erv
l a t es i n t o t h r e f u nc
t ha
t co t i o ns
nt ai ns t he ac :
t ua
l
S E R V E R — T he host " m yc om
pan
U S E R — T l he PA
T he co
n
ec
pg_con
S
t f un
nect
c t i on f P or ( S TR
os
t co
st = l oc a
user
ec t
( " ho
=user
nam
I t d o es
n' t hu
pa
sw
as ord
pg
_co
n
a as
oc
you
uc
( " db
r t i ne
st po
or d=p
na
m e=
I n t he ca
se P of
dat
se.
ab
uc e
es
ev
ost w on
hi t ch d he
t o d he
of d ust he
Q L im s
r t = 54 as w
at ab
at ab se ase
ser se
r ver,
ver
f or exa
i r s un
i ng,
f or exam
m pl e, " Joe
".
pl e,
er .
h di f f er n
t . pg
_c
on
ne
c t t ak
es as i t a s r gu
m en
t a si ng
l e st r i ng
:
nt i nf orm 32 db
t est
at i on r eq
na
m e=
sf
ui r ed by yo ser ur
ve
r . T he m os
t co
m pl et s e t r i ng yo c u ou
l u d se i s:
t est
or d" ) ;
i at ed w i t t h he us
ha s ve eri
t h he
t c es
o ve
, b u t i f t he ho
co u
ul g d et w by
er, t he yo n
use
r =u
ser
na
m e")
Q L do c um on t he de
en f au
t at i on f you or l t po r t of 54
ul l c on y
ne
st w a l s o c a
l h o st , t he po
r t w a t s he de
f a ul t po
r t o f 5 4 32
, an
d yo
uh a dn o
i t h:
; r spe c i f i c m pl em , so t he po r t i n s ot i nc
32
t i n g t h P e r o p er D at ab
yo qu ur
m ysql
dr of es . 0. 1" .
swor
t greS
l ho
e pas w
ec t
I P ad . 168 r w h ho
r t t o u se a l l o f t he i n f o r m a t i o n ab
S el ec
H ow
i of n t he use
nt ai a n l lof t he pe
C on sul t you r P ost gr eS yo P ur os t greS Q s L erv
O nce
192
IN G );
pg
n
og
or e
" or "
W O R D — pas The
T he S T R I N G m us _co
nam
y. c om
as
en
t at i on . T he exa ed it n he pg _c
l ud
m pl es i n t hi ch s ap t asu er ne ct ex am pl es .
on
m e t ha
t you
ar e r un
ni ng
e
ct ed t o he da
t ab
ase
ser
ver
, you
t he n n e t d se o
l ec
t ed t he da
t ab
as
e i n yo pg ur
Q L, you
st i l lne
ed t se o
t he da
t ab
m o e f t he da
t ab
l ec t
t he da
t ab
ase
ne
c t ( ) f un
c t i on
on w hi yo ch
a u r g e oi ng t p o er f or m
. os
t greS
Q L, yo
u ha
ve al r ea
r , w he u n si ng M S S Q o L r M yS _sel
ec t
_db
(S T R IN G )
m s ql
_sel
ec t
_db
(S T R IN G )
I e n ac h
c ase
dy se
l ec t
_c
ase
usi
on
ng t he r esp
ec t
i f ve
, so t he
un
r e in s o f un
c t i on
c t i on t o se
l ec
t he
:
o r
, S T R I N G r ef er t s t o he na
Q u er yi n g t h D e O nc y e ou
' ve c o
n
ec
f or m of q a uer
y. M ost
T he t hr e da
t ab
ase
da
at ab
as t e o I n se
t ed t o t he da
t ab
t ab
c ept
a se
as
e se an st y
use s
i d t n he exa
m pl a es
m ysql
_que
r y( S TR
IN G );
m s ql
_que
r y( S TR
IN G );
pg_quer
y( S TR
ase
IN G );
r ve
tw o
hi yo ch
a u r co e
r t , R ea
r an s d el ec ar S d
Q co L
l l use
t he sam
syn e
ec t
i ng
.
d , o r D el et D e
t ed t he da
and
n
m m and t ax:
t ab
as a i n qu
at a
e, t he ne
xt l og
i ca
lt hi ng i t s d o o
er y, w as
el t las
he
i r ow
d n at ab
som ase-
spec i
f ciom c
m and
et hi ng w s.
ith th e d a ta in th e
w her
ST e
R I N G ani s
S Q st L
at em
O b t ai n i n g t h R e O nce
you
si m pl es
ha m ve
ad yo e
que ur
t w ay t s a o c o
,suc
as h
" S E LE
r y, you
ne
ed t g o et t he r esu
m pl i sh t hi i s u s si ng t he f et ch _f et ch_a
r r ay(
R E S U LT
);
m s ql
_f et ch_a
r r ay(
R E S U LT
);
f et ch_a
T h e d at a f r o m t he r e su ay
r r ay(
l t i l s o a de
. T he ke o ys
C nam T
FR e
O M phoneb k
W H E R nam E
u l t o s f Y o u r Q u er i es t o P r es
m ysql
pg_
f a i el i d nt o t he ar
es
ent
R E S U LT
ay c o
l t an sh d
ow
r r ay f un
i t t o he use
ct i on i s nc
l ud
tt o t h U e
per or ed i m n
f or m som os
t P H P su
se
r
o e t he
r pr oc e
p
ed da
ort
."
si t ab
ng on i t . O ne of t he as
es
.
);
d i n t o a f i e l d i n t he ar f t he ar
_a
en
' = e S ar ah'
r r es
po
a (t y ha nd t t o he co
t ib s o t h a so l um
n na
ci a t i ve a nd i n d ex m es of t he da
t a r et urned
ed
) . E a ch co
l u m n i n t h e r e su
l t i l s o a d ed i n t o
.
T o p
D B X — P H P S up
po
F o r ap
i r c e om
p l i ca
B ef or yo e ar usi e
t i o t ns ca u
W ng
E na
h a t d o n' t r e qu
u n t se
he D B X f un
i ndow
r t f or M ul t i pl D e at abse
c t i on
pl e da x s, you
t a ba
m ust
en
se
- sp
ab
e c i f i q c u eri
l su e
p
e s, yo c u an u P se
or t a c om
pi l t e i m i e f you
H P ' bu s
i l t - iD n
B X f u n c t i o n s.
ar u e si ng Li nu ena or x
bl t e he D B X m od
ul i e f you
s.
bl i ng D B X i n L i n u x
I f yo c u o m p i l e P d P H P m odul i bre a s B e f rec o re
H P us ez.
i n Ag
p ac
he
' A s P X S f u n c t i o n al i t ( y c o
m pi l i ng P H P , I f i r st su
g g e st t h a t yo
m p i l- e
u d el e t e t h e c o
w i t h - a p xs=
n f i g . ca
ch
e f i l e an
/ pa
t h / t o / a pa
ch
e / b i n/ a p xs),
d c l e a n u p f i l e l s ef t o ve
r f r om
t h en a d
t h e prev
i n f g un
c t i on
i o u c s o m p i l Th e.
is
c a b n d e o n l e i ke t h i s: cd / p a t h/ t o / ph r m co
nf i g. ca
m c l ake
ean
A f t you er
i su
c l ea
urc e
e
e t he m ak
ni ng up f i l es i t w on
pr ob an
p / so ch
e c l ea c n om ' t ne
l em
s. I f you
ha b ve
yt hi ng
, i t g 'a s
o b d et t ha
O nce
you
T c o om
' c l ve
ea
pi l P e
m an
ed w he e co n
n you
u w i l l no
t i c e qu
m pi l e. I f you
do
m pi l i ng P H P w i t n h p o r ob t t he m ak cl e
ne u d t p he m f es
H P w i tD h
d, yo r ec o
B X su
p
ea c o n
r om ort en
ab
l em
m m an w d
t he pr evi l ed
an s i l l so
ou c om s
, i su
i t e f a ew
f i l es be
n' t r un t he m ake su d l y ve
pi l e, you
t e he f ol l ow
d ou
en r probl
c an
i ng co
i ng de n c om
. D on m an
li y t w on em
ge
l et ed
c l ea
' t c om
m p i l e - - w i t h - a p xs = / u sr/
- - e n ab
l e - d b \x
Y ou sho
ul a d l e so
na
bl su e
p
l o ca
l / a p a ch
or t f or an da y
ase
t ha
t you
w i t sh u o a se
pi lri e gh
t , ev
t n ho
t s ar t ed w i t h he ne s a he
el l — f or exa
l l prom
m pl e:
- - w it h - m s q l A f t er t he co m ak A s um
nf i gu
r r e un
s, i s u
t e he co
m m an
d:
e i ng e no
r r or oc ur s
c a , you
t n hen
i t s ue
co he
m m an
d:
m a ke i n st a l l T h f e i n a l co R es
t art A pa
m m a n c d o p i e t s h l e i b p h p 4 . so l i b r a r f y i l t e / o p a t h / t o / a p a c h ch t e o l oa t d he ne
w l i bra
y:
/p a th /to /a p a c h e /b in /a p a c h e c tl r e s ta r t
ug yo h
e prog am
i j s us
ni ng i nt o som h u ave
n' t cha
t
e ng
ed
.
m m an f d r om
ws
ut i t . T he m ak
m ay st ar t r un
e / b i n / a p xs \
t ab
a y bo n you
nec sary): . / co
' t w or d, t he
e / l i b e xe
c/ .
w c om
pi l e. pt ( r ep
l ac
i ng pa
t hs sp
ec
i f i t c y o ou
r i ns
t al l as
a l i tty to h e
Y o c u an ve co
r i f t y ha
t D B X h a b s e e c n or
n f i g u r a t i o n se
E nabl
i ng D B X Wi n
E na
bl i ng D B X sup
w i nd
ow
i s ns
ec
t l i y ns
t a l l e b d u y si ng t he p hp
i nf o ( ) f u nc
t i o a n n v d e r i f yi n g t h a t D B X i l s i st ed u nd
e r t he
en pr ec o
si P c H P
ct i o n .
po
i nd
r t f or W i nd
t al l at i on
. O pe
ow
ow
n yo
s
i s ver s
ea y
sy,
ur
p hp
e w he
r e yo P ur
si nce
t he D L f i lf e or D B X ha be s
. i n f i i l e i n a t e ed xt
i t o an r
d se
m pi l ed an i d ncl
a r c h f o t r h e l i n e t h a t sa
ud
ed it n he ba
ys :
e xt e n si o n _ d i r = . / T hi l s i ne sh f i l e, t he
ou
l d po
i nt t o t he pl ac
n yo d u o no
t ne
ed t o m od
i f t y he l i ne
n e e d t o e d i t t h e l i n e t o p o i n t t o t h e co ex
t en
si on
_d
i r = C : \ A pa
N e xt , f i n d t h e se ; W i nd
ow
ch
e\ ph
ct i o n i n t h e
E s xt ensi
H P ex
t en
. I f yo d u i d no
i de
. I f yo
u co
t m ov t e he P H P ex
si on r s es
t en
si on t s o t he sa
r r e c t d i r e c t o r y, f o r e xa p\ ex
t en
si on
p hp
. i n i f i l e t h a t s a y s:
t en
si on
Y o c u an ve co
p_
ave
un
db
r i f t y ha
m en
i on
ct i on a s r a e si ng
w r ap
c t i on
A of s ver
t ed t he l i ne
t D B X h a b s e e c n or
nct
r f un
, save ec
t l i y ns
l s e et of f un
p. T e o na
d r est
ar t he A pa
t a l l e b d u y si ng t he p hp
ct i on t s ha
po
r t s he f ol l ow
pgsql m s s ql fbsql
ose(
si on f s ph or L L :
t al l ow
yo s
t u o ac
s.
odbc
dbx_cl
t he
ph
s
t he f i l e an
m y s ql
i n f g un
t as ory
bl D e
B X su
p
ort
, un
co
m m en
t ( de
l et t e he se
m i co
l on at
che
W eb serv
i nf o ( ) f u nc
. t i o a n n v d e r i f yi n g t h a t D B X i l s i st ed u nd
e r t he
s
si on 4. 1, P H P D B X sup
T h f e o l l ow
m e di r ec he
ct i o n .
T he D B X f un pe
t as ory
x. dl l
c om
n f i g u r a t i o n se
D B X Fu
si on t s o t he sa
ons
= ph
A f h t you er
t en
m e di r ec
m p le :
T ih l s i ne w i l lbe f ol l ow ed by m an l y i ne o s f w i nd ow . s dl lex t en t he b eg i n n i n g t of h e l i n t e) h e l i n e t ha t co tn a i n t s h e D B X l i D bray ex
pi ed t he ex
c t i on a s r a e va
C O N N EC
i l a b lie D n
TI O N )
B X :
i ng da
t ab
ase
s:
ce m s
ul t i pl e su
p
ort
ed da
t ab
as
es w i t ho
ut ha
vi ng t o w r i t y e ou
r ow
n
p h p. i ni p . i n if i l e , t h e n yo u
T d he db
bx_ x_
c l ose co
dbx
_c
T he db
( ) f un
n n ec
on e
x_
c t i t on
t ( ) f un
ake
c t i on
one s
ct ( M O D U LE,
co
n
ec
ar gu
t ( ) f un
H O ST,
c t i on i u s se
db x_ co n ec t r et a urns S e t he ex am pl f e or de
m en
t , C O N N E C T I O N . C O N N E C T I O N i t s l he
n ob
D A TA
d t o es
B A SE,
t ab
l i sh a c o
U SE
n
ec
D BX
_M
Q L—
M y SQ
D B X_P
G SQ
DB
SQ
X_M
L—
W O R D PE ,
t i on t o t he da
S Q L—
nam
or e I P ad
B A S E — na The
t ab
de
nt i f i er cr ea
U SER
— The
us
er na
as
For
gr eSQ
Fr ont
dat
t da he
t ed w he you n
c al
lt he
T)
r , as w el l as sp
ne
c t i on
ec
i fw y
m e of t he da
t ab
. T he m od
hi ch da as
ul i e es s
t ab
e tw o
as
e i t s o be us
ed
n
t ed
hi ch i t i co s
nt i al l t y he da
t ab
ec
ase
t ype
ab s
es
es
D B C cone
.
.
ab se. ver
dat he
.
ser ab se
ver
.
m e.
O R D — pas The
swor W he
f d or tus he
t he
notr or
E R S I S T E N T her.
tm o O t herw
er . ake
t hi p a s
i se,
t hi ar s
er si st en gum
en
t c on
ne
t noi s
c t i on
t r eq
ui r ed
. I f you
w it sh m o
ord"
) or D I E (
ake
t he con
ne
c t i on pe
r si st en
t , t he p n ut
.
[ V i e w f u l lw i d t h ]
$d
odul bc
= e D B X _M on d = n
bx
" U na
Y S Q L; / / not
_c
on
ne
c t ( $m
bl e T o C on
ec t
t e a he od
o bsenc
f quot
ul e, " 19
2. 16
es!
8. 0. 5", " ph
p", " m ysq
l us
er"
, " pa
sw
");
//$ d b c o n n -> d a ta b a s e = " p h p " / /$ d b c o n n - > h a n d le is a r e s o u r c e id e n t if e r
dbx_er
r or ( C O N N EC
T he db de
x_
f i ne w d
E xam
pl e:
$resu
l t = db
er
f or un he yo n
x_
qu
TI O N )
ct i on r et t urns u c al
l ed db
ery(
$d
he er f or r om x_co
bc
to
t i on.
pl e:
$m
. .
.
t ser ab se
t on ab se
r ve
or O ant s
dat L
base
r of es
es
as
e se
or t hi con s
hi sup ch
M S S Q d L at ab
For
as
R SI STEN
t i on as w el l as t he na en t s:
t u o f se
d L at ab
Post
m of e t da he
w an e:
w ab se
For L—
D B X _FB
D A TA
D B X _P
For
D B C — For dat any
Th host e
SW
YS
D B X _O
P E R S I S T E N T—
E xam
S
j ec
M O D U LE — T eh da t ab ase m od ul t e ah t you w hi yo ch a u r t e r yi gn t co o n ect . V al ue m s b ay
P AS
R PA ,
t ha t co tn ai sn t he ah dn l e of t he co n ec t ai l s. T eh db x_ co n ec t f un ct i on ac ce pt si s argum x
H O S T—
i nk
.
n
on " n, se
ec t
t he l at es
t f un
c t i on c a
l l t o t he m od
ul Th e.
i st i ng
l e")
e argum
().
l ec
t so
m et hi ng f r om
no
n_
ex
i f ( $ r e su l t = = { 0) e c h o db x_ e r r o r ( $ d bc on n ) ; } / / r e s p o n d s : T a b le 'p h p .n o n _ e x is t in g _ t a b le ' d o e s n 't e x is t
_t ab
;
en
t C O N N E C T I O N ti s he l i nk i de
nt i f i er
dbx
_q
T he db
uer
y( C O N N EC
x_
qu f ery
un
on o e r m o r row e w n as
TI O N SQ ,
STA L
u se
nd S Q L qu
c t i on l et yo s
s. A q u t ery
d o at r a et ur ne
ha
d, suc h
t r e t u r n ze s w as
TEM
se u
ST L
ATE
F LA
M EN
T—
G S — Y ou c an
de
f au
spe
" D BX
_R
ES
T he ob
j ec
t r et urne
d by db
ha
nd
c ol
l e— s—
r ow
nt i f i er cr ea
t ed w he yo n
D B X _R
E S U LT_
qu c o ery
m be
T he nu
m be
t w o - di m e n si on
r ow
E xam
l d t = bx e_t
abl
dbx_sor
t a. T he ar gu
st L
w m uc h
i nf or m at i on ir s et ur ne b d t y he qu
er by y
ent
U LT_I
t ar s
e:
ec t
( ) f un
c t i on
d t he qu r ery
s as
uc
ce
sf
et urns u l , b ut t h er
.
.
ci f yi ng t he f l ag
ES
l lt he db
m en
ar SQ d
at em
ca u
t f ai l an
N FO
s, yo m u "f The.
us
spe
ci f yi ng on o e r m or o e f t he f ol l ow
t us a e | sym
ar l ags
bo
l t s o ep
ar t
t e he
m —
ul t i s t n he r es
ul t ar
a ay
r i e nd
ex
et ur ne
d, a suc h
f exa or
i ng f l ag
s. B y
m pl e
e:
d. A l l r es
ed a by
nu
m be
r , i . e. , $resu
_I N F O — R et ur i ns A S S O C — S et t s of keys he
nt ai ns t he f ol l ow
i ng pro
h e an
dl t e ha
l f e r om
r of c ol
um
r of r ow
nf or m at i on abo
t i av s
i l ab
ns i n t he r esu
i s t n he r esu
li y f ei t her
l t se
l t se
D B X _R
ert
i es
$d
bc o
n
et ur ar ned
- >h
an
um
r ns
r t ay t o col he
dl e. A c es
b d $r y
esu
l t - >c o
l t - >row
_I N F O or D B X _R
a l a r r a c y o n t a i ni ng t h e n a m e t of h e co i cu
tr he
d by $r esu
. A c es
um
nam n
f s i el n d am
a e nd f i el t d ype.
es .
l um
a d $r s
esu
l t - >h
an
dl e.
l.
s.
E S U LT
_A
n a n d i t s yp A e.
ce
S S O C i spec i s se
f i ed t n f he
d by $ r e su
l ag'
l t [ ' i n f o' ] [ $x
par s
am
et er . P r ovi
] a n d $ r e su
l t [ ' na
_q
ue
r y( $d
_s
U LT,
bc
on
n, " se
E S U LT_I
SO
R FU T
ort f u n c t i o a n l l o w yo s
R D E R B Y " c l au i se you n R E S U LT—
l ec
l t . A ce
se
b d $ y r e su
l t - > da
t a [ $x
] [ ' f i e l d n am
e' ] w he
r e $x i t s h i e nd
e o x f t h p e a r t i cu
t u o so
esul
r t t h e r e su at em
t of pr a
S O R F T U N C TI O N — Y our
E xam
pl e:
f un
c t i on m y_
so
r t{
m et hi ng f r om );
N C TI O N )
r S Q st L T r he
t so
N FO
en evi
l t o s f a q ue t . T a he
t om
r u y si n y g o u r o w n c u
r gu
ou dbx_q s c us
a des
m e' ] [ $x
l a rr o w .
C o n t a i ns t h a e ct u a l d at a f r o m r e su
e" ,D B X _R
l t [ 0] ,
:
. A c es
E S U LT
ut t he col
.
t ( R ES
T h d e bx t "O he
da
es no
, f t or h q e u w ery
pl e:
$resu som
t ha no s
_I N D E X — A l w ay r s et urne
i x t s h e i n d ex o f t he p art
d a t a—
t i f t he qu do ery
n
E S U LT
E S U LT
R et ur ne on d
w h $ er
j ec
x_co
. W he s n pe
D B X _R
T he sam
s—
i nf o—
n ob
u l t [ 1 ] etc . ,
x_
T he nu
e. I t r et a urns
de
N D E X D| B X_R
$ res
as
l t e ha
on
D B X _R
t ab
e n s ot r e t u r a n o n b j e ct . I n st ea i d t r e t 1 urns
* f r om t a ab
ci f ho y
U LT_I
S)
l ec t
A s t and
l t , al lf l ag a s r t e urned
T, FLAG
es t o t he da
do s
C O N N E C T I O N — T he l i nk SQ
eri
r row
he yo n
EN
m en uer
sor
tf unct
st y i on.
t s he dbx_ at em
sor ent
.
st o m so t ac ep
r t f u nc t ar s
e:
t i o n. H ow
e ve
r , i t im s
o r e ef f i c i e n t o us
e
la r
],
/ / yo
u r cu
stom s
o rt d e f i n i t i o n
} d b x_
so
r t ( $ r e su
l t , "m
//$ r e s u lt is n o w
dbx
_ co
Th db e
m pa
y_
r e( RO
x_com
so
r t ") ;
s o r te d a c c o r d in g to m y _ s o r t( )
par
W 1, R O W 2 CO ,
f e unct
a i on
l l ow t you s
R O W > 1 R O W 2, tdbx_com hen ac
ce
pt ar s
par
c om o
par
r e et ur 1. ns
Y, FLAG
S)
t e w r o esul
t se
s, R O W a 1 R nd
O W 2. I f R O W = 1 R O W 2, t hen
I fR O W < 1 R O W 2, tdbx_com hen
R O W 1—
A r esul
t f r om d a bx_q
uer
f y un
c t i on c al
l.
R O W 2—
A r esul
t f r om d a bx_q
uer
f y un
c t i on c al
l.
M N K E Y — nam The
F LA
G S — Y ou c an
sho
ul b d m e
ad
of e tcol he spec i
um w on n
f sev y
e. S ep
r al f l ags
ar at t e he or de
par
t o c om
M P _A
S C — ( def
D B X_C
M P _D
E SC
D B X _C
M P _N
A TI V E — ( def
D B X _C
M P _TE
X T—
P_N
U M BE
_CM
hi t ch com he pa
r of an t y ype
D B X _C
D BX
$c o
N KE
r e et ur –1. ns
The
ar gum
dbx_com ent
par t s hat
r e et ur 0. ns
dbx_com
par
If e
e:
C O LU
E xam
LUM
t ) C om
— C om
C om
par
R — C om
pi pe
.
par
i e ascendi n
i e de n
sc
houl
m be d
i s a n scend
or ng
der
o ng
r der
.
t ) C om
par
t e i he
t em
" s i as
t e i he
t em
as s
st r i ngs
pa
tr e i he
t em
ade.
i ng or de
endi
aul par
si son
r e t he r ow
a by
aul
par
scend
i ng or der,
an w d
hat
t ype
of c om
pa
r i son
.
s. "
.
a s n s um
be
r s.
pl e: m = p db
x_co
m pa
r ( e $r 1, $r 2, " i nco
m e")
;
/ /$ c o m p = 0 if $ r 1 = $ r 2 / /$ c o m p = 1 if $ r 1 > $ r 2 //$ c o m p = - 1 if $ r < $ r 2
U si D ng N ow l i nk
t ha
B X t you
s. S i nc yo e
ha so ve
m i e de o a f ho
w t he D B X f un
i n a c ti o n .
S cri
p t 3– d 1 b x_
u r l s. p hp
[ V i e w f u l lw i d t h ] 1 .
tm l>
c t i on w s
a u r u e si ng D B X , yo c u an us t e hi a s p
l i ca
or k, l et c'r s
ea
t i on w i t a h ny da
t a e sm t ab
al lU R d L at ab as t e ha
t i su s
p
ase
t ke o
ort
ed by D B X .
ep t r o ac k
f som
o e f you
r f avo
r it e F i g u r 3 e - 1 sh
ow
d s bx_u
r l s. ph
3 .
A P H P - D B X U R L O r ga
ni zer
< / t i t l e>
4 . < st yl t e yp e = t e xt / c s s> 5 .
p , u l , t d , h 1 , h 2 , h 3 { f o n t - f a m i l ve y:
6 . < / styl
e >
7 . hea
d>
rda
n a , h e l ve
t i ca
, sa
n s- e
r if;}
8 . 9 . < ? 10.
/* * * * *
1.
* TAB
12.
* c r ea
13.
* ur lV A R C H A R ( 128
14.
* de
sc r
15. 16.
pri * * */
m a r k y e (url y
17.
/ /d e f in e $ M O D U L E a s D B X _ M Y S Q L , D B X _ M S S Q L , D B X _ P G S Q L , o r y o u r s u p p o r t e d d a t a b a s e
18.
$ M O DU
DBX_ L = E
19.
$s = erv
" 19
20.
$u
21.
$pas w
2.
$da
23.
/* F U N C T IO N S * /
24.
f un
D LE
EFI
N I TI O N FO
t t e ab
lU e
R LS
XA
M PLE:
nul
l,
r = " ps
));
PG 2. 16
SQL;
8. 0. 5";
ql us
er"
t ab
= se
; or d" ;
" ph
p" ;
c t i on g et _ url
s($d
25.
$r esu
l t = @ db
26.
i f ( $ res
u l t= = 0 ){
ec h
db o
b co
x_q
x_e
ue
n
, $ sq
r y( $d
r r or ( $d
{l )
bc o
bc o
n
n
, $sq
l) ;
);
} e l se {
29.
ret
30. 31.
) not
or d = " pas w
28.
EI S
i pt i on T E X T ,
se
27.
R TH
(
u r $ n res
u lt;
} }
3 2 . f u n c t i o n u r l ( $ a c t i o n , $ d b c o n n , $ u r l , $ d e sc r i p t i o n ) { d ") { 3 3 . i f ( $ a c t i o n = "ad 3 4 .
$ sq
l = " i n se
r t i n t oU
R L S v a l u e s(' $ u r l ' , ' $ d e sc r i p t i o n ' ) ";
3 5 . } e l se i f ( $ a c ti o n = "de 3 6 .
$ u r l = u r l d e co
3 7 .
$sq
" l= de
3 9 . $r esu
l t= @
4 0 . i f ( $ res
u l t = =0 )
4 1 .
"
3 8 .
l e t e ") {
d e ( $ u r l) ;
l et f e r om
U R wLS
he
r Ue
R L ' = $u
r l'" ;
}
echo
db
x_q
ue
r y( $d
bc o
n
, $sq
l) ;
{
>E
R R O ADR
D I N UG
R L: " .dbx_er
r or ( $dbcon)
;
4 2 . } e l se { 4 3 .
pri
4 4 .
}
n t ( " < p>
$ ac
t i o n : $ url su
ce
e de
d !< p > " );
4 5 . } 4 6 . / * * M A I N * */ 4 7 . $dbc o
d=n
bx_cone
N EC D TO T
c t ( $M
AT B
ASE
O D U LE
, $ser
ver
, $dat
ab se,
$user
, $pa
sw
or d) or di e( " C A N N O C T
");
4 8 . ? > 4 9 . P
H DP
5 0 . < f or m ac t
B UX i on
5 1 .
b A
=d ad
5 2 . < br>U < i np
zer
h1>
ur l s. ph m p
et ho
d=
po
st >
U R L: b>
R L: < i n pu ut t yp
R L O r gani bx_
e=
" t ex
t t yp t " na
e=
" t e xt " n a m e = " url m e=
" de
sc r
i pt i on
" m a xl e n gt h = " 1 28 " > < i np
U R L! " >
5 3 . < / f orm
>
5 4 . < ? 5 5 . if (i s s e t ($a
d d u rl ) {
5 6 . u r l ( " a d d ", $ d b c o n n , $ u r l , $ d e sc r i p t i o n ) ;
ut t yp
e=
" su
" va bm
l u e= i t " na
" h t t p: / / " D > m e=
" ad
du
e sc ri r l " va
p t io n : l ue
= "A d
O N
5 7 . } 5 8 . i f (i s s e t ($d
e le t e ) {
5 9 . u r l (" d e l e t e ", $ d b co n n , $ d e l e t e , " ) ; 6 0 . } 6 1 . $sq
"sel l=
ec t
* f r om
6 2 . $ r e su l gt = e t _u
U R LS
";
r l s( $ d bc
on
n , $ sq
l) ;
6 3 . i f ( si ze o f ( $ r e su l t - > d a t a ) = = 0 ) { 6 4 .
? >
6 5 .
3>
6 6 .
S or r y, t her
ar e U no e
R i Ls t n da he
t ab
ase.
Y sho u
ul som ad d
e.
< ?
6 7 . } e l se { 6 8 .
? >
6 9 . < p > 7 0 . < t ab l e bo
r de
r = 1 ce
7 1 . <
< b>
U R L<
7 2 .
t d>
l l pa
d
/ b>
i ng
= 5 ce
l l sp
< / t d>
ac >D
i ng
= 0 w i dt h=
esc ri
pt i on
60
0>
b>
t d>
& nb
sp;
< / t d>
< /tr >
< ?
7 3 . f o r ( $ i 0 = ; $ i s< i ze o f ( $ r e su l t ->d 7 4 .
a t a ) ;$ i + + ){
? >
7 5 . < t r > < t d > < a h r e f = < ? = $ r e su l t - > d a t a [ $ i ] [ ' u r l ' ] ? > > < ? = $ res 7 6 . < t d > < ? = $ res 7 7 .
u l t ->d
7 8 .
u lt - > d a t a [ $ i] [ 'u r l'] ? > < / a > < / t d >
u l t - > d a t a [ $ i ] [ ' d e sc ri p t i o n ' ] ? > < / t d > 1>
a t a [ $ i ] [ ' u rl ' ] )?>
bx_
ur l s. ph
p?
de
l et e=
=u
r l en
c od
e(
> d e l e t e < / a > < / t r>
< ?
7 9 .
}
8 0 . ?> < / t ab
l e>
< ?
8 1 . } 8 2 . ? > 8 3 .< 84.
/ bod
y>
< / h tm l>
F i g u r 3 e - 1. d b x_
u r l s. p h p
S cr i p t 10
- 5. xm
l _d
u m p . p h p L i n e- b y- L i n e E xp
L IN E 2–14
U t se l hes
it nes
16
C r eat e an e
nt r i y t n d he
17
C r eat ad i an e
t i onal
20
–2
8
21
C r ea
tf a e
cr o
un
eat
i pt c an
ot c on
23
R et ur f n al ( se I f t he co
5
n
ec
t i on at t em
pt w s as
E t nd f he
30
I f t he con
31
P r i nt out
unc
t X he
M r L equ
P r i nt t he t op l evl
3
G en
er at an e
34
E xec ut
t e S he
36
–5
Lo 1
op t hr ou
S Q st L
at em
Q qu L
er and y
Cl os t e h whi e
53
C l out ose
54
C lt ose
i he
en
ll e o t X he
t hen
on
ne
ct i on t t o he da
( Y c an ou r epl " m ysq l" ) .
t ab
as
e.
al ac e
lt he M S S Q f L unct
as se e
r ve
wi ons
it h
i pt w i l l us
e.
pr i nt an er r or .
c ause
sf
t d he
at ab c o ase
ul , t he se n
, bec ause
l ec
n
t he da
t ab
t he cone t
r ue
ec t
if on
as o e t n he da
i on w suc es f as
ai l ed. t ab
r t ha
t t he scr
na he
t a i ve
ul .
n. S i nce
t sel o
ge P as
e. Y ne ou
ec t r he
t ed t use o
t hi i s an s
ad
al lof t he con
t en
ti n $ he
r esul
esul
en
l an e
orde d
ent
c l t a t ose
st ar l t on ed
30i. ne
t encl o
t ose
?> nd
X M L
t ag
r es bo
l lt by s
ast
ok> na
.
m e, t he f n i r st na
m e.
e.
.
t f s ou
nd w i t hi n " co
l t a ot of da
t a, i t ' ea s
f ag
or t r he
ot
el em
si t er j o us
t . P r i nt o ut e a ch o f t he r e su nt ac
t c on "
t ai n t he de
p . i nt iou ng
ent
s.
t he t op l evl
ab i abl
H P . S i nc w e a e r p e r i nt i ng ou l em
i nt st at em H P t ag
o k,
t of s t t he t var
.
pr he
dr b es
n e g a c h l i n e as a p r i n t st a t e m en be
xt l i ne
ot i nt e r p r e t e t d b o P e
w i ta h w hi l e op
si
nt i nu o e t n t o he ne
M pag L
e
pl t ac e
t . T he su
M pr by L
f st at em
, t he co n
X ani n
en
t se
ng t he pa
t el " em
5 2
cae
12i. ne
X M t L ag t o he scr
si
nt ac
ce am
i r t ed beg o
X M L i n st e ad o f p r o c e " co
, be
t i o ns so t h a t t h ey n are
gh t he r esul
S t op proc e
uc
ct i on r et ur t ns
ng i n st r uc
32
t d c reat o
l ar at i on.
c t ( ) f un
si
ase,
am
st ar l t on ed
t deci on ne
ab
l i ng pr ogr
ent
c t i on i use s
t i n ih case, s M an S S Q d L at ab se. gi gn t he f i r st " s" im n sq l t a o " y" —
an
r ogr
f st at em
t ab se.
t ( ) . T hi f s un
l l ip ng
28
52
ec
0) t o ca he
C lt ose
35–
n
t o he dat
27
S Q da L
ab se.
ec t
R et ur t n r ue ( 1) t o he cal
p r o ce
i e your n
r i y t n dat he
l l ed c o
26
i he
abl
ect t o d he at abse, c t i on si s m pl b y c h y
I f t he scr
–2
at i o n
s e.
ent
c t i on c a
A t t em pt t c on o M yS Q f L un
t e t he at ab
2
24
l an
D E S C R IP T IO N
ent
dr es bo k>.
t ha t ve
he se
r ve
r se
l t r s e t u r n ed i n t he cu
t ai ol s f t he ad
dres
bo
ok en
nd ou r r e n t r ow t r y.
t pl ai n a p s art o f a
L IN E 5 5
D E S C R IP T IO N En
dt h es c r ip t .
T o p
C h ap I T n hi C s
ha
t er 1 .
G en
er at i n g D yn
am
iG c
r ap
h i w cs
ithP H P
pt er O ver
vi ew
Th G e
D Li br ar y
E nabl
G i ng
G en
D S up or
er at i ng G r ap
t hi w cs
i tG h
D
T o p
O ve P H P i ab s l i bra i
r vi ew l t e d o yn e t s ha
nt are
am
i ca o t i nc
l l ge y
ne
r at a e nd m od
l u d ed b d y e f a ul t w h e n yo
i f i y m ag
es
. T u o t se
hi ad s
va
nc
ed f un
c t i on
al i t i y P n
H P , yo n u e t d i o nc
l ud so e
m ae d
i t i on
al
u i n st a l l P H P .
T o p
T he G D L i b r ar y P H P pr ovi
de t s he ab
w w w . bo
i l i t y c o r ea
ut el l . c om
/ gd
" A An
co
ou
sl y, G D w w as
m pres i
t e an
d m an
i pu
on al go
l at e i m ag
es t hr ou
gh sup
po
r t of t he G D l i br ar y. T he G D ho
m p e ag
e li s oca
t ed at
n l d i st t s h e d e f i n i t i o n o f G D a s:
N S I C l i b r ar f y or t he dyna t cr eat G e I i F m ages.
G D no does P r evi
/a
i de
l use y
r i t hm
f d or c r ea
us
m cir c
eat
i on of i m ag
es.
G D cr eat
P es
N G and
JP
E G i m age
s, am
on o g t f her
or m at s.
"
t i ng G I F i m ag
ed i n G I F i m ag
es
, r ec
en
es,
bu
t lst y
t U ni C sy
art
ed en
or p. , t he com f orc i
ng t he
pa w ny
i r pa
t en
t r i gh
hi o ch
w t ns
t s, an
he pa
d G I F c r ea
t en
t f or t he LZ
t i on w as su
W
bs
eq
ue
nt ld y r op
pe
d
f r o m t he l i st o f G D f e at u r e s. H ow ad
ev r
, G D c an
di t i on
, G D sup
B as
i ca
l l y, G D sh
use
d t o m an
G D im s
os
i pu t us
st i l lbe used po ou
tcr o
r t cr s l d co
l at e exi ef ul i c n r ea
ea ve
eat
e JP
E G and
P N G gr aph
t i on of W B M P i m ag r yo ba ur
st i ng i m ag t i ng bu
se n s i c e es by ad
t t on i m ag
i c s,
bot
w hi ch ar u e sed
l f y you or di ng t ext
es
es,
r sc r t o t he
, as w el l as em
i pt ed grap m t or o c r ea be
d
o h f w hi a ch f sm or
i ng ca
al lm ob hi creat c
t e ne
r e sup
i on ne w i m ag
or t ed m by
i l e w i r el es
es ou
ed
ost
de
s. N ot e t ha t of t w o m or
pt i on i s e n xi st i ng i m ag
of t he po
ul W ar
eb br ow
ser
s. I n
vi c es. t G D in s ot a pa
or e exi es
st i ng i m ag
i nt prog
r am
. I t ca
n
b e
es.
.
T o p
E nabl
i ng G D S up
G D su
p
us are
i ng Li nu
ort in s ot en
l ed by de
rt
f au
l t . Y ou m us
t en
ab
l e t he ex
t en
si on i f yo
u u are
si ng W i nd
ow
s, c om or
pi l e-i
pi l ed an i d ncl
ud
n/ l i nk t he ex
t en
si on i f yo
u
x.
E nabl E na
ab
po
i ng G D f or W i nd bl i ng G D sup
po
r t f or W i nd
i n st a l l a t i o n . O p e n yo
ow
p hp
u r
ow
s
i s ver s
ea y
sy,
si nce
. i n f i i l e i n a t e ed xt
t he D L f i l f e or G D ha be s i t o an r
d se
en pr e- c om
a r c h f o t r h e l i n e t h a t sa
ed i t n he ba
si P c H P W i nd
ow
s
ys :
e xt e n si o n _ d i r = . / T hi l s i ne sh f i l e, t he
ou
l d po
i nt t o t he pl ac
n yo d u o no
t ne
e w he
ed t o m od
n e e d t o e d i t t h e l i n e t o p o i n t t o t h e co ex
t en
si on
_d
i r = C : \ A pa
N e xt , f i n d t h e se ; W i nd
ow
ch
e\ ph
ct i o n i n t h e
E s xt ensi
r e yo P ur
i f t y he l i ne
H P ex
. I f yo d u i d no
i de
. I f yo
u co
t m ov t e he P H P ex
t en
si on r s es
t en
si on t s o t he sa
r r e c t d i r e c t o r y, f o r e xa p\ ex
t en
si on
p hp
. i n i f i l e t h a t s a y s:
ed by m an l y i ne o s f W i nd
ow
m i co
in
n t a i n ts h Ge
ex
t en
l o a n t t he b eg
A f h t you er Y ou c a
ave n ve
p_ un
si on t s o t he sa t as ory
m e di r ec
t as ory
t he
ph
he
m p le :
ons
se
= ph
t en
m e di r ec
s
T hi l s i ne w i l lbe f ol l ow
si on
pi ed t he ex
gd c om
i n o g f t h l e i n t e) h a t c o
. s dl l ex
t en
si on f s P or D l i D bra y
H P . T e o na
bl G e
D su
p
ort
, un
co
m m en
t t he l i ne ( de
L L :
. dl l m en
r i f t y he G D ha b s e
t ed t he l i ne n co
r r ec
, save
t he f i l e an
t il y ns
t al l ed by us
d r est
ar t he A pa i ng t he ph
pi nf o()
F i g u r 1 e 1- 1. p h p i n f o ( ) r es
che
W eb serv ; as se
u l tw s
.
en i n
i t h G D en
F i gu
ab
re1
-1
.
l ed f o r W i n d o w s
l et t e he
p h p. i ni p . i n if i l e , t h e n yo u
E n ab
l i n g G D f o rL i n u x
I f you
pi l ed P H P usi
c om
P H P m odul B e f rec o re b c an
che
A' s P X S f un
m pi l i ng P H P , I f i r st su
g g e st t h a t yo
i bre a s
do e
a ne
f s ol l ow
cd / p a t h/ t o / ph r m co
nf i g. ca
m c l ake
ean
A f t you er c l ea
e c l ea c n om ' t ne
s. I f you
ha b ve
, i t g 'a s
o b d et t ha
' c l ve
ea
m an
ed w he
l em
To c om
co
m pi l e - - w i t h - a p xs=
/ p a t h/ t o / ap
a ch
e/ b i n / a px
s
) , t h e n a d d i n fun g
c ti o n a l i t t y o t h e
u d el e t e t h e c o
n f i g . ca
ch
e f i l e an
d c l e a n u p f i l e l s ef t o ve
r f r om
t h e prev
i o u c s o m p i l Th e.
is
urc e
e t he m ak
you
al i t ( y
e
yt hi ng
O nce
. / co
p / so ch
i su
c t i on
s:
ni ng up f i l es i t w on
pr ob an
ng A pa
ez.
e co n
n you
u w i l l no
t i c e qu
m pi l e. I f you
do
m pi l i ng P H P w i t n h p o r ob t t he m ak cl e
ne u d t p he m f es
pi Pl e H P w i t G h
d, yo r ec o
r om
D sup or
m p i l e - - w i t h - a p xs = / u sr/
ea c o n
t enab
l ed:
l o ca
l / a p a ch
t e he co
m m an
l em
m m an w d
t he pr evi
i t e f a ew
f i l es be
n' t r un t he m ake an s i l l so
ou c om s
su d l y ve
pi l e, you
d ou
en r probl
c an
i ng de n c om
li y t w on em
ge
l et ed
c l ea
. D on m an
' t c om
' t w or d, t he
pi lri e gh
a y bo n you t ev
ut i t . T he m ak
m ay st ar t r un t n ho
ug yo h
e prog am
i j s us
ni ng i nt o som h u ave
n' t cha
t
e ng
ed
.
t s ar t ed w i t h he ne
w c om
pi l e.
e / b i n / a p xs \
- - w it h - g d \ - w i t h -g d -na -w
t i v e -t t f \
i th -t tf
A f t er t he co m ak A s um
nf i gu
r r e un
s, i s u
d:
e i ng e no
r r or oc ur s
c a , you
t n hen
i t s ue
co he
m m an
d:
m a ke i n st a l l T h f e i n a l co R es
t art A pa
m m a n c d o p i e t s h l e i b p h p 4 . so l i b r a r f y i l t e / o p a t h / t o / a p a c h ch t e o l oa t d he ne
w l i bra
e / l i b e xe
c/ .
y:
/p a th /to /a p a c h e /b in /a p a c h e c tl r e s ta r t Y o c u an ve
r i f t y he G D ha b s e en co
r r e c t l i y n st a l l ed by us
i n t g h p e h p i n f o()
f u n ct i o n .
T o p
G en
er at i n g G r ap
O nce
you
ha co ve
nf i gu
Th Li e an nes T he ba f se $l en
c t i on t u o w se
eC
r ea
he creat n
t ar s
$b
l ue = I m ag
gu
m en
ed an i m ag
eC
ol orA e c r ea e:
H ea
t en
r ( " C on
I m ageP
t hat h you
ave
i ne
T h e p oi n t w s
at e($i
c r eat
( $i m ag $x1 e, h i c h yo
lo r ) ;
t i ng an a d R n e, 0, 0, 25
hi cs.
i y t s he I m ag
eC
r ea
t e() f un
c t i on
.
t e m ove
m co e
l t or i o t us
G B c ol
or val
d gi ve i n c t a ol or. N ow
e/ pn
g")
i ng t he I m ag ue
eC
ol orA
l l oc
at e() f un
c t i on
. I m ag
eC
ol orA
l l ao
ca
t e() t ak
es
:
5); al l t ha
t i l s ef t i t s o di sp
l ay t he i m ag i e a n brow
se
r . T o do t ha
t , yo n u e t d w o
;
ed i base your
u sp
m ag
n ne
ct i ng t w e o nd
, $y $x2 1,
, $y $c o 2,
e c i f i y n t h e I m a ge
e, you
a c an
t s t o he r i gh
t , as i n a no
l or)
m e ba d in
t r i n g ( $i m a g $f e,
sha e
pes
ct i on t ha
ont
i o t .T he m ost
e . L i ne a s r c e r e at e w d
t ou
t pu
basi
t s he i m ag
" c shap
e" you
i t t h h I e m ag
e Li n e()
e t ha
a c an
t yo
u ha
ve c r ea
d t yo o
t ed
ur i m ag
e
f u n ct i o n :
;
L i n e ( ) f un
c t i on a r e x, v y e r t i c e d t o p l a c e sh
r m al m at g h r ap
) i 1 s p 0 i xe
d som
p o i n t o s y n o u r i m ag
d h e r e i a s l i t t l e d i f f e r e n t . T h e g r i d u se
G D al so su p ort so s o n l y f i ve si ze l s, i ste
$ co
g e r ap
se r t o ex pe ct a P N G i m ag e, an d t he se co nd l i ne it s he f un o u go t yp i n g t h a t a l l i n , t h o u gh , l e t 'a s d d so m e t e xt .
m a t g h r a p h, so t he p oi n t ( 1 0 , 20
I M a g eS
t i ng som
;
t ed b c o y
t h a t t h e g r i d u se
ea m ag
t - t yp i e: m ag
your
i a s l i n e. A l i n i e c rea s
r di na
si ng t he G D l i bra
e, yo n u e t d a o d so
t ed b a ox an
T eh f i r st l i ne t el lt s eh brow t o t h e b r o w se r . B e f y ore
co
st ar t c r ea
i dt h) ;
a u r cr e
l l oc
N G ( $i m age)
eL
gt h, $w
t t s he i m ag yo e
S o no w yo h u av m or e l i ne o s f cod
I m ag
i ng i m ag u es
t e( $l en
h u av c reat e
i as
N ow
c an
;
$i m ag = e I m ag
de
he G D l i br ar y, you
0;
i dt = h 10
O nc yo e
r ed P H P t u o t se
ithG D
T d ext
un
gt = h 30
$w
h i w cs
h. T he co y
s, a l m o st l i ke t h o se u se
d i n pl o t t i ng p oi n t i s n m a t he
a p e i s n G D st a r t a s t t h e x, p y o i n t 0 , 0 i n t h e t o p l e f t c o or di na
l t s t o h ri e g ht o f t h u e p p l er e f t co
t h e ow
ev
r , m ove
d s ow
n, i nst
r n e r of t h i e m a g a e n 2 d p 0 i xe
ea o d f up
m a t i exc s,
w ar a d i s t do i es a n
ld s o w n .
si st c r i ng f un ct i on t s ah t al l ow yo t u o pri tn t ex t on t o t he i m ag e. Y ou ca n on l u y se on b e as i f c on t an d t he r e are T ab l 1 e 1- 1 , b u t i t w o r w ks e l l f gr or a p hs an c d h art w s h e r f e l as yh f o n t a s r n e o t r e q u i r e d . T a o d t ex t y o o u r i m ag on
t S i ze
, $x $y1 1,
, $ st r i n g,
p t
r n e r .T h e x
e :
T ab
l1 e
- 1. F o n t S i T zes
h at C an B U e
FS OI Z N E T
sed
f o r G D S t r i n g F u n ct i o n s
F O N T
S IZ E
1
g d F o n tT in y
2
g d F o n t S m a ll
3
g d F o n t M e d iu m B o ld
4
g d F o n tL a rg e
p i x e8 l s x 1 5
5
g d F o n tG ia n t
p i x e9 l s x 1 5
T he ne gr ap
xt sc r
i pt c r ea
h w or a ks
S cri
t es s a i m pl g e r ap
nd t he ap
p t 1 g –1
pe
ar an
d _g
h, sh
ow
ce of t he t ext
in n
F i gu
p ix e 5ls
3 . $w
re1
-2
p i x 7 e l xs 1 3
, u si n g t h e I m ag
e Li n e() a n d I m ag
si zes:
r id .p h p
1;
i dt 301; = h
4 . $i m ag I = e m ag 5 . $w
hi t = e I m ag
6 . $b
l = ue
I m ag
7 . I = $red
eC
r ea
eC eC
m ag
eC
t e( $w
i dt h, $h
ol or A l l oc a ol orA
l l oc
ol orA
at e($i
l l oc
ei gh
t);
t e( $i m ag
e, 25
m ag
at e($i
5, 25
e, 0, 0, 25
m ag
e, 25
5, 25
5) ;
5);
5, 0, 0);
8 . f o r ( $ i = 0 ; $ i< $ h e i g h t ; $ i= $ i+ 2 0 ) { 9 .
I m ag
e Li n e($i
m a ge
10.
I m ag
e L i n e($i
m a g 0, e,
, $ i $i , 0,
1.
I m ag
e S t r i ng ( $ i m a ge
12.
I m a g e S t r i n ($i g
, $ he
i gh
t , $b
$ i , $ w i d t $i h, $i, 1,
+ 0, 2,
lu e ) ;
, $ bl u e);
$ i ,$ r e d ) ;
m a g e ,1 ,2 ,$ i ,$ i ,$ r e d ) ;
1 3 . } 1 4 . I m ag
eS
t r i ng ( $i m ag
e, 1, 82
,2
, " S i ze F 1 on
t " , $red);
1 5 . I m ag
eS
t r i ng ( $i m ag
e, 2, 82
, 62
, " S i ze F 2 on
t " , $red);
1 6 . I m ag
eS
t r i ng ( $i m ag
e, 3, 82
, 10
2, " S i ze F 3 on
t " , $red
1 7 . I m ag
eS
t r i ng ( $i m ag
e, 4, 82
, 14
2, " S i 4 ze
F on
t " , $red
);
1 8 . I m ag
eS
t r i ng ( $i m ag
e, 5, 82
, 18
2, " S i ze F 5 on
t " , $red
);
1 9 . he
er ( " C on
ad
2 0 . I m ageP
ng(
2 1 . I m age
D est
t en
t - t yp
$i m age) r oy(
e: i m ag
e/ pn
g")
);
;
; $i m ag
8
p i x e6 l s x 1 3
1 . < ? 2 . $h ei gh 30t =
x
e) ;
2 2 . ? >
F ig u r e 1
- 2. g d _g
r id .p h p
e S t r i ng
( ) f u n c t i o n t s o i l l us
t r at e ho
w t he
S cri
p t1
- 1. g d _g
r i d . p h p L i n e- b y- L i n E e
L IN E
xp
l an
at i o n
D E S C R IP T IO N
2
D ef i ne a he
i gh
t of 30
1 pi xe
3
D ef w a i ne
4
C r eat
5
D ef i ne t he $w ih t var e i abl u e si ng t he I m ag eC ol or A l l ocat e( ) f unct 2 5 5, 2 5 , 2 5 ) t o be u se d b $ y i m ag e . I t i a s l so us ed a t s he ba ckg r ou
i dt of h pi 301 t e he base
l f s t or he i m ag (t e he ex
xe f l s or it he
t r p a i xe
l i so s
t ha
t t he f i na
l i ne on t he ou
t si de of t he gri i d vi s
si bl e).
m age.
i m ag u e si ng t he I m ag
eC
r ea
t e( ) f un
c t i on
, spec i
f yi ng t he hei
ght
and
w i dt d h ef i ned
i on. T he ar gu m en n d c o l f or o r $ i m ag
ear
l i er .
t al s l ow t he col or w hi t ( e R G B val ue e , si n ce i t i t s eh f i r st co l a or l o ca t ed t o
$i m age. 6
D ef ti ne col he
or bl al and ue
7
D ef ti ne col he
or al r and ed
8–
13
C r ea
9
l ow by uised tbe o l ow
i use t be o
t a e f l or o t p l o o t p hroug
W hi l e i n t he f l or o
$i m age. $i by d
m age.
a h nd draw
p, c r ea
t e a l i ne i nsi
l a i ne ev p 20 ery
de $i m ag
e f r om
4 0 , 3 0 1, e t c . ) . E a c h i t e r a t i o o n f t h e l o o d p r a w a s ve 2 0 p i xe 10
po r t i ca
l st s
art
i ng at t he co
i nt $i , 0 ( 0, 0 20
, 0 40
ordi
na
t 0 e , (up 0
, 0, et c . ) t o po
i nt $i , $h
l er ef t c o ei gh
t ( 0, 30
r ne
r of i m ag
1 20
, 30
e).
1
l i n f e r o m t h t e o o p f t he i m a ge t t o h b e o t t o m o f t he i m a ge sp
a ce a d t
l s f r o m l e f t t o ri g h t .
W ih l i e t n eh f l or o p, cr ea t a e l i ne i ns i de $i m ag f e r om po i nt 0, $i ( 0, 0 0 , 20 0, 40 , et c. ) t p o oi tn $w i dt ,h $i ( 30 1, 3 0 01 , 20 30 1, 40 , e t c. ) . E a ch i t e r a t i o n o f t h e l o op d r a w a s h o r i zo n t al l i ne f r o m t h e l ef t of h e i m a g e t o t h e r i g h t o f t he i m a ge sp a ce d a t 20 pi xe l s f r om
1
t op t b o ot t om
W hi l e i n t he f l or o f u nc
W hi l e i n t he f l or o
1 3
En –1
8
. p, c r ea
t e a sm
al l ab
t i o n. R e m e m b e r , I m a ge
12
14
i xe
p, c r ea
el t o di sp
S t r i n g($i
t e a sm
al l ab
l ay t he cu
r r en
m a g e, $ f o n t si ze
el t o di sp
l ay t he cu
r r en
t pi xe t lof he cu
r r en
, $ x, $ y, $t e xt , $c t pi xe t lof he cu
t ve
r t i ca
l i ne us
r r en
t ho
r i zo
nt al l i ne I m ag
d t h e f o lr o o p .
C r ea
t e som
e t ext
19
S t end
i he
20
D i spl t ay i he
m age,
$i m age,
21
D est
m f age
r om
m he age
r t oy i he
at var
i ou p s oi nt o s n t he scr
ader
t s t o us he
er br ' s t hat hav you
t ser he
ver
ow
se cr e
m em
e
n t d o i spl
ay t he var
i ou f s on
t ype
sent en
t o br he
s.
r. eat
or y, si i nce
ed. al thas
r be eady
i ng t he I m ag
eS
t r i ng
()
ol o r ) ;
ow
ser
.
eS
t r i ng
( ) f un
c t i on
.
A d
i ng Tr ueT
Y ou c a a n d be I m ag $ co
eT
ype
t t er-
lo
T F T ext
ki ng t ex
f s or I m ag
$i m ag
es us
gl $xc o e,
i ng T r ue
T yp f e on
r d, $yc o
or d,
t s. T he f un
ct i on t ha
t ac
ng t hi f s on
t.
co
m pl i sh
T F T ext
dl f er or t he i m ag i e w n
hi y ch
ou ar p e l ac i
T he a ng
l i e n n um
b of er
de
g r e es t h a t h t e e xt sl a nt s. N o t t e h at t h i s sn
h e n u si n g i t a l i c f o n t , b u t t h e sl a n t o f t h e "l i n e on "
' t t he sl an
t o f t h c e ha
o r d—
T h x e co
o r d i n a t i e t n h i e m a g o e f t h e bo
t t om
l e f t of t he f i r st ch
ar c t
e r i n $ t ex
t.
$ yc o
o r d—
T h y e co
o r d i n a t i e t n h i e m a g o e f t h e bo
t t om
l e f t of t he f i r st ch
ar c t
e r i n $ t ex
t.
ol or—
T he co
$ f o nt—
, gd
l of or
T h e l o ca
$t ex
t — T he t ex
_t ext
. ph
t he t ex
t . T hi m s
t i o n o f t h e T r u eT t ha
t yo
p, pr ovi
–2 g d _t ex
u w an
de an s
us
t be c a ol t or ha
yp
2 . $h ei gh 15t =
n previ
ou
sl a y l l oc
at ed t o t he $i m ag
t i n t he i m ag
m pl o e si f a
m pl G e
D i m ag w e
i t so h
m t e ext
, sho
w in n
t.p h p
;
4 . $i m ag I = e m ag 6 . $w
m ag
eC eC
r ea
t e( $w
ol orA
hi t = e I m ag
eC
i dt h, $h
l l oc
at e($i
ol or A l l oc a
ei gh
m ag
t);
e, 0, 0, 25
t e( $i m ag
e, 25
5);
5, 25
5, 25
5) ;
7 . $ f o n t = "a ri a l . t t f "; 8 . $t ext " = A dva 9 . I m ag 1 0 . H ea
eT de
nce
t ( $i m ag
e, 50
r ( " C on
t en
e: i m ag
1 1 . I m agePN 1 2 . I m age
d\ n\ r P H P " ;
T F T ex
t - t yp
G ( $i m age) D est
r oy(
$i m ag
, 0, 10
,5 e/ pn
, $w g")
r a c t e r t s h em
se
l ve
s, su
e.
e .
0;
i dt 30 h= l I=ue
t().
e F o f nt i l e ( . t t f ).
t t p o r i nt ou
exa
t ha b s e
1 . < ?
5 . $b
T F T ex
w h i c h t h e t e i xt s w r i t t e n .
$ xc o
$c
3 . $w
eT
( ) ar e:
T he i m ag h e an
l e—
a ws
p t1
es t hi i s I s m ag
— T he si ze of t h t e e xt , i p n o i n t s.
$ a ng
S cri
$an ze,
eT
e—
$ si ze
–2
r i m ag
r I m ages
t );
ent
S c r i pt 1
nt t o Y ou
t y o ou
( $i m ag $si e,
l o r $f , o n t $tex ,
T he ar gum
Fo
hi t e, $f on
t , $t ex
t);
;
; e) ;
1 3 . ? >
F ig u r e1
- 3. g d _t ex
t.p h p
F i gu
re1
-3
.
ch
S cri
p t1
- 2. g d _t ex
t . p h p L i n e- b y- L i n E e
L IN E
xp
l an
at i o n
D E S C R IP T IO N
2
D ef hei a i ne
3
D ef w ai ne
4
C r eat
5
D ef i t ne
ght
of pi 30
xel f s or it he
i dt of h pi 150
xel f s or ti he
e t he base
i m age
$ he
bl va ue
D ef ti ne col he
7
A si i nd
s, yo c a u
f i l j e; u st m ak 8
A si
l usi e
gn si a
I he
e( ) f unct
eC
ol or A l l oc a
m ag
kg
r i ab
t . Y ou ne
l l f y i nd T r ue
f yi ng t he hei
t e( ) f un
d co
c t i on
l o r f $i or
. T a he
m a ge
ed t p o l ac
st r i ng t o he $t ext
e t hi f s on
gh r gu
t and
w i dt h def
m en
t al s
i ned
l ow
, si nc i e t i t s he f i r st co
t f i l i e t n he sa
T yp f e on
t f i l i es C n
: \ W i nd
T yp
e f o n t h a t yo
u co
r e t he f i l e n a m e t of h e T r ue
m pl t e ext
spec i
ear
t c he
l i er .
ol or bl (R ue
l o r al l o c a
G B val
0 ue
, 0, 25
5) t o
t e t d o $i m a g e.
m age.
l e $f on
i ca
i on,
r o un
l ow $i by i used t be o
t n yp
e su
t ng
C r eat
. I t i a s l so u se a d t s he b ac
t f i l t e o t he va
ow
m age.
ng t he I m age
or w hi al t and e
gn f a on
IWn
usi r i ab
be u se b d $ y i m a ge 6
m age.
vari
ab
l e. Y ou c an
use
ow
m d e i r ec
s\ F on
t or s
p i y n t o t h e sa
t he synt
"\ ax
t f ory
r om
w hi ch t hi scri s
C : \ W I N N T \ f on
m e di r e c t a ory
n\ r " f or ne
t s hi sc s
w l i ne an s
pt i e s xe
cu
t s. Y ou c a u n a se r i p t i d s ef i ne
r d et ur ns.
S om
*ni e
t ed
T ny
.
r ue
d he
T yp f e on
re .
syt x
em
do s
n o t r e q u i r e t h e "\ r ". 9
A td
10
S t end
i he
1
D i spl
t ay i he
12
D est
r t oy
A d
$it o
sef
T cr o
eat b a e
I m ag
eC
$i m ag
Y ou c an an I d m ag i m age. T he I m ag
m age,
t you
c an
d t he
n su
ut t on n , you t eF
e = I m age
Y ou w ou
, an
an
t he l eng eS
eF i pu
f r om
T F B bo
ow
ser
t he ser
ver
m em
i on.
. eat
ed.
or y, si i nce
al t has
r b eady
en
sent
t o he br ow
ser
.
m ages i m po
r t an exi
st i ng i m ag t e w o
r i m po
se t ex
t on
t u o t se
w ne o
w G D f un
r si y
m pl f e un
P N G ( " bl ank_
l at $ e i m ag j e ust yo as
ta h nd w i dt o h f t he $i m age
x( ) f un
( ) f unct
t hat cr have you
pe
r om
Y ( $i m ag f e) un
eT
Text br ' s
$i m age,
P N G ( ) vei a s
C r eat
lt d he m n get
ed
r om
m ageT F
t s t o user he
t o B I ase
t t on
r ea
t ng I he
he i m age
ul ti n ha
e of a bu
m usi age m headr age
i ng Text
G D ial s u so i m ag
ext
c t i on
s, r es
c t i on i a s f ai r l c o y
wu you
pe
or w k
t o i t . T hi w s c t i on
ay
i t a h t s he ba o se , yo c u an c r ea
s. T hes
f unct
ct i on t ha
t j us
t c r ea
bl ue
_bt
t n. pn
ou
l i d f you
c r eat
c t i ve
m pl i c a
ia ons t a es
r I e m ag
t ed f un
i m ag
eC
w i m ag f e r om
t ed i t f r om
I m ag
eC
eF
r om
e. F exam or
pl e, you
t t on f s r om r ea
ne
t eF
t he ex
r om
on
c an
lo y ne ba
t ake
b a l an
se i m ag
P N G ( ) an I d m age
k
e f i l e. T T F B bo
x( ) .
i st i ng P N G f i l e:
g" ) ;
ha cr d
ea
u e si ng t he I m age
l y; S X an S d
n f a ew
t e m ul t i pl e bu
Y m ea S n
ct i on t ha
C r eat i o ze
t r et t urns
f t he X ax
he co
r ea
t e.
P N G ( ) f un
c t i on u by
i ( s t he w i dt and h)
r ne
r co
ordi
S i o ze
na
t es of a bo
si ng t he I m age f t he Y ax
un
i ( s t he he
di ng bo a x r ou
S X ( $i m age i gh
)
t ) of t he
nd yo t ur ex
t . Y ou
t
p r o vi d t e h s e i ze
, a n g l e , f o n t , a n tex d
t ca o
l cu
m uc s h pa
$t ex
t bo = x I m ag
T ab
l1 e 1- 2 l i st t s he co
1 -4
p
l at h e ow
r ov
eT
T F B bo
i de a s grap
st r i n o g f t h tex
c e yo t ur ex x( $s
t us
i ze
, $a
es ng
o r di n at e f s o r ea hi ca
l r ep
r es
en
a n t d h f e u n c t i o ret n
. U sa l$f e,
ge of t he scr on
t , $t ex
c h o f t h e e l em
t i s n t h e a r r a ret y
ay el em
F i g u r 1 e 1- 4. A r r ay E l em
T ab
l 1- e
o r d i n a t e i s a n a n r r a y. T h i a s r r a a y l l o w yo s
en
en
t i s n t he bo
u r ne
d f r om
un
di ng bo
t he I m a g eT
2. C o o r d i n at R es
et u r n f ed
r o m I m ag
1
c Y o o r d i n a t o t e h f l eo w e l e r h f t a n c d o r n e r
2
c X o o r d i n a t o t e h f l eo w e r i r g h t a n c d o r n e r
3
c Y o o r d i n a t o t e h f l eo w e r i r g h t a n c d o r n e r
4
c X o o r d i n a t o t e h f u e p p e r ir g h t a n c d o r n e r
5
c Y o o r d i n a t o t e h f u e p p e r ir g h t a n c d o r n e r
6
cX o o r d i n a tote h f u e p p e l e r h f ta n c d o r n e r
7
cY o o r d i n a tote h f u e p p e l e r h f ta n c d o r n e r
m on
st r at h es
ow
t t o ak a e bl an bu k
t t on an a d d t ex
t mo
t he o ut p u t .
S c r i p t 1 g –3
d _b
u tto n .p h p
C r eat
eF
1 . < ? 2 . $i m ag I = e m age 3 . $w
hi t = e I m ag
eC
ol or A l l oc a
r om
c t i on
. A d d i t i o n a l l y,
F i gu
re
eT
T F b o x( )
B O U N D I N BG O C X O O R D I N A T E c X o o r d i n a t o t e h f l eo w e l e r h f t a n c d o r n e r
i pt de
( ) f un
t f s o r t h c e o o r d i n at es i n b a o u n d i n g b o x
0
xt sc r
T F B b ox
x.
A R R A PY O S I T I O N
T hi ne s
u
t); en
t at i on t of he ar
u r n t s h c e o r n e r co
i pt i s:
P N G ( " bl an t e( $i m ag
e, 25
k_bl
ue_ 5, 25
bt t n. pn 5, 25
5) ;
g" ) ;
ak m e
an di y
f f ernt
bu
t t on
s. S e
F i gu
re1
- 5 f e an or
xam
pl o e f
4 . $ f o n t = "a ri a l . t t f "; 5 . i f ( ! i s e t ( $ t e xt ) ) { $ t e xt = "B U T T O N " ; } 6 . $s i"20 = ze 7 . $an
"; gl e=
" 0";
8 . $t ex t bo I = x m ag 9 . $t e xt b ox _w
eT
T F B bo
i dt h = a bs
x( $s
i ze
, $a
1 0 . $ t e xt b ox _h e i g a = ht
b s( $ t e xt bo
w i dt = h I m ageS
X ( $i m age)
1 2 . $i m age_
hei
ght I = m age
S Y ( $i m age) t bo
( $i m ag
e_
w i dt - h $t ex
1 4 . $y = ( $i m ag
e_
he
1 5 . I m ag
i gh
t - $t ex
1 6 . H ea de 1 7 . I m agePN
r ( " C on t en t - t yp G ( $i m age)
1 8 . I m age
D est
x_ x_
t);
; ;
he
e , $ si ze
i gh , $a
e: i m ag ;
$i m ag
t , $t ex
x[ 0 ] ) ;
w i dt h) / 2;
t bo
e T T F T e xt ( $ i m ag
r oy(
l e, $f on
x[ 7 ] - $t e xt b o x[ 1] ) ;
1 1 . $i m age_ 1 3 . = $x
ng
( $ t e xt b o x[ 2 ] - $ t e xt bo
t ) + / 2 $t ex
t bo
x_
n gl e , $ x, $ y, $w
e/ pn
g")
he
i gh
t;
h i t e , $f o n t , $ t ex
t);
;
e) ;
1 9 . ? >
F i g u r 1 e 1- 5. g d _b
S cri
p t1
- 3. g d _b
u t t o n . p h p L i n e- b y- L i n e E xp
L IN E
l an
at i o n
D E S C R IP T IO N
2
C r eat ne a e
3
D ef i ne t he $w
4
u tto n .p h p
w i m u age
25
, 25
A si
gn f a on
si t ng I he
hi t e var
, 25
) t be o
i abl
m ageC
e usi
used
t f i l t e o t he va
r eat
eF
ng t he I m ag
$i by
m ag
r i ab
l e $f on
eC
r om
P N G ( ) f unct
ol or A l l oc at
i on,
e( ) f unct
spec i i on.
f yi " ng
bl ank_bl
T he ar gum
ent
ue_b al s
bt n. png"
l ow
t he col
w or
t as ba he
i se
m age.
hi t e ( R G B val
ue
pt i e s xe
t ed
e. t . Y ou ne
ed t p o l ac
e t hi f s on
t f i l i e t n he sa
m d e i r ec
t f ory
r om
w hi ch t hi scri s
cu
.
I W n i nd ow s, yo ca u t n yp i ca l l f y i nd T r ue T yp f e on t f i l i es C n : \ W i nd ow s\ F on t or s C : \ W I N N T \ f on t s. Y ou ca u n a se T ny r ue f i l j e; u st m ak e su r e t eh f i l e n a m e t of h e T r ue T yp e f o n t h a t yo u co p i y n t o t h e sa m e di r e ct a ory t s ih sc s r i p t i d s ef i ne d he r e . 5
C he t ck s o e i f t he $t ex a p p a r e n t i the n
6
A s i f a gn
7
A si t b o "0 , e
8
C r eat
ont
gn a an
t va
n e xt sc
ng
l t e t o f he
t e he t ext
bo as i by x
l i e se s
t . I f i t i n s ot , t he a n si
gn t he st r i ng " B U T T O N " t $ o t ex
t . T he r ea
so f n t or hi w s
i l l be
r ip t.
si t ze t o $si he
si nc y e ou w an
r i ab
T yp f e on
var ze on
i abl t usi
t ng
t t h t e ex gn
e. $ he
an
t b o h e ori i ng t he val
gl va e zo
r i ab n t al ac
ue of t he f unct
l e. T hi ar s
gu
m en
r os t s he p ag i on I m ag
t i r s eq
ui r f ed
or t he I m ag
eT
T F bo var x
e ,w i tn h ao n g l e . eT
T F box(
) t o he var
i abl
$ e t ext
bo
x.
i ab
l e. Y a ou
si
i gn
t
t
L IN E
D E S C R IP T IO N
9
D et er m i ne t he w i dt o h f t he t ext f r om t ho
10
t he t ex
t bo
x' l s ow
ug t h he r esu
l t i ng nu
m be
i gh
t of t he t ext
D et er m i ne t he he f r o m t he t e xt bo
bo by x
l er ef t - ha
ge
nd co x r m b ay
n e eg
n dcy o
1
D et er m ti ne w he
12
D et er m i ne t he hei
13
D et er m i ne w he
r t e p o l ac e
w i dt o h f t he ba i se
m ag a e nd di vi di ng 2 by
14
yo
u r r es
ov
e r l a p . T h i s, o f c o
D et er m i ne w he t ex
t bo w x
l ef t - ha
nd co
e r l sp y
16
S t end
i he
17
D i spl
t ay i he
18
D est
r t oy
si lreus y l h os
of t he ent
T he ab
r d i na
sol
t ng I he usi by
r t e p o l ac e
ue of t he t ext
t he val y
l h s i gh
"t e xt"
r ne
r ( an n d ot t he up
pe
i m age
m headr age
usi
r wy
r er
i gh
, si nc
e yo
u w an
t o ha
t s he ne
ga
r r em bo
ove
t - ha
nd co x
r di na
ve a po t i s ve
x' u s p l er ef t - ha
gn
nd co y
t su e
bt r ac t
si t i ve nu
ed
m be
r , ev
en
.
or di na
t e sub
t r ac t
ed
i on.
Y ( ) f unct
i on. m ag b e sub y
el l i f yo
p 0 i xe
lw s
ve o s n e p i xe
t r ac t
i de
i gh
t of t he t ex
l d gi ve yo
u a va
l ue f 1 of
r l ef t - ha
nd co
r ne
t bo
l on e i t h si er
t or he co y r as yo
ov
ordi
na
u m i gh
t as
t bo w x 8 as
bo f x r om
pi xe
lw s
t b o f x o r t h e ba
i de
t he , t he
n
se i m a ge t o
r b a se i m a g e. t r ac t
i ng t he t ext
e, i f yo bas ur t H e.
su
ur t ex
d e o f t he t ex
m ag b e sub y
x. A ab s
i ng t he w i dt o h f t he t ext
, an yo d
u r t e xt bo i x l s a r g e r t h a y n ou
ir n el at i on t o he ba i se
ng t he I m age
t s t o user he m age,
he i m age
$i m age, f r om
br ' s t hat
T T F T ext
ver
ow
n in
t ex
ow
ser
you
t he ser
e t hi s s cr i pt , as sh
ve
r al bu
, a i s n t h e f o l l o w i n g sh
S cr i p t 1
x' l s ow
bo he x
i e m ag w e 1 as e yo
i gh
t f r om
p 0 i xe
ow
ev
er, si nc
u sp
ec
m e), yo
u ne
ed t o al so ad
d t he he
t he x, val y
ue t s hat h you
ave
l hi s
i f t y he l ow i gh
t he ba
se
gh an yo d
ur
er
t of t he t ex
t bo
x,
( ) f un
c t i on
. Y ou use
j ust
det
er m i ned
to
ac t e h t e e xt i n r e l a t i o t n o t he b as i e m a g e.
t / g d _ t e xt . p h p?
al l se
S X ( ) f unct
i m ag w e 1 as
ue of t he t ext ou
be
ir n el at i on t o he ba i se
. I f yo base ur
. T he a n d t he he
, t hi w s
ue of n a um ue of t he t ext
ng t he I m ageS
, d o e n s o t w ve ork
c t i on
ut e val
m age
. ha
m em
c r ve
eat
t t on on s o r t sc
e d .
or y, si i nce
al t has
r b eady
F i gu
re1
- 6 ad , by
en
sent
di a ng
t o he br ow
par m
et er t o U he
ser
.
R L—
f or exam
pl e,
t= H O M E .
F i g u r 1- e
Y ou c a a n l c so
s( ) val
bo
s( ) f un
t e.
usi by
i r i e m age t he val x
u r se
t o he base
pro
n ea
at i ve.
l ue of t he t ext
e t he ab
u v a al ue of 9.
A d t he t ext
ht t p : / / l o ca
nt i r i e m age
t an d d i vi di ng 2 by
as 8 pi xe
gi vi ng yo 15
ut va e
t e. Y ou us
ul t i n g p x o si t i o n f o r t he t e xt w o u l d be a t 1 . T h i l s ea
i m ag h e ei gh
Y ou c a
ght
sol
na
bo b x g y et t i ng t he ab
x' l s o w e r l e f t - ha i dt of h te he
t t i ng t he ab ordi
6. g d _t ex
on p e ag u e si ng t he H T M < L i m g> t ag an s r i p t .S e e
–4 b u t t o n s. h t m l
F i gu
re1
- 7 f exam or
ref d
t . p h p ? t ex
t =H
O M E
ernc
m sc e
r i pt us
pl o e ut pu
i ng t he sa t.
i ng di f f ern
t va
l ue f s or
1 .
tm l>
2 . 3 .< t it le > B u t t o n s ! < / t it le > 4 .
hea
d>
5 . 6 .
8 .
. ph
t t on
_b
?t ext . ph
t t on
. ph
ut t on
. ph
=H
O M E " ><
?t ext ?t ext p?
=G =N
t ext
br >
A M E S " >< E W S " ><
br > br >
= LI N K S " >
y>
1 1 . < / ht m l >
F ig u r e1
C r eat
i n g R ect
I a n d d i t i o t n tex o w i t h t he sa I m ag
eF
T he ar gu
an
g l es w i t h G D
a n l d i n e s, yo c u a a n l so e a si l u y se G D t c o r e a t rec
m e argum
en
i l l ed
R ec
t an
m en
t s I o m ag
$i m ag
t s o c r ea gl e($i eR
e—
- 7. b u t t o n s. h t m l
t e an un
m ag ec t
an
e, $x
f i l l ed r ec 1c
o
r d, $y
gl e( ) an I d m ag
T he i m ag h e an
t an
t a n g l e s, e i t h e r f i l l e w d
i t a h co
gl e): 1c
eF
o
r d, $x
i l l ed
R ec t
2c
o an
dl f er or t he i m ag i e w n
hi y ch
r d, $y
2c
o
r d, $c
ol or)
;
gl e( ) ar e:
ou ar p e l ac i
ng t hi r s ect
$x
1c
o
r d—
T he co x
ordi
na
t o e f t he up
pe
r l ef t c o
r ne
r of t he r ec
t an
gl e.
$y
1c
o
r d—
T he co y
ordi
na
t o e f t he up
pe
r l ef t c o
r ne
r of t he r ec
t an
gl e.
$x
2c
o
r d—
T he co x
ordi
na
t e of t he l ow
r er
i gh
t co
r ne
r of t he r ec
t an
gl e.
$y
2c
o
r d—
T he co y
ordi
na
t e of t he l ow
r er
i gh
t co
r ne
r of t he r ec
t an
gl e.
an
gl e.
l o r o r u n f i l l e (us d
I e m a g e R e ct a n g l e ( )
$c
R ec
T he co
l of or
t he r ec
t a n gl e a s r p e l o t t e f d r o m u p pe
i n t he l ow
r er
T hi n s ex sp
ol or—
ec
i gh
t co
t sc r
r ne
i pt us
i sif a y
a ze
es l i ne
al dl y on
s, t ex
t , an
5 g d _g
us
t be a c o
l t or ha
e r r i g h t . R e m e m b e r t ha
e w he
d r ec
el f s t or he i m ag
t an
n pl ot t i ng i n m at he
gl es t o c r ea
e. T he grap
i l l u st r a t e s t h e g r a p h - e n t r s y c re
S cr i p t 1–
gl e. T hi m s
r l e f t t l o ow
r as ni s orm
nd l ab
t an
t e a dy
a h ut om
t ha b s e p n r ev
t t he co
sl a y l l oc
at ed t o t he $i m ag
o r d i n at e 0 , 0 st a r t a s t t h e up
p r er
m i b c gr ar l l ch y
ap
an
h. Y ou ca
ge sc a s
l d e ep
n pl ug va en
r i ou n s um
di ng on t he nu
eri va c m eri va c
n .
r ap
h . p hp
[ V i e w f u l lw i d t h ] 1 . < ? 2 . i f (! i s s e t ($ ren 3 .
? >
4 .
< f or m ac t
5 .
6 .
< br >< 13
i on t ext
, 10 ab
< br><
9 .
, S ep
< br>I
1 1 .
< br>V P r od uc t
s="4
st >
na
m a) :
m e=
" val
ue
s_i
m ag
" 40
er at ed by a c om
" r ow
s=
" 4" na >
D ec <
/ t ext
ar ea
t : < i np
ut t yp
e=
e W i dt h: < i np
e r t i ca i on Ti n oh
< br>H
1 3 .
< br >
ori
/ f orm <
" t ex
t " na
" l ab m e=
el s_
i n">Ja
i gh
t"
" he
ut t yp
e=
" t ex
t " na
t t yp
e=
l S c a l e L a be l : < i n pu usa dn s" >
zo
nt al S ca
ut t ype
l e La
be
="subm
l : < i np
ut t yp
m e=
" r en
i t " na
m e=
xp
2 1 . / * D et erm
l od
e ( " , " , $ va
i F ne
on
$sm
_f ont d_f
$l g_
0">
e= de
" t ex
t " na
r " val
ue
l ue
s_
($h d
in ) ;
e i g ht 4 > 0 0)
{
= 2; ont
= 3;
f on
$sm
t = 4;
_f ont d_f
$l g_
= 1; = 2;
ont f on
t = 2;
3 0 . } B e I ase
m age
3 2 . $i m ag I = e m ag 3 3 . / * A l l o ca t C e 3 4 . $w
hi t = e I m ag
3 5 . $b
l ue I = m ag
3 6 . I = $red 3 7 . / Fi * nd La
m ag
*/ r ea
t e( $w
i dt h, $h
ei gh
t);
o l o r */ s eC
ol or A l l oc a
eC eC
r ge
eC
ol orA ol orA
st I t em
l l oc l l oc
t e( $i m ag at e($i at e($i
m ag m ag
I n V al ue A s r r ay * /
e, 23
5, 23
e, 0, 0, 25 e, 25
5, 0, 0);
5, 23 5);
m e= ="R
2 6 . } e l se {
3 1 . / * C r eat
A pr,
l u e = " W i d ge
t S i ze * s /
2 2 . i f ( ( $ w i d t > h 4 0 an 0)
2 9 .
, M ar,
= " 50
2 0 . $ yo f f se $t = h e i g h t / 1 0 ;
$m
, 75
e l " va
1 9 . $ xo f f se $t = w i dt / h 1 0 ;
2 7 . 2 8 .
0, 20
l ue
1 8 . $ l a b e l = s e xp l o d e ( " , ", $ l a b e l s_ i n ) ;
$m
n, F eb
" w i dt h" va
>
1 7 . $ va l ue e = s
2 5 .
0, 15
" t e xt " n a m e = " vl ab
1 6 . } e l se {
2 4 .
, 10
, 23
,5
, 20
M ay
, Ju
n, Ju
0,
m a) :
m e=
< ?
2 3 .
n">50
> el s sep
l s=
po
at ed by a c om
" r ow
t are
t er l ab co
d=
s sep r
" 40
/ t ex
e H ei gh
1 2 .
1 5 .
3<
p m et ho
ber
0">
1 0 .
1 4 .
s=
t are
m ag
= " 50
r t . ph
ar ea c ol
, O c t , N ov,
< br>I val ue
cha er num
el s ( en
t ex
A ug
d_ ( ent
3, 16
< br >L
8 .
=g
al ues
5, 63
7 .
d e r) ) {
r >V
5) ;
i g ht co
e.
r n e r of t h i e m a g e, n ot
m at i c s.
na
at i c a
i ou
" hl ab en
de
el " va r C ha
l ue rt">
= " M on
t t h">
l,
l ue i s nt o t he graph l ue yo s
e u nt er.
an
d F i gu
re1
-8
3 8 . $g
r ea
t es
t0; =
3 9 . f o r ( $ i = 0 ; $ i < si ze o f ( $ va l u e s); $ i + + ) { 4 0 .
$ va
4 1 .
i f ( $ va
l u e s[$i
4 2 .
] = t r i m ( $ va
l u e s[$i
l u e s[$i
]);
] > $ g r e a t e st)
$ grea
t e st = $v
a l u es
[ $i ] ;
4 3 . } 4 4 . / * D et er m i S ne
c al
A e S nd
pa
ci */ ng
4 5 . $ sc a l = e ( $ h e i g h t / $ g r e a t e st ) * . 8 ; 4 6 . $ h _ sp a c i n = g f l o o r ( ( $ w i d t h - $ xo f f se t ) / si ze o f ( $ va l u e s) / 2 ; 4 7 . $b
ar w i dt = h $h
_sp
ac i
4 8 . / * D r aw B ar s, La 4 9 . $ = $x
xo
f f se
be
ng
;
l s, an V d
al ue
s* /
5t + ;
5 0 . f o r ( $ i = 0 ; $ i < si ze o f ( $ va l u e s); $ i + + ) { 5 1 . $ y = $ h e i g h t - ( $ va l u e s[ $ i ] * $ sc a l e ) ; 5 2 .
I m ag
+ $b
e F i l l e d R e ct a n gl e($i
a r w i d t h , $ h e i g h t - $ yo
5 3 .
I m ag
5 4 .
I m ag
5 6 .
$x+
i ] = t ri m ($l
e , $ sm
spa
_ f on
a b e l s[$
e S t r i ng ( $ i m ag =($h_
m a g e, $ x, $ y - $y
of f se
t , $x
t ,$ r e d ) ;
e S t r i ng ( $ i m ag
$ l a b e l s[$
5 5 .
f f se
t , $ x, $ y- $ yo
f f se
t - 1 2, $ va
l u es
[ $i ] , $ b l u e ) ;
i ] );
e , $ m d_
f o nt , $ x, $h
e i g h t-
$ yo
f f se
t + 2, $ l a b el s[ $ i ] , $b
lu e ) ;
ci ng * 2) ;
5 7 . } 5 8 . / * D et erm
i ne T i */ cks
5 9 . $ t i c ks
_ e ve
r " =y
6 0 . f o r ( $ i = 1 ; $ i(r < 6 1 .
1 ";
o u n d (l o g 1 0 ( $ g rea
$ t i c k s_
e ve
6 3 . / * D r aw Ti c ks
A N nd
t e st)
) ) ;$ i + + ){
r y . = " 0 ";
6 2 . } um
ber
*s /
6 4 . f o r ( $ i = 0 ; $ i < $ h e i g h t - $ yo f f se t ; $ i + = $ t i c k s_ e ve r y* $ 6 5 .
$ y = ( $ h e i g h t - $ yo
6 6 . 6 7 .
I m ag I m ag
e Li en e Li en
6 8 .
I m ag
e S t r i ng(
f f se
sc a l e ) {
t )-$ i ;
( $ i m a ge ( $ i m a ge
, $ xo , $ xo
$ i m ag
f f se f f se
e , $ sm
t / 2, $ y, $x of f se t , $y , $ b l u e ) ; t + 5 , $y , $ w i d t h + $x of f se t , $y , $ w hi t e); _ f on
t , $ xo
f f se
t / 2 , $y
f f se
t , $ h ei gh
i g h t - $y
of f se
, $ i / $ sc a
l e , $ bl ue
);
6 9 . } 7 0 . / * D r aw Lef
t and
B ot t om
E dg of e G r aph
*/
7 1 . I m ag
e L i n e($i
m a g + 0 e,
$ xo
f f se
t , 0 , $ xo
7 2 . I m ag
e L i n e($i
m a g e, 0 + $ xo
f f se
t , $ he
$ yo
f f se
be
7 4 . I m a g e S t r i n ($i g e S t r i ng
7 6 . / * D i sp l I ay 7 7 . he
ad
t , $ bl ue of f se
); t , $h
e i g h t-
l *s / m a g e , $ l g _ f o n t , $ w i d t / h 2 , $ h e i g h t - ( $ yo
U ($i p
m a g e, $ l g _ f on
t , 1 , $ he
i g h t - $h
f f se
t/2 ) ,$ h l a b e l ,$ b l u e ) ;
e i g h t / 3 , $ vl a be
l , $ bl u e);
m ag * / e
er ( " C on
7 8 . I m agePN 7 9 . I m age
f f se
t ,$ b l u e ) ;
7 3 . / * D r aw A xi La s 7 5 . I m ag
t - $ yo
t , $ w i d t + h $x
t en
t - t yp
G ( $i m age) D est
r oy(
$i m ag
e: i m ag
e/ pn
g")
;
; e) ;
8 0 . } 8 1 . ? >
F i g u r 1 e 1- 8. g d _g
r ap
h . p h p b ef o r e su
b m i t t i n g va
l u es
S cr i p t 1
- 5. g d _g
r ap
h . p h p L i n e- b y- L i n E e xp
L IN E
l an
at i o n
D E S C R IP T IO N
2
C he t ck se o
3–15
P r i nt out st a
i e f t he $rend an
dar
var er Hd
l i e se s
T M f L or m aski
T n he
um
er i c al
T he cor i np
i ab
r esp
ng f or som
val
di ng l ab ab
ov
T he w i dt a h nd he
i gh
17
18
T ake
t he val
$ va
l u e va s
T ake
cu
l ues
f or t he scr
ar gr ap
h, sep
el f s or t ho b se
t l e i ne 3– s
15
, el e se
i pt . Y ou c an
ar at ed c o a by
ar s, sep
xe
spec i
cu
t f e r om
l i ne 16 t t o he en o d f t he scr
i pt .
f y:
m m a.
ar at ed a by
c om
m a. Y ou sho
ul h d ave
on l e ab
el f or ea va c h
l ue you
e. t of t he ch
T he l a b el f s o r t h e sca T h s e cr i pt e nt e r so s
t , t he e n xe va e
ue f s or t b he
on
ut i n t he f orm
t . I f i t i no s
art
.
l e s.
m v e al u es a a s d ef a ul t f o r t e st i n g .
ue en s
t er ed f r om
t he f or m an t d ur t n hem
i nt a o a n r r u ay
si ng t he expl
t er ed f r om
t he f or m and
i nt o an ar r u ay
si ng t he expl
ode
( ) f un
c t i on an a d s i
gn
i ng t he ar r t ay t o he
r ia b le .
t he l ab
el en s
t ur n t hem
od
e( ) f un
ct i on and
as i
gn
i ng t he ar r t ay
o t he
$ l a b e lv s a r i a b l e . 19
D et erm
i ne t he of f se
t f t or he x- ax
i s, w hi ch i 1/ s
10
t h he t ot al w i dt o h f t he ch
art
l e f t si d e o f t h c e h a r t . 1 / 1 0 t i h a s n a r b i t r a r n y u m b e r t h a t w o r ks w e l l f o r c h 20
D et erm
i ne t he of f se
t h b e o t t o m o f t he ch 2
–3
0
D et erm sm
32 34
–3
6
C r eat
t e i base he
A l l oc
at e t hre
ch 38
art st an
I ni t i al it ze va he
n 40
pro i
at e f on
04 x 0
, t he
m usi age co ds ou
i s, w hi ch i 1/ s
10
t h he t ot al he
i gh
t al l ow
f s r or
t of t he ch
art
. T hi o s f f se
lws
t al l ow
o
m f som or
t e ex
t on t he
id e o rla r g e r . f s r or
o
m f som or
t e ex
t on
a rt.
i ne t he ap
al lt er ha
t f t or he y- ax
. T hi o s f f se
a r t t s h a t a r e 3 0 0 p i xe
l t ors
n us
t si ze f s t or he ch e sm
t ng w he o t he i m ag
al l f er on i dt and h
hei
e: w hi t e, bl ue
t be
t t f er r om
t he pa
ge
r i abl
$ e gr eat
est
w i t 0. h
.
art
. T he ch
t s. O t he ght
obt , an
art us
es t hre
r w i se
, us
e l f arge
ai f ned
r om
ft he
d r ed
. T he w hi t e he
si ze on
s: sm
al l , m ed
i um
, an
d l arge
. I f t he ch
art i s
t s.
or m . r e ( R B G : 23
5, 23
5, 23 i 5) a s c t ua
l l a y l i t t l e so grey
t ha
t he
L IN E 39
–4
D E S C R IP T IO N 3
U f a se
or l o t p l o o t p hr ou
p l o t t ed va
l ue
m as
i d er
46
t ba
D et er m i ne t he ho
r i zon
d f i na
57
ge t ha
C r eat
51
est
val
ue
. O nce
w kn e
e t he
i r va
ow
t he l ar ge
p tt r i m a s n w y
l u es w h e n t h e e y n t e r t he
st nu
hi t es
m i nt o t he f orm
pa
m be
r t ha
t ha t s b o e
ce f r o m t h n e u m e r i ca
w i t h sp
ac
l
es i n a d d i t i o n t o
t nu
t yo
cu
r c en
py 80 pe
a c e av
m be
t of t he l ar ge
st val
nt t of he he
i gh
r ce
i vi du
al ba
ue di vi de b d t y he he
i gh
t . T hi cr s
r by t w si o,
nc
r . H er w e se e
e w e w an
r i s n t he cha t o c r ea
t i t t o he sam co
un
r roun t by
t t h e ab
t a es
sc al
t e ha
t
di ng of f t he w i dt h m i nu t s he w i dt h of f set
t e an eq
a e t s he spa
t t ha
ea
t.
ai l a b l e t t o h b e a r s) , t h en d i vi d i n i g t b t y h n e u m b e r of va
u do a l t e r i t , t a ke i n t o ac
r i ab
l e $x t o be f i ve pi xe
u al l oc
at ed as sp
a e f or l o t p ha
t l op
D et erm
i ne t he ba co y se
ba
en
r d s ep
ng 80 pe
ua
ci ng
l sp
ac r e-bar
, bu
t you
( w hi ch
d t b o c e ha
r t e d,
at i o.
m f ay
o ve l i ne a l l o ca
l ue t s h at n e
i nd you
ne
t e h s al f o f t he sp
ed t a o l t er i b t a i t f or you
a c e t o sp
r
a ci n g . Y o u m ay ne
e d to
e ll.
I ni t i al i ze t he va
50–
nd f i nd t he hi gh
a r t . N o t t e h at , o l n i n 4 e 0 , t h e sc ri
ci ng f t or he i nd
t of sp
l ld y i vi di ng t ha
e c i f i c c h a r t . I f yo
ed
aki t o oc
t al spa o un
a l t e r t h a t l i n e a ws 49
r a ay
p ar t
r t by
D et er m i ne t he w i dt o h f t he ba sp
r se s
r on t he graph
g i ve u s t s h t e o t al am
47
o r i s f u se
o e f t he cha
t s he l arges
an
l ue ar s l o e f t he ch
.
D et er m i ne t he scal al l ow
gh t he $va
t e r m i ne t h s e ca
. T hi i s t s o a vo
c om 45
, w c e a n de
ac
t s hr oug ordi
ml s t ore
e f t or ex $ h val
na
ha
ues
ar r a ay
t o e f t he ba
di ng on t he si ze of t he grea
n t he of f se
t . T hi a s l l ow
yo s
u t o st art t he f i r st ba
t s he bar
t he gr bar
r f i ve pi xe
al s w ay f r om
t he
t. nd dr aw
r . T hi i s b a s
t es
t va
l ue
i t t r i c ky,
be
. T d o et erm
on s
ca
ap
us t e he scr
i ne t he ba
h.
i pt au
se c o y
t om
ordi
na
at i c a
l l sc a y
l t es
t e, yo n u e
he pres
d t s o ub
t r ac
nt at i on of t he t he he
i gh
t f r om
t h s e i ze o f t h v e al ue m ul t i p l i ed b t y eh sca l e. I f t h v e a l u w e a 1 s 0, t h en i t w o ul a d u t o m at i c a l l b y s e c a l ed d ow t n 8 o . Y o t u h e n su b t r a ct t h e o y f f se t ( f o r t he ex t r a sp a ce a t h e b o t t om f o r t e xt ) a dn t he o ve r a l l h e i g h t o f t he i m ag e ( b ec au se t he G D l i bray u se t s h top e sh
ou
bu 52
r n e r o f t h e i m a g e a t s h e 0 , 0 p o i n t i n st e a d o f t h e l o w e r l e f t c o t he T O P of t he i m ag
t he G D l i bra
C r ea
d y oe
t e t he ba
co r en o f t h rec 53
l e f t co
l d st art f r om
r usi
sn
ou
val
U t se
he t r i m ( ) f unct
5
W r i t e t he l ab el of t he cur l ab el t w p o i xel B s E LO
56
I ncr
em
en
he
r sh e
Cl os
59
I ni t i al i t ze var he –6
2
sam b l o c ks w an
$t e
he ba
b e t w e e t n i l ck
t a im ck
9
C r ea
i ne
t a e f l or o t p ha
t h e i n t e r va
ove
gl e( ) f un na
t he ba
c t i on
r usi
t ua
. T he f i r st t w c o o
t e argum
ve t he b i ar t se
en
ng t he I m ag l f . R e m em
l l b y (w e
r di na
t a e r gu
t ( s $x + $b
arw
i dt and h,
$h
eS
( ) f un
c t i on
t r i ng
b t er h a t h s e c r i pt c a
p t i c s a l cu
hi ch w ou
m en ei gh
t ( s $x, t – $y
. T he co y l cu
la t in g h o w f a rt h e b a r
l d, of c o
urse,
si er,
an $ d y) pl ot t he t op l ef t
of f se
r di na
be ea
t ) pl t ot he bo
t i e l s i st ed $ as
t t om
12 – y
r i gh
t
so
l a t e h s o w f a r f r o m t h t e o o p f t h e i m ag
e
w f f ar r o m t h e t o p of t h b e a r .
co x
f r om
ar ound
t he l abel
.
r di na d 47 i f yo
t so e
u w an
t hat
i t al l ow
r s om
f or am
t o m uc a k bo w ut
pl sp e
i t h t he sp
ac
ac e i ng
i gh
t – $yo
f f set
be
t w e t n he ba
. N ot e t ha
t i n m os
+ 2. T ha
r s. Y ou
t ca
t pu
ts h e
' l lha t ve m o
od
se t s he w ay i t ico s
if y
de
d
. i ne t he sca ou
n ce s. I t t ak
l o e f t he t i m ck
nd of t he i m ag
i va
ar e k ver
( n o t n e ce sa r i l p y i xe e t I c . t ' n s o t a n e xa sc i c t –6
an ordi
hi t espac
e ve
t va
ha
t oc
d e r aw
l h d a ve va
i t s. T hi f s l or o
es t h g e r e a t es
t arks
e. T he ar y
b l t e h at yo c u ou 1 y 0 un
t h a n $ i , i t a d d a s " 0 t " o t h e $ t i c k s_
64
r ab
i cks_evry
c kgr
. S i n ce i t ' co s t h o ave
).
r n e r ) . T h s e c ri
l d ac
p. i abl
l or t as
t w ay
ou
.
t a e f l or o t p d o et erm co e
do i t t ha
r sh
r en t ba r at t he bo t t om of t he ba r . N ot i ce t ha t he co y or di an t e $i s he W t he t op of t he w hi t esp ace al on t g eh bo t t om of t he i m ag e .
i ne
e t h e f or l o
C r ea
t ho
ue of t he next
l w d f ork
t o l you et R ec t
l a s bo
di t i on t o l i ne 4 s 6 an
ou
g t he ba
nd t w o co
i on t o r i m w any
t he val
5 7
60
, no
l on
i l l ed co
ue of t he ba
r i t t en
54
t hi l s i ne i n ad
eF
r i t t en 1 p 2 i xe
lb d w e
r t ha h n ow
t o w an
gl e. T he se
m er i c al
t h at t h v e a l ue i w s t h t e e xt sh
em
ng t he I m ag
r of t he r ec t an t a n g le .
W r i t t e he nu
' t se
e, r at he
ap w ay t o de
l u a e n c d o m pu
t dr aw
" s t i c k"
m ar on ks e ve
r y.
t he ba
r s, w as
r s. T he t i m ck
rts mo
ake
t er m i ne ho
t e t s he l o g 10 o f t h a t va l l y, i f t h e g r e a t e st va
l s, b ec au se yo n u e e t d t o a ke i n t a o c o un e n c e , b u t i t g i ve p s r e t t g y o o d r e su l t s.
l d e f i n e d i n $ t i c k s_
r on t he ba t he ba
ar arks
t he ba
el n l as
t sc a
um
r al s
sa
l ue
l l y i ne t s ha
qu
al l seg y
n d s, yo w u
w m an " y t i shou cks"
on t g he axi y
t are
he
m en
t ed
o ul n d o t a u t om l d be spa
c ed
a t i ca
lly
in
. E a c h t i m i e t d o es so a n t d h v e al u i e l s e s
l u e i 1 s t o 3 1 6 , t h e n t h e r e i a s l i n e e ve
l i n g). F r o m 3 1 t 6 3 o 16
be
a e c t ua
r l s o l k i e ke
l u es t h a t a r i e t n he t e ns o r i t n h t e h ou
p ai s che
r f y u n c t i o n . B a si c a
cu
o n ver
2 , i t u se t s i m c k
of s t he gr ap
h, spa
e arks
c ed
r 1 y 0 t i ck s ve
ac o
r 1 y 0 t i c ks
r di ng t o
,
L IN E
D E S C R IP T IO N
65
C al c ul
6
D r aw sh a d i sp
at t ecor y he
di nat
f e or t he
ed a l o n g t h e a y xi o s f t h e c h
D r aw l a on l g ia ne
68
D i spl
t ay
6 9
Cl os
e t h e f or l o
71
D r aw
t b he
l x- ue
axi
72
D r aw
t b he
l y- ue
axi
74
D i spl
t ay
he l ab
el f x- or
75
D i spl
ay t he l ab
7
S t end
i he
78
D i spl t ay i he
m age,
$i m age,
79
D est
r t oy i he
m f age
r om
80
C lt ose
i he
re1
- 9 sh
ow
ar k.
ort l i ne t t o he l ef t of t he of f se
l ay
67
F i gu
mi c k
c r t os
he " t i ck"
nu
m age
m be
ort bl ue l i ne i us s
ed a as
di vi de
r be
t w e t n he nu
m eri
ca
l sc a
l t e ha
t di o
vi t de b he
ar i s nt eq o
r t t o he l ef t of t he axi y
f s or t he cha
l s ia ne
c r t os
of t i he
l s ia ne
l on t g ri he
ua
leasi
l y- r ea
dab
l seg e
m ent
s.
rt.
p.
axi
ader
f st at em
m pl e ou
t om
ght
si o de f au
l t c ase
s. I n t he de
f au
t s t o us he
ent
he bot
s. I t n he de
el f t or he y- axi
m he age
e s xa
i he
t . T hi sh s a rt.
er br ' s t hat hav you
t ser he st ar l t on ed
t pu
f t he i m age
ow
se
m em
t w e t n b he
ar and s
t hei
w en
ni t nu
m be
( bet
, t hi i s " s M on l t c ase
cr e
ver
m ag ( e be
t u he
r l ab
el s) .
r and s
t b he
ar s) .
t h. "
, t hi i s " s W i dg
et P r od
uc t
i on i n T ho
usa
nd
s. "
r. eat
ed.
or y, si i nce
al thas
r be eady
sent en
t o br he
ow
ser
.
2.i ne
t f t or he scr
i pt .
F i g u r 1 e 1- 9. g d _g
r ap
h . p h p af t su er
b m i t t i n g va
l u es
ti s
T o p
C hap I T n hi C s
t er 12. ha
P H P G T K
pt er I nt r od I nst C r eat
uc t
i t on
Po
H P G T K
al l i ng P H P G T K i ng B asi
Gc
T K O bj ec t
s
P u t t i n g I t A l lT o g e t h e r A S i m pl P e H P G TK
A pl
i c at
i on
T o p
I n t r o d u ct i o n t o P H P G T K P H P G T K ia s n ex
t en
si on t o P H P t ha
t al l ow
yo s
u t o c r ea
t e grap
yo P ur H P a p l i c a t i o run n i s i n t o s w a n p l i ca t i o w n i nd T he f i l es i sn t ea d r es i de on t he us er' h s d ard r i ve . F use or ( w i t th h Ge
T K + ex
G T K + w o as st an f ds be
t e n si on
r i gi nal
) i n st a l l e o d t n h e i r sy
del y
si gn
or t he G I M P T o
p n or t ed t W o
i nd
ow
s, Li nu
x, and
es G T K + t o draw
bu
on o g t he
w i dg
s, am
sc a
et n s e t d b o c e on t t er d
r an
do
a p p l i ca W i dg
t i o n i s a s co et h s av
c i de t d u o G se m hus
c al
e ( G U I ) ap
pl i c a
t i on
s. I ns
t ea
d of r un
ni ng i n a brow
de on l y. T he y n, t he m y ust
l ed t he G I M P ( G N U I m ag M e ea
e f s g a or
U I ap
t an W y
am
T K t + cr o
ak
ui r ed i n an G y
art al m os
W i dg
et se s e t se
i dg
se
d o n o t r e si d o e t n h e h a ve t he pro ver er s
r,
W eb se r ve i o of n PH P
r.
i nd
pl i c a
ow
ap s
t t e he
i r de
skt
op en
o c d r o s -pl
t i on
. W i dg
pl i c a
vi r on
, su a c h
i ca
l . Y ou c a
pul
at i on P r og
t f or Li nu
r am
) .G T K
x. G T K h + as
at f o r m G U I l i b r ary.
et a s r e t hi ng l s i ke scr
t i on
ani
m en
Was
ol l ba
eb brow
se
t ha
ve b a un o c h
r s, t ex
r , yo a u r l e o
t i np f ut i el ds
, an
ki ng at co a
l l ec
d t i on of
ert
i es t ha
nd si gn
al t s yo o
t ha
op c o t are
a t are
ut om
ert
ur prog
r am
l l ba
r - d ef i ne h d a n d l e r s) . T h u e se
A o s f t he w r i t i ng o f t h i d s o cu P H P G T K 0. 5. 1 ai s vast r co y
s. C t heck
P he
at i c a
t ork
b o u e se l em
f ul an l d og
, w e us
e a sp
t f o r yo
u r ap
t hi n i k t b es
m pl ex. H P G TK
t co
l lh y an
on
ec
n' t j us
i al ki nd of w i dg p l i ca
et c a
t i o n. F o r e xa
l l ed a c o
f bu
nt ai ne
m p l e ,t h me
t t on a s nd t ex r . A co
nt ai ne
t f i el ds r ia s no
t he
r
e n b u a r at t h t e o o p f m o st
w t he l y o a k nd ac
i va
dl ed by G T K ( de
r r en
t ve
t ove
b s asi
nd cl as
se t s ha
W si eb
ta e
e w of
i dg has et
t ed
. A e n xa
m pl o e f w i dg
et ac
t i va
f au
l t ha
nd
A ca
i t o s w n un
l ers)
. O t he
r i t t e in Pn
H P .
l0. 1 r el ea pl et e l an
i l ab
l e, bu
h t t p : / / g t k.ph
t i on i w s
l l b a i c k b s a si c a r si gn
al e s nd up ex
r si on o f P H P G T K w a 0 s . 5. 1 , r e l e as
tl y w o com avt are
h t yp
a l w i t h c a al l b a c k.
t i o ns a r w e
r t he or i gi na c al
t . E ac
i qu
e se pr t of
op
ert
i es
,i n
et s.
d t t o h at si gn
r - d e f i n e f d u nc
m en
I t ake
nt r ol ho r w i dg
w he t n he act re y
m e n t , t h e cu
i m pr ove
et ho a ds
i es t ha
e r a l l r y e sp
( u se
t ai lt he m an m y
ew
l ve t hi p s r ob
m m on t o ot he
i n ca
P H P G T K vei s
n. T o so
n ta in e r .
n d a s si g n al , yo g u en c ks
t e yp o e f r am e
i d g et h s o w ev you er
e m an d y i f f pr ernt
di t i on t o pro
wa
al l ow
et r s" eq st u
t ai ne i d s n om
m la y bo t ut he scr
st r u ct u r t e h a t o r g a ni ze t s h w e
de
m ag e e di t i ng pr ogr m de
O S t ,and
s. W he yo n
ac
et s.
W i dg
ad
i ce
m t e ea
B e
t he " w i dg
r t hi ng
lus i er nt erf
te m .
n- sour
t er , t he G no
P H P G T K us t t on
ed f t or he ope
lK i t . La
hi ca
o w . T h e se a p p l i ca t i o sn a r c e l i e nt - si r t s o us e t he P H P G T K ap pl i ca t i o
ed o n A pri
he u a n
se
r c l i o c ks
l l j y u st a f u n c t i on ec
ut i ng on
l 2 6 , 2 0 0 W 2.
ban
ut t on
. S o m e si gn
e you of
r f un
c t i on
. O nc
e
a le s n u d p s
h i l e st i l l i n i t e s a r l s y t ag
e s,
se. gu
ag
es an
t I w i t sh p o r ov
d pu
t s he
i de g a en
p . n e t f o rw a
m t og eral
ov
et he ervi
r . T hi l s on ew
e cha
pt c an er
of P H P G T K i ns
of t as ar
ot ho
pe t o exp
hi sp s
ac
l ai n i n
e
e a l toh fi n f o r m a t i o n !
T o p
I n st al l i n P g
H P G T K
B ef or yo e
ng P H P G T K , you
ca u
st n
h t t p : / / g t k.ph
ar t usi
p . n e t . Th P e H P G TK
ne
W si eb
ed t d o ow
nl oad
t he ap
ow
nl a oads
d nd
d t has e
r opri
at f e i l es.
oc um
ent
T he P H P G T K t eam
at fi on
or t G he
TK
ext
has
ensi
set
up n a i W c e
eb si t a e t
on.
B ef o r Y e o u I n st al l P H P G T K st i l lha no s W e b se
r ve
r . I n f ac
a p p l i ca
t io n !
P H P G T K d ia s so
t r ea
che
t d he 1. ve 0
t , t h rea er
ev
l op
l l i y sn
er s' t a oy
m f e un w i t i h t , t r i y t ou
t , bu
r si on
' t a r e a so
t he m om
t do
n' t ba
, an a d suc h s
I w ou
n t h you at
en
' d w an
t , an a d nyt
se yo c om ur
pa
l dn
' t r ec o
t t o i ns
hi ng isub s
ny
' n s ex
m m en t d ha
t you
t al l P H P G T K o n yo
j ec t
t ch o
t bi p g r od
an
uc
ge
use
u r p r o du
, at l ea
st be
f or P e
t hi versi s
on of P H P on you
r pr od
c t i on W e b se
r ve
r . I t i a s c l i en
H P G T K r ea
che
versi s
uc t
i on
t - si de
on 1. 0. H ave
t on P H P G T K 0. 5. 0.
I n st al l i n g o n W i n d o w s I ns
t al l i ng P H P G T K on a W i nd
W i nd
ow
bi s
nar
f y i lf e r om
ow
t P he
ms
ac
hi ne i f s ai r l st y
H P G T K W si eb
U n zi p t h e f i l e u si n g a zi p u t i l i t s y u c h a W s T h f e o l l ow
i n f g ol de
ph
p4
t est
vi ew
— C on
l so e
t ai t ns
— C on
ow
ul c opy d ab
t you
98 s
c an
m sa e
W or
i nd
ow
c ut
t ou
t t he i ns
t al l at i on
ab
m pl * . e
Ms
l e, w as
nd si m i l t ar o i ns
t al l i ng t he no
r m al ve
r si on of P H P . D ow
F i gu
r e 12
d t he
e c rea n
t ed
t e m f i l t es
bo e
r e t o f i r st ba u c k
p yo
.
ph f p i l t es
E , t he yo n
ha
wu
se
t he ne
c es a
rD y
t use
i l lno
, t yp
L f i l t es c o o
p hp
e t he f ol l ow
i ng f r om
T K l i br ar f y i l es.
t he G T K w i dg
t i t ce
ha
: \ w i n do
t py
. i n f i i lC e.
a co
m Ge
he
m ove
t f ol de
d prom
r ca s
.
l l ed " w i n
t " an "w d
in
w d s i r e c t o r y. N o t t e h at yo m u r tC o
op t y hi t s o yo C ur
m m an
et set
: \ w i nd : \ W i nd
ow
t / sy t
em
- 1 f o r a sc r e e n sh
r 12- e
1. g t k. ph
ow
o s r C : \ W I N N T di r ec
t ory.
pt :
p i n Li nu ( x G no
" ha b ve u r sy
.
s.
o t o f t h e g t k. p h p f i l e i n a c t i o n .
F i gu
32
a h y av t e s o e t yo
c : \ p h p 4 \ p h p . e xe - q c : \ t e st \ g t k. p h p Se
nl oa
p .n e t .
u r C : d r i ve
el so las
n t e n t o s f t h os f e o l d e r i s nt y o o C ur
A d i t i on al l y, yo s u oh ul s d e n a ew e xi sti n g p h p . i n i fi l e . T o t es
a ard
h t t p : / / g t k.ph
i n Z i p . E xt r a c t t h e f i l e t s o yo
he P H P ex
t ai so ns
t he co t ha
t f orw
r a s r c e r e a t ed w he y n o u u n zi t p he f i l e:
I f yo a u r u e si ng W i nd Y sho ou
r ai gh
ta e
m e) an
d W i nd
o w 20 s
B e su
ur
In s ta llin g o n L in u x I ns t al l i ng P H P G T K on Li un i x ea s si er t ha i n ns t al l i ng t he no co m pi l e G T K f un ct i on al i t i y tn o an ex i st i ng st an da l on e ve ne
w P H P ex
ec
1 .
2 . O nc y e ou ha t a - r zx p vf T hi cr s
c an c r ea . / co
t a es
pi l P e r ec o
l t e ha
t ha G s
D ow
nl oa t d he sou
D ow
nl oad
ve t he ne
h p - 4 . x. ea
C om
ut ab
ne H P us
t he sour ce
sa
n f ig u r e
c t i on
al i t b y ui l t i n. B ef yo ore
r f ce
i l f e or P H P f r om
f ce
i P l e H P G TK
f r om
zi a p nd un
t t ar he r eg
r f y i l e, un
t he do
b u eg
i n:
w nl oa p d ag a e t
t he dow
nl oad
ul P ar
n
page
w w w . ph.
of
H P so f urc e
net
.
h t t p : / / g t k.ph
p .n e t .
i l e:
ta r.g z w di r ec t
or na y
m ed ph
i ng t he m i ni m um
m pi l e at er . F or no t ed P H P so di urc e
T K f un
r m al P H P ; yo d u on ' t ha t ve w o or ab y ou t co m pi l i ng w i t A h pa ch e. Y ou ca r si on of P H P , bu t f ou or r pu r po se w s e' l lst art f r om scr at ch an d m ak e a brand
r ec
op
w , you
j ust
t ory.
C om
p- 4. x. x, w he t i on
s. W j e us
w an
tmo
pi l b e t y yp
r t e he " x" de t w an
ake
sur i ng
t c rea o yo e
:
no
t t es
t a e st an ca u
c reat n
he exa
c t ver
da
l on e e xe
a e w or ki ng ver
si on nu
m be
cu
l e. I f yo w u
t ab
r of P H P t ha an
t you
t a o d ad
si on of P H P G T K . C ha
do
w nl oa di t i on
ng d e i r ect
de al f un
or i y nt yo o
d. c t i on
al i t y, yo
new ur
ly
u
T h at a' s l l t h e r e it s o i t . T h i s au
t o m a t i ca
l lc y r ea
t e a s n e xe
O n c e yo
r f y i l e , yo
u m u st c o
p i y t t o / u sr/
on on
ur P H P ex c u
ne
u h av
e t h e p h p b i na
ed t o be r o
c p p h p / u sr/ N ow
cu
t ab l o ca
l e t h ha at
s bu
i l t - i n M yS
Q L su
p po
r t as w e l l .
l / b i n . T he P H P G T K i n st a l l a t i o n w i l l b e l o ok
i n g f o r i t i n t h l at o c a
t i o n .Y o u
t o do t hi s. l o ca
l/ b in
, i t t' s i m t e b o ui tl d he G T K ext
ensi
t yo o
t abl
e. G b o t ac k
wo
her
yo e
d u ow
nl oad
ed t he P H P G T K sour
f ce
i al e nd
e x t ra c i t t : t a - r zx ph vf
p - g t k-0
T h i c rea s
t e nas
.5 .0 .ta r.g z
e w d i r ec
r o t ot o p e r f o r m t h e f i na eac
c om h
m and)
t o r n y a m e p d h p - g t k- 0 . 5. 0 . C h a ng d e i r e ct o r i y n t t o h a t d i r ec l st e p , m a ke i n st a l l . T o c o
m p i l e P H P G T K , t yp
t an ory
e t he f ol l o w i n g ( a t l of ot
c d o m p i l t e h s e ou
r c e f i l e . Y ou w i l l n e t d b o e
e xt w i l l p r i n t t o t h e sc re
n a f t e you r
t yp
e
:
1 .
. / co
m p ile
2 .
m ak
e
3 .
m ak
e i ns
Y o c u an t e st yo i ur ns
t al l t al l a t i o n by g o i n i g n t o t h t e e st di r e ct o r a y nd r u n
i ng f a e w of t h s e cri
p t s. X - W i n d ow
ws
i l l n e ed t b o e r un
n in g !
c d t e st ph gt -q p A w i nd F i gu
k. ph ow r e 12
sh
p ou
- 1 sh
l p d op up sh ow
ow
i ng va
r i ou G s
t s he gt k. ph f p i l a e i s t ap
Y o u ca
n a l so t r run y
sc re
n ( t he p hp " q u i e t op "
n i n g t h e o t h * er t i on
. ph
T K w i dg pe i ars
et bu
t t on
L n i nu ( x us
s. C l i t c k i ng t he G no
he di f f ernt m d e es
p f i l e i s n t h e t e st d i r e ct o r y. U se t he - q f l a g t o su
w i dg kt op p
et t s g o et b a r i ef i de o a f w ha ) on t he l ef t an i d W n r e ps
i nd
r i nt i ng H T T P h ea
ow
t he d y o.
2 s 0 o 0 t n he r i gh d i er n f orm
t.
a tio n to th e
).
T o p
C r eat
i n g B asi
T he G T K e + xt ensi G T K + l i bra PH .
on ian s
obj
y. I f yo h u av
C r eat
en
an m d
c r c an
eat
a n f y l a vo se o d pe od
ec t
or i ent
ed pr og
r am
on so e
, yo m u
an e
P y H P G T K ap
pl i c at
r o s f U N I X , t h at l e a ve u s w s i f i ca
s
t i on
em
u s se . so l i bra
, yo
u m us
an
W i nd i ons,
m you
H P .Y ou ne
t d u o O se
O P synt
ac t k o
ust
t el lP H P w hi G ch
f l i bra i
e s. W i n d ow t yo ap ur
na
d l of oa
m im c
si on t P o
a ax
C ha
nd st r uct
ur t es u o t se
pt er 1 an
r d evi
ew
he
t he m at er i al ab
ou
tO O P i n
ow
. S i nc y e ou w an
de a dy
en
t g o a o l l t he w b ay
i t t h w t o yp o es i es
t provi
m i ng ( O O P ) ext w ay
r Fi r st P H P G TK
r at i ng syt
w i t ho m ut
T K O b j ect
' t al r ea d dy
i ng Y ou
B ef or you e ba
Gc
et ho
pl i c a
T K l i br ar w you y u s se d s yn
ant
t use o
a m i l c i l nk
. S i G nce
i b r a r i es
T K r o uns , a l so c a
t i on t b o a e bl t e b o u e se o d b n ot t h yp o es
di ng t he l i bra
da
r d m et ho
Wn
l l e Dd f op
erat
d doi of
i nd
ow
i ng syt
i es
. T he st an
p po
r t f o r t h e se ot h e r pl a t f o r m i s a s d d ed
s
L L s. M o st *ni
x
em
s
ng t hi i s s:
i f (! c l a s s _ e x i s t s (' g t k ' ) { i f ( st r t o u p
e r ( su
b st r ( P H P _ O S , 0 , 3 ) ) = = ' W I N ' )
l d(' p h p _ g t k . d l l ' ); e l se d l (' p h p _ g t k.so
' );
}
S id Ne I f yo
o te
u i n t en
d f o r yo
i l n at er ver
u r sc ri
p t t o r u n o n pl a t f o r m o s t h e r t ha
si on of s P H P G T K ) , t he yo n
mu
ust
en
sur
n Li nu o x r W i nd
t e ha
t he pr op
o w (i s f su
er P H P G T K l i br ar i y l s oa
de u d si ng t he sam
me
an
ai w n
i nd
ne
r as
above.
T he cor co
p e ar t of an P y H P G T K ap
nt ai ne
Th ba e $w
r i nt o w hi ch yo
si w c i ndow
N ow
t ha
w i n do
i ndow
c l i as
& = new
G t kW
t you
ha a ve
w by c l i c ki
u pl ac
pl i c at
P n H P G TK i ndow
w i nd
i on it s he m ai w n
e yo ot ur
he
r w i dg
Gi s
t kW
i nd
i ndow
al a s r e ge
yo n u e t d c o on
ow
ca
r al ul y se ne
, you
m ust
pr ovi
" i t n h u e p p r er
de f or w a t ay d o est
i g h t co
r n e r o ft h w e
ct t he si gn
r i np
ut , an al t t o he ca
d ca
l l ba l l ba
c ks c k.
l l b a ck :
$ w i n d o w - > co
ap
pl i c at
i on you
w i ndow
obj
c r ea
t sh e
ou
l h d ave
ma
ow
t ha
t ac t a as s
a e new
ec
t l i k e th i s :
();
n t g h "X e
ne
. E ac h
( ) . Y ou c r eat
W eh n yo u cl i t ck eh " X " i n P a H P G T K ap pl i ca t i on , t w o si gn F o r no w w e ' l l j u st co cn en t r a t o e t n h d e e st r o si y g an l . S i gn
ow
et s.
n n e c t ( ' d e st r o y' , ' d e st r o y' ) ;
f are
un
i nd
r t oy
ha
t w i nd
o w ( so
al a s r e se
ct i on t s ha
ow
.I m n
ost
m L e i nu d x e skt nt t o t he ap
t yo
T d o t o hi s, yo u u se t he co
pl i c a
op
er at i ng syt
o p p s r ov t i on
. T he
se si gn
u c r ea
t e t o do so
m et hi ng i n r es
n
t ( ) m et ho
d.
ec
em
s, u a ser
i d a e d i f f er n
t co
c an
al a s r d e el et e_
po
ns
de
st r a oy
nt r o l ) . ev
en
t an d d es
e t o t he us i er np T
co o
n
ut . H ow ec t
th
t r oy
ev
.
er,
e d e st r o si y
g n a lt o
o u r d e st r o y
T he f i r st argum yo
en
u w a t nt o ca
t i t s he na
l l i n r es
f u n c ti o n d e str
po
m o e f t he si gn
n se t o t he si g na
al t ha
t i se s
l . T o ke
nt P by
H P G T K . T he se
co
nd argum
en
t i t s he na
ep t hi n gs si m pl e , w e ' l l n a m e t h e f u n ct i on ( ca
m o e f t he f un
l l b ac ' k) de
c t i on ( c a
l l ba
c k)
t ha
t
st r o y' .
o y() {
G t k: : m a i n _ q u i t ( ) ; } T h e G t k: : m ai n_ N ow
q u i t ( ) ; i s t h e P H P G T K f un
w cr have e
eat w a ed
P H P G T K r equ
i r t es
$w
i nd
ow
- > sh
F i na
l l y, yo
u ne
G t k:
m a i n ( );
S id Ne
an
ow
_a
or t e hi ngs
d pr ovi
t b o d e one
t ki l l s t h e ap
de
p l i ca
t i o n.
d a m e a ns f o r t h e u se
. F i r st , w n e e d
t sh o
ow
r t o g e t r i d t of h e w i n d ow
t he w i ndo
w . Y ou show
wa
. B u t w e st i l l c a
i nd
ow c a by
n ' t r un t he a p
l l i ng t he show
_a
l i ca
t io n .
l l ( ) m et hod
:
ll( ) ;
ed t o st art t he ev
en
t se
qu
en
c e ( po
l l i ng ev
en
t s?
) by c a
l l i ng t he sp
ec
i al P H P G T K f un
ct i on m ai n()
:
o te
Y ou m ust
be
gi yo n
ur sc r
P H P G T K t o j ust
W he
i ndow w mo
ct i on t ha
n w e pu
ec h
t i t al l t og
S cr i p t 12
i pt w s
t o he en
et he
r , yo
- b 1 asi
i t t h he f ul l" t i r e sc r
u ge
c_w
ph
p" t ag w he u n si ng P H P G T K . U si ng t he sho
i pt t o t he scr
t
e
S c ri
n i nst
ea o d f c r ea
p t1 2 - 1
, ba
t i ng a G T K w i nd
si c_w
i nd
ow
. ph
ow
r t ha
nd "
" m c a ay
use
.
p.
in d o w .p h p
1 .
i f ( st r t ou
4 .
p p er(
su
bs
t r ( P H P _O
S ,0 ,3 ) ) = = ' W I N ' )
d l (' p h p _ g t k . d l l ' );
5 .
e l se
6 .
d l (' p h p _ g t k . s o ' );
7 . } 8 . f u n ct i o d n e st r o y() 9 .
{
G t k: : m a i n _ q u i t ( ) ;
1 0 . } 1 1 . $w
i ndow
& = new
G t kW
i ndow
();
1 2 . $ w i n d o w - > c o n n e c t ( ' d e st r o y' , ' d e st r o y' ) ; 1 3 . $ w i nd
ow
- > sho
w _a
ll( ) ;
1 4 . G t k: : m a i n ( ) ; 1 5 . ? > R un t he scr ph T h res
if pt r om
- b q asi
c_w u l t sh
t he co i ndo
m m an
d l i ne ( r em
em
be
r , yo
u ne
ed t o ad
-2
. Y ou c a
d t he f ul lpa
t h t o t he P H P ex
ec
ut ab
l e i f i t ni s i ot n t he cu
r r en
t di r ec
w . ph
o u l l d o o si k
m ila rt o
F i gu
r e 12
n c l os
F i g u r 12 e
e t he w i nd
- 2. b as
ow
by c l i c ki
ng t he " X i " n t he up
i c_w
in d o w .p h p
pe
r r i gh
t co
r ne
r.
t ory)
:
S cr i p t 12
- 1. b as
i c_
w i n d o w . p h p L i n e- b y- L i n E e xp
L IN E I f t he G T K cl ha as no C t heck
f he
4
I fi W t i s
I N ,t hen
5–7
I ftP he
H P _O
10
no s
syt he
em
S envi
, t hen
D ef i ne f a un
c t i on
9
E xec ut
t e G he
10
E t nd f he
unct
1
C r eat ne a e
12
C on
ne
w he
n t he us cl er
13
I su
t e he sh
14
C al tlG he
ng G a
ac t
er of s t P he
r i s uni
W ng
r onm
l i br ar y.
p r i n t i n g o u t "H
d n ef i ned
i r st t hr char e
P H P G TK
T eh si m pl es ge t t he progam
t be
ex c u
t l e i3 nes
–7.
I f t he G T K cl ha as
be s
en de
f i ned
, t hen
t he scr
i pt ne t eds
do o
t h i n g.
3
A di
at i o n
D E S C R IP T IO N
2
8–
l an
, de
ent
st r oy
ar at i on.
w w obij ndow
ec
ow
st r m oy i t c ks _a
tca
c t i on c a
var
i abl
H P G TK
W I N , t hen
as um
e.
l i br ar f y or W i ndow
t e hat
i pt w he c n al l ed
st o t op scr he
l $wli ed
ent
P he
t st op t s he scr
P H P ri s uni
s. o ng
a n Li syt nux
em
l oad
t he Li nux
.
i pt cl and
t ose
G he
TK
w i ndow
.
ow
t o he de
st r oy(
t of t he w i nd
l l t t o he $w
tr o un t he scr
i nd
ow
ow ob
) f un
ct i on t ha
t you
de
f i ne e d ar l i er . T he de
st r m oy
et ho i d cal s
l ed
. j ec
t so
ha
t ev
eryt
hi ng w i t hi t n he ob
j ec
t id s
sp
l ay
ed
.
i pt .
B ut t on
t an m d os t ba si ex c am t o pri tn ou t he w "H ords
pl i e a n l l of prog el l o, W orl
r am m i ng i t s eh H el l W o d! " W e g are oi gn t o en ah
orl e d xa nc o e H ur
m pl e. T he go al of t he ex am el l o W orl d prog am sl i gh
e l l o W o r l d , " l e t ' a s d d t h a t t e xt t o a b u t t o n . W h e n t h e b u t t o n i c s l i c k e d , w e ' l l c l o se o u r a p p l i c a
l o o k a t t h e b r i e f l i n e -by
and
ndow.
et ho o d f t he w i nd
t k: : m ai n( ) m et hod
TK
i e not s
he " X " on t he t op r i gh l l ( ) f un
r onm
s. t Load
ui t ( ) m et t hod
decli on
S envi
i ndow i abl
( ) , t ha
t k: : m ai n_q
ct t he de
var
H P _O
- l i n e e xp
S c r i p t1 2 - 2 h e l l o . p h p
l a n a t i o n f o de r
t a i l s.
F i gu
r e 12
- 3 sho
w t s he ou
t pu
t of t he scr
pl e, i f yo d u i dn ' t kn ow , i t s o t l y. I ns t ea d of m erl y t i o n . T r o y u t t h i e s xa
i pt i L n i nu an x
id Wn
i nd
m p l e ,t h e n ow
s.
1 .
i f ( st r t ou
4 . 5 .
p p er(
su
bs
t r ( P H P _O
S ,0 ,3 ) ) = = ' W I N ' )
d l (' p h p _ g t k . d l l ' ); e l se
6 .
d l (' p h p _ g t k . s o ' );
7 . } 8 . f u n ct i o d n e st r o y() { 9 .
G t k: : m a i n _ q u i t ( ) ;
1 0 . } 1 1 . fu
n cti o n h e l l o () {
12.
gl oba
13. 14.
p r i n t "H e l l o W o r l d ! \ n "; $w i nd ow - > de st r oy( ) ;
l$w
i ndo
w ;
1 5 . } 1 6 . $w
i ndow
& = new
G t kW
i ndow
();
1 7 . $ w i n d o w - > c o n n e c t ( ' d e st r o y' , ' d e st r o y' ) ; 1 8 . $b
ut t on = & ne
1 9 . $ b u t t o n ->c 2 0 . $w
i nd
2 1 . $ w i nd
ow
w G t kB
- > ad ow
ut t on
( ' H el l W o
o n n e c t (' c l i c ke - > sho
d( $b w _a
ut t on
orl
d! ' ) ;
d ' , ' h e l l o ' ); );
ll( ) ;
2 2 . G t k: : m a i n ( ) ; 2 3 . ? >
F i g u r 12- e
3. h el l o . p h i p L n i n u ( x G n o m e) an W d
in d o w s
S cri
p t 12
- 2. h el l o . p h p L i n e- b y- L i n e E xp
L IN E 2
I f t G he
T K cl ha as
do no
t hi ng
3
C t heck
f he
i r st t hr char e
4
I fi Wti s
I N ,t hen
sy he
5–7
I f t P he
H P _O
S envi
8–
10
l i br ar y.
D ef i ne a f un
c t i on
t e G he
10
E t nd f he
unc
– 1 4
12
A l l ow
i ndow
13
P r i nt t he
14
U t se dest he
15
E t nd f he
16
C r eat ne a e
17
C on
ne
w he
n t he us cl er
t$w he ext
unc
21
I s ue
2
C al Gtl he
M od
i f yi ng B asi
T eh syn ( bu t t on
t f ax c r or s, w i nd
$w
i nd
ow
T hi w s i ndo
ou
var
S envi
i ndow i abl
, t ha
–7.
r onm
s. t Load
i e not s
I f t G he
ent
P he
t pri
as um
i pt w he
var
t ewa
be s
de n
f i ne
d, t hen
t scr he
i pt ne
t ds
o
l ed
i pt cl and
n t t s he t ex
or l d! " t S o TD
l i br ar f y or W i ndow
s.
P H P ri s uni
o ng L a n
siyt nux
em
and
l oad
t L he
i nux
st r oy'
m et ho
. t ose
G he
TK
w i ndow
m and
l fi ne
r om
w hi excut you ch
w he
i ndow
st r oy(
) f un
.
t " H el l o W o r l d ! " hi f s unct
O U T ( t sam he
$w he
i ndow
w obj
ec
st r oy'
ct al $ l ed
i on. c om e
obj
ec t
m et ho
w i ndo
t c l o t ose
t ed scr he
i pt ) .
.
w .
d of t he w i nd
ow
he " X " on t he t op r i gh
t obj on
ec t
c al
$blut ed
m et hod i ndow
usi
w _a
l l ( ) f un
c t i on c al
Wc
ow
r i p t , yo
t on t o he he
t ng ad( he
l l o( ) f un
c t i on
i nd
me
al l est
et ho
ds.
i g h t ) m e t h od
ef au
( 20
i ze t ha
0, 20
t i 2 s 0 pi xe
f i ne
d ea
r l i er . T he ' de
d cia s
ow
ob
j ec t
so t ha
t ev
r yt hi ng w i t hi n t he ob
ar an
di s i spl
aye
d.
ce ca am
si ze po
F exam or
si
bl e w he
pl e, i f you
w an
n c r ea t ed t se o
us t e eh bo are y pl e, t eh co a ll—
t cl h n
d t a ef au
m od l t si f ze
:
l b s 2 y 0 pi xe
l s. Y ou c a a n l so se w t a
i nd
ec
as se of s G a t ( ) m et oh d .
T K w i dg
i n f a ct , i t i o s n l a y s b i g a the s
t i ng i t . W e can
0);
t _t i t l e( " M P y H P G T K A P P " ) ;
j ec t
i pt .
et A p pe
t o t he sm
de
.
u w i l l n o t i c e t h a t t h e w i n d o w si ze i p s r e t t y sm ow
t you
) m et hod. lt o t he $w
( $ w i d t h , $ he l t _s
ct i on t ha
.
t on.
r o t un scr he
i dg
t o he de
t of t he w i nd
of t he but
t on t o w he
ow
e.
l ar at i on.
si ng som
i nd
i abl
t e hat
n c al
st o t op scr he
t by ed
) m et t on hod
t he w i nd
et u by
t _d
T K cl ha as
H P G TK
W I N , t hen
t s op t s he scr
t ( ) m et t hod
t k: : m ai n( ) m et t hod
i nks
l t _ si ze
w - >se
t l e i 3 nes
t i ng bu t t on an s w d i nd ow l s o ve ks r si y m i l ar. T ah t i be s s, et c. ) ha ce s r t ai m n et oh a ds va i l ab l t e t o eh m — f or ex
w i dg
l c d r ea
ex c u
H P _O
ec t ac es t be o
t he ' cl i cked'
t he sho
ow
- > se
ent
obj
but
ec t
se P H P shr e f au
r onm
l l o ( ) , t ha
i t c ks
u r u n t h e h e l l o . p h p sc
t _d
W ng
, he
ct t he ' de
A t d but he
se
ri s uni
st r oy()
w w i ndo
20
ow
t em
t deci on
C on
i nd
er of s tP he
, de
r oy(
19
G t kW
d, t hen
ac t
" H el Wl o
C r eat new a e
c au
f i ne
l ar at i on.
c t i on
be
de n
t k: : m ai n_qui
D e f i n a e f un
ea
be
t deci on
18
$w
not s
P H P G TK
E xec ut
I f yo
at i o n
.
9
1
l an
D E S C R IP T IO N
ow
t i t l e:
i f t y he de or t he w i nd
f au
b u t t o n i n si d e i t . T h a t ' s l t ap
ow
et . E ac o h bj ec t
pe , you
ar an c ou
ce of t he lu d t se
he
l l ed
F i gu
r e 12
- 4 sh
ow
a s w i nd
ow
m od
F i g ur 12- e
T he
rae rme
an m y
h t t p : / / g t k.ph
T ex
tE n t r y
A d es
kt o p a p pl i c a
l i n e o f t e t xt o yo $t ex
t = 1 & ne
A t e xt en $l ab
ad
t ha
ve ou
l t e ha
ef au
w m od
t c an
af f ec t
se m et ho
l d n ' t b e t o o u se t i o n . T o c re
t _d
( ) an s d et _t i t l e() m et ho
pe
ar an a c e
nd be
er t m y
ha
ds
.
et ho
ds ( L i n a ux
vi or of G T K w i dg
et s. S e t he do
n Wd
c um
i n do
en
w s)
t at i on on
.
f u l i f yo
a t e a t e en xt
i ze
i f i ed w i t p h r op
t he ap ds
l t _s
u co
ul d n' t i n se
r t da
t a i n t o i t . G T K p r o vi de a s t ex
te n t r w y
i d g t et h al at
l ow
y s ou t o i np
u ta
t r fi y e l d :
nt r y( ) ; ' t r e a l l u y se
w G t kL
t w e ha
l ab
t ai l o s t n he
t i on w ou
t r f y i el i d sn
d() m ul t i pl e w i dg
4. W i n do
vai
u r a p p l i ca w G t kE
el 1 = & ne
N ow
et ho a ds
p . n e t f de or
i f i ed by t he se
ab r ne
f u lu n l e y s
el ( " A T ex w t ex
t en
ou ha
m we
a t y l o ab
e l i t . T h at ' w s
he
r t e he G t kL
a be
l co
ow
. T he
r e' a s sl i gh
t probl
m e i s h n an
d y:
t E nt r F y i el d: " ) ; t r f y i el d an
et i s nt o t he t op
ve so
- l ev
d a l ab
el w i nd
el , w e ne ow
. I ns
ed t o pu
t ea you d,
t i t i nt o ou pl ac
r w i nd
e a bo i x nt o t he w i nd
ow
, an
d ad
em d yo sub ur
, t ho
ug
h. Y ou j us
t ca
n' t
ob
j ec
t i s nt o t ha
t bo
x.
vbox and hbox T he
r a e r t e w t o yp o es
t he vb vb
o (vert x
i ca
o a x l l o w yo s
f bo
xe t s ha
l ) . A t s h e ina r p to u
t yo c a u
n t a l l ( y l i ke n o r m a l a p p l i c a
& = $box
new i ndow
G t kH - >a
d($box);
ur w i dg
et i s p n l ac w e u t o pl ac
B ox(
);
t i o n d s o ) , w e ' l l c rea
i t hi t n he m ai w n
e o b j e ct i s nt o i t so t ha
l a c e o b j e c t i s n t o i t so t h a t t h o e b j e c t a s r a e l i g n e d ve
h o r i zo box:
$w
u n t se h o ol yo d
m e i s m p l y, t h e h bo a x l l o w s yo
r t i ca
i nd t t he ob
ow
. T he t are y j ec
t s are
he hb (hori ox a l i gn
e d h o r i zo
zo
nt al ) an n t a l l y, an
l l y. S i n c e w e w a n t t a o l i g n o u r t e xt e n t r f y i e l d a n d l a b e l
t a e h n b o a x n a d d i d t t o u r w i n d o w , t h e p n a t ck
h l e a b e l a n t d e xt e n t r f y i e l i d n t the o
d d th e
T he hb a ox
nd vbo
wx
i dg
et spe are s
c i al c on
t ai ne
r i s nt w o
hi yo ch
ca u
a n d m ul t i pl w e
i dg
et s. T a o d t he
m , you
ne
ed t p o ac k
t he w i dg
et s
i n t o t h e b o x: $ b o x->p
a ck _ st a r t ( $ l a b e l 1 f , a l se f , a l se 0); ,
$ b o x->p
a ck _ st a r t ( $ t e xt 1 , f a l se f , a l se 0); ,
pack_str T he pa
c k_
st art m et ho a d l l ow
yo s
t u a o d t he w i dg
et i s nt t o he bo
x. I f yo a u r p e ac
ki ng w i dg
et i s nt v o bo
x, t he p n ac
k_
st art ad
ds t he w i dg
et s
f r om t he t op of t he bo x. E ach t i m yo e p u a ack on t he r w i dg et i nt t o he bo x, t he pr ec di ng w i dg et i m s ove d d ow a n dn t he en w lad y de d w i d ge t i a s t t eh t op o f t h v e b ox . I f yo a u r p e a cki n w g i dg e t i s n t a o h n b o x, t he p n a ck_ st a r t a d t s h w e i dg e t i s n t t o h b e o f x r o m t h l e ef t . E a c h t i m y e o p u a a ck T he pa
n e w w i d g et i nt t o he b ox
ck_st
ar t ( ) m et ho
T he ob
d t ake
j ec t
f s ou
you
f au
r ar gu
ar p e ac ki
W h et h e rno or
T he de
, i t i p s l a ce t d t o he r i gh
t t o e xp
ng an
m en
d t h e ob
j ec
t i f t h e bo i x resi s
T he am
i ng t o use
ar ou
ne sp are
ec
l t argum
en
t u s se
d
d, i f no
nd t he ob
i f i ed
t , are
j ec t
r ue
outp .
n tr y .p h p
1 .
i f (! c l a s s _ e x i s t s (' g t k ' ) {
3 .
i f ( st r t ou
4 . 5 .
p p er(
su
bs
t r ( P H P _O
S ,0 ,3 ) ) = = ' W I N ' )
d l (' p h p _ g t k . d l l ' ); e l se
6 .
d l (' p h p _ g t k . s o ' );
7 . } 8 . f u n ct i o d n e st r o y() 9 .
{
G t k: : m a i n _ q u i t ( ) ;
1 0 . } 1 1 . $w
i ndow
& = new
G t kW
i ndow
();
1 2 . $ w i n d o w - > c o n n e c t ( ' d e st r o y' , ' d e st r o y' ) ; 1 3 . $t ext & = 1 en w G t kE tn r y( ) ; 1 4 . $l ab el & = 1 en w G t kL ab el ( " A T ex t E nt r F y i el d") 1 5 . = $box 1 6 . $w
& new i nd
G t kH
ow
- >a
d
B ox( ( $bo
); x) ;
1 7 . $ b o x->p
a c k _ st a r t ( $ l a b e l 1 , f a l se
1 8 . $ b o x->p
a c k _ st a r t ( $ t e xt 1 , f a l se
1 9 . $ w i nd
ow
- > sho
2 0 . G t k: : m a i n ( ) ; 2 1 . ? >
w _a
ll( ) ;
, f a l se , f a l se
,0 ) ; ,0 ) ;
ze
d ( t r u e o r f a l se
a c e w h i c h i a s va
L e t ' l s o o a k t a sc r i p t t h e u se t s h e l a b e l a n d t e xt e n t r f y i e l d . S e e
S c r i p t 1 2 - 3 t e x t _e
i d g et .
.
o u l d f i l l t h e sp
nt of pa
di n w g
t s:
W h e t h e r o r n o t t h e o b j e c t sh ou
t of t h p e r e c e
;
( an i nt eg
, t r ue
, 0. T he
).
i l a b l e t o i t ( t r u e o r f a l se
).
er ) .
se m ea t n e o xp S c ri
an a d nd f i l lan u d se no pa
p t1 2 - 3
, t e xt _e
n t r y. p hp
d , b el ow
i ng
. .S e e
F i gu
r e 12
- 5 f t or he exa
m pl e
F i g u r 1 e 2 - 5 . t e x t _e
S cri
p t 12
- 3. t ex
t _e
n t r y. p h p L i n e- b y- L i n e E xp
L IN E 2
at i o n
no s
t be
d n ef i ned
, t hen
ex c u
t l e i3 nes
–7.
I f t he G T K cl ha as
be s
en de
f i ned
, t hen
t he scr
i pt ne t eds
do o
t h i n g.
3
C t heck
f he
4
I fi W t i s
I N ,t hen
5–7
I ftP he
H P _O
10
l an
D E S C R IP T IO N I f t he G T K cl ha as no
8–
n tr y .p h p
i r st t hr char e syt he
em
S envi l i br ar y.
D ef i ne f a un
c t i on
E xec ut
t e G he
10
E t nd f he
unct
1
C r eat ne a e
12
C on
ne
w he
n t he us cl er
, de
C r eat n a e
14
C r ea
15
C r eat new a e
16
A t d box he
17
P ac k
t l he
18
P t ac k
t he
19
I su
20
C al tlG he
ent
var
st r oy
ec st r oy
r obj y
l ab
el ob
j ec t
i zont
t o w he abel ext
c al
usi
W I N , t hen
as um
l i br ar f y or W i ndow
t e hat
i pt w he c n al l ed
e.
P H P ri s uni
s. o ng
a n Li syt nux
em
and
l oad
t he Li nux
.
i pt cl and
t ose
G he
TK
w i ndow
.
ndow.
t ext
l ed $l ab
el c o 1 c al
ow
t t o he de
t of t he w i nd
$l ed
ec t
i abl
st r oy ow
( ) f un
ct i on t ha
t yo d u ef i ne e d arl
i er. T he ' de
st r oy
t id s
ed
'm et ho i d cal s
l ed
.
1. nt ai ni ng t he t ext
" A T ext
E nt r F y i el d".
$lbox. ed
t ng ad( he
) m et hod.
i nt t o box. he r obj y
_a
c al
var
H P G TK
st o t op scr he
l $wli ed
ent
P he
t st op t s he scr
al obj box
ec t
- ent ow
ec t
i ndow obj
i e not s
'm et ho o d f t he w i nd
- ent
r onm
s. t Load
he " X " on t he t op r i gh
t ext
hor
tca
S envi
i ndow
ui t ( ) m et t hod
w w obij ndow
i t c ks
H P _O
i abl
( ) , t ha
ar at i on.
ew
t e he sh
W ng
decli on
ew
nt a e
r i s uni
t k: : m ai n_q
ct t he ' de
13
er of s t P he
r onm
P H P G TK
9
ac t
ec t l l ( ) f un
t k: : m ai n( ) m et hod
i nt t o bo he
x.
c t i on c a
l l t t o he $w
tr o un t he scr
i nd
ow
ob
j ec
t so
ha
t ev
eryt
hi ng w i t hi t n he ob
j ec
sp
l ay
.
i pt .
T o p
P u t t i n g I t A l lT o g e t h e r S n o o w yo k u no a a n p p l i ca
w ho
w tmo
ak a e l a b el b, a ut t o (w n
i t a h l a b el i n t ) , an a d t e xt en
t r f y i el d . W i t t h h e se t h r e t e o o l s, yo c u a b n e gi t n b o u i l d
t io n !
F i r st , w n e e t d k o no neds:
w ho
w t g o et t he t ex
t t he us ent er
i ers
t n he t ex
t en
t rwy
i dg
et . T he G t kT
ex
t E nt r w y
i dg
et ha m a s
et ho t d ha
tm e
t o s ur
$ i n p u t = $ t e xt 1 - > g e t _ t e xt ( ) ; Y ou c a w ha us
n as
si gn t he us
t ev yo er er-
er-
u w a w nt
en
e nt e r e t d e xt . S e e
S cri
p t 12
t er d
da
t a us
i ng t he ge
t _t ex
t ( ) m et ho
i ng scri
p t pu
t i s t a l l t o g e t h e r a nd prov
i t h t h a t t e xt . T h e f o l l ow
- t 4 ex
F i gu
t _s
r 1 e 2-6
f exam or
pl o e ut pu
u b m it.p h p
1 .
i f (! c l a s s _ e x i s t s (' g t k ' ) {
3 .
i f ( st r t ou
4 . 5 .
p p er(
su
bs
t r ( P H P _O
S ,0 ,3 ) ) = = ' W I N ' )
d l (' p h p _ g t k . d l l ' ); e l se
6 .
d l (' p h p _ g t k . s o ' );
7 . } 8 . f u n ct i o d n e st r o y() 9 .
{
G t k: : m a i n _ q u i t ( ) ;
1 0 . } 1 1 . f u n c t i o sun
b m it ( ) {
12.
g l o b a l $ t e xt 1 ;
13.
$ i n p u t = $ t e xt 1 - > g e t _ t e xt ( ) ;
14.
e ch
15.
$ t e xt1
o $ i n p u t . "\ n "; ->s
e t _ t e x t (' ' );
1 6 . } 1 7 . $w
i ndow
& = new
G t kW
i ndow
();
1 8 . $ w i n d o w - > c o n n e c t ( ' d e st r o y' , ' d e st r o y' ) ; 1 9 . $w
i nd
ow
- > set
2 0 . $t ext & = 1
ne
_b
or de
w G t kE
r _w
i dt h( 5) ;
nt r y( ) ;
2 1 . $l ab el & = 1 en w G t kL ab el ( " A T ex t E nt r F y i el d") ; 2 2 . $b ut t on & = 1 en w G t kB ut t on ( ' S ub m i t T ex t ! ' ) ; 2 3 . $ b u t t o n 1 - > c o n n e c t( ' c l i c k e d ' , ' su b m i t ' ) ; 2 4 . = $box 2 5 . $w
& new i nd
G t kH
ow
- >a
d
B ox( ( $bo
); x) ;
2 6 . $ b o x->p
a c k _ st a r t ( $ l a b e l 1 , f a l se
2 7 . $ b o x->p
a c k _ st a r t ( $ t e xt 1 , f a l se
2 8 . $ b o x->p 2 9 . $ w i nd
a c k _ st a r t ( $ b u t t o n 1 , f a l se ow
- > sho
3 0 . G t k: : m a i n ( ) ; 3 1 . ? >
, f a l se , f a l se
w _a
ll( ) ;
,0 ) ; ,0 ) ;
, f a l se
,0 ) ;
t.
d on t he $t ex
t 1 ob
j ec i d e a s sh
t o a va
r i ab
o r t e xa
l e ( f exa or m p l e f a of
m pl e $i np un
ut ) , t he
ct i on t o h a nd
n do
le t h e
F i g u r 1 e 2- 6. t ex
t _s
u b m it.p h p
S cri
p t 12
- 4. t ex
t _s
u b m i t . p h p L i n e- b y- L i n E e
L IN E 2
I f t G he
T K cl ha as
do no
t hi ng
3
C t heck
f he
i r st t hr char e
4
I fi Wti s
I N ,t hen
sy he
5–7
I f t P he
H P _O
S envi
8–
10
l i br ar y.
D ef i ne a f un
c t i on
t e G he
10
E t nd f he
unc
6
not s
P H P G TK
E xec ut
–1
l an
at i o n
D ef i a ne
be
de n
f i ne
d, t hen
ex c u
t l e i 3 nes
–7.
I f t G he
T K cl ha as
be s
de n
f i ne
d, t hen
t scr he
i pt ne
t ds
o
.
9
1
xp
D E S C R IP T IO N
ac t
er of s tP he
t em
ri s uni
W ng
r onm
ent
, de
st r oy()
t deci on f un
A l l ow
t var he
13
A si
gn t he use
14
E t cho
user he
15
C l ea
r t he us
i abl
, t ha
r onm
s. t Load
i e not s
P he
t s op t s he scr
var
i abl
H P G TK
W I N , t hen
t ( ) m et t hod
ent
as um
l i br ar f y or W i ndow
t e hat
i pt w he
n c al
st o t op scr he
l ed
e. s.
P H P ri s uni
o ng L a n
siyt nux
em
and
l oad
t L he
i nux
.
i pt cl and
t ose
G he
TK
w i ndow
.
l ar at i on.
c t i on
12
S envi
i ndow
var
t k: : m ai n_qui
H P _O
, sub
i abl
m i t ( ) , t ha
$t e
ext
r - en
er t ed en
oe t s he use
t 1 be o t by ac es d
t er ed t ext
- ent er-
t ec h
ext
t t er d
o t he $i np t S o TD
ex
r - en
hi f s unct
i on.
ab
l e by c al
ut vari
O U al T w ong
t f r om
t he t ex
t er t ed
tS o
T D O U T .
l i ng t he ge
i new t a h
t i np
ext
l cihar ne
ut c a by
t _t ext ac t
l l i ng t he se
t _t ex
( ) m et ho
d of t he $t ext
1 t obj ext
ec t
.
er t ( ) m et ho o d f t he $t ex
t t 1 ex
t ob
j ec
t , as
si gn
i ng t he ne
w
t e t xt o b e b l a n k (' ' ). 16
E t nd f he
unc
t deci on
17
C r eat ne a e
18
C on
ne
w he
n t he us cl er
l ar at i on.
w w i ndo
w obj
ct t he ' de
st r oy' i t c ks
19
S et f a i ve-
pi xel
20
C r eat
a e new
t ext
21
C r eat
e n a ew
l abe
2
C r eat new a e
bor
23
C on
24
C r eat new a e
25
A t d bo he
26
P ac k
t l he
27
P t ac k
t he
28
P ac t k but he
29
I s ue
30
C al Gtl he
der - ent
but
ec t
lob
abel
- ent objt on
t he w i ndow ec t c al
ec t
c al
c al
$t l ed
ext
l ed $l ab
el c o 1
$blut ed
m et hod
t o he de
ec t
c al
t ng ad he i nt t o box he
r obj y
ec t
t k: : m ai n( ) m et t hod
) f un
ct i on t ha
der
_w
t you
de
f i ne
d ea
r l i er . T he ' de
st r oy'
.
ng t he set
_bor
i dt m h
et hod
of t he w i ndow
obj
ec t
.
1. nt ai ni ng t he t ext
" A T ext
E nt r F y i el d" .
t on t o he he
l l o( ) f un
c t i on
.
$boxl. ed ( )m et hod.
. i nt t o box. he
ti nt t o box he
l l ( ) f un
st r oy( ow
t on.
of t he but
al obj box
ec t
ow
usi
j ec t
ec w _a
d of t he w i nd
ar ound
usi ndow obj
w .
t of t he w i nd
i zont
t x t o w he
t he sho
m et ho
w i ndo
he " X " on t he t op r i gh
t obj on
hor
ct al $ l ed
r obj y
t he ' cl i cked'
ext
ec
.
c t i on c al
lt o t he $w
r o t un scr he
i nd i pt .
ow
ob
j ec t
so t ha
t ev
r yt hi ng w i t hi n t he ob
j ec t
di s i spl
aye
d.
m et ho
d cia s
l l ed
D i al og B o xes M o st G U I ap
p l i ca
t i o ns h a ve t he a bi l i t t y d o i sp
w an
t t s t o ak t e he de
t r t y cl o
os t e he ap
si r ed ac pl i c a
si m pl d e i al og bo T he G t kD yo b ur
su up
. F exa or
t i on w i t ho
ut f i r st sa
xe u s si ng t he G t kD
i al og c l as i s si s
l ay sm
a l l w i n do
m pl e, d a i al og bo a x p vi ng t he do
i al og c l as
m pl a y w i nd
ow
t ha
t co
cu
m en
w n s ot i f yi n t g h u e se ea
r a s ski
r t h a t so
ng " A r y e ou su
t on w hi y ch
ou w are
orki
ng
r e…
m e t h i ng i w s " im n
os
r o n o g r t c o o nf i r m t h at t h u e se
t w proc e rd
. P H P G T K al p so
r ov
t sc r
i pt sh
i c ks
S cri
nt ai ns v a bo
x, s a ep
ar t
or, an a d "ac t n
ow
a s e n xa
t h e " Q u i t bu "
m pl o e f ho
t t on
w t u o a se
, o r t h e " X i " n t h e u p pe
G t kD r r i gh
i al og bo t x c o on t co
r n t of er
f i r m t ha
u t a se
he m a i n w i n d ow
p t 12
- 5 d i al o g . p h p
1 .
4 . 5 .
p p er(
su
bs
t r ( P H P _O
S ,0 ,3 ) ) = = ' W I N ' )
d l (' p h p _ g t k . d l l ' ); e l se
6 .
d l (' p h p _ g t k . s o ' );
7 . } 8 . f u n ct i o d n e st r o y() { 9 .
G t k: : m a i n _ q u i t ( ) ;
1 0 . } 1 1 . f u n ct i o cln 12.
o se
_ d i a l o g ( $ b u t t o n ,$ d i a l o g ) {
$ d i a l o g - > d e st r o y()
;
1 3 . } 1 4 . fun
c t i o n de
l e t e _ e ve
15.
co
n f ir m ( ) ;
16.
ret
u r tr n
n t(){
u e ;
1 7 . } 1 8 . f u n ct i o c n o n f i r m ( ) { 19.
gl oba
20.
$d
21.
$ d i a l o g - > se
t _ t i t l e ( "A
2.
$ d i a l o g - > se
t _ d e f a u l t _ si ze
23.
$d
t _m
24.
$ d i a l o g - > se
t _ t r a ns
25.
$ d i a l o g - > se
t _ p o l i cy ( 0 , 0 , 0 ) ;
26.
$l abe
27.
$b
28. 29.
$ b u t t o n _ ye s-> c o n n e c t( ' c l i c k e d ' , ' d e str o y' ) ; $b ut t on _n o = & ne w G t kB ut t on ( ' C an cel ' ) ;
30.
$ b u t t o n _ n o - > co
31.
$vbo
32.
$vb
3.
$ vb
34.
$vbox2->pack_star($buton_yes);
35.
$vbox2->pack_star($buton_);
36.
$ d i a l o g - > sh
l$w
i ndo
i al og & =
i al og
w ; ne
w G t kD
- >se
& l= ut t on
new _ye
i al og;
od
r eY
i e n t _ f o r ( $ w i n do el ( " A r Y e S ou
ne
x1 = $di
al og->vb x;
ox2
= $d
i al og
o x1
- > p a c k_
i ndow
& = new
u re ? "); (' 1 0 0 ' , ' 1 0 0 ' ) ;
al ( T R U E ) ;
G t kLab &=s
o uS
w G t kB
ut t on
- >a
c t i on
_a
r ea
st a r t ( $ l a b el ) ;
o w _ al l ( ) ; G t kW
i ndow
();
w );
ur Y e W ou
ant
T Qo
ui t ?" ) ;
( 'O K ') ;
n n e c t ( ' c l i c k e d ' ' , c l o se
3 7 . } 3 8 . $w
i de an s
r
ng ap
pl i c a
t i on i s f you
ea w sy
t ay c reat o
t i t n he vb
ox an p d l ac
e
s. i on are .
" Y ou pl ac y e ou
r w i sh
es t q o ui t ou
, a d i al og b ox i d s i sp
t of t he ap l ay
r e t h e w y a n t t o q u i t . I f t h e u se r c l i c k "O s K i " n t h e d i a l o g b o x, t h e n t h e a p p l i c a t i o n e xi t s. I f t h e u se r c l i c k "C s p e r r i g h t co r ne r o f t h d e i al o b g ox , t h e t n h d e i al og b ox cl o se s, b ut t h a e p pl i ca t i on r e m a i n o s p en . S e e
3 .
si
r t ex
e
u t t on i s n t h e " a c t i o n a r e a . "
T hi n s ex us c l er
t i on
;
_ d i a l o g $' , d i a l o g ) ;
ed
pl i c a , a ski
t i on
. W he a n
ng t he u se
a n c e t l or "
r i s f t h ey are
h e "X i " n t h e F i gu
r e 12
- 7 f exa or
m pl o e ut pu
t.
3 9 . $ w i n d ow 4 0 . $b
ut t on & =
- > co
n
ne
w G t kB
e c t ( ' de
l et e _ ev
ut t on
en
t ' , ' de
4 1 . $ b u t t o n - > c o n n e c t( ' c l i c k e d ' , ' c o n f i rm 4 2 . $w
i nd
4 3 . $ w i nd
ow
- > ad ow
d( $b
- > sho
ut t on
w _a
l et e _ ev
en
t ') ;
( ' Q ui t ' ) ; ') ;
);
ll( ) ;
4 4 . G t k: : m a i n ( ) ; 4 5 . ? >
F i g u r 12 e
- 7. d i al o g . p h p — i n i t i al w i n d o w an
S cri
p t 12
I f t G he
T K cl ha as
do no
t hi ng
3
C t heck
f he
i r st t hr char e
4
I fi Wti s
I N ,t hen
sy he
5–7
10
not s
W ng
I f t P he H P _O S envi r onm P H P G TK l i br ar y.
ent
c t i on
E t nd f he
unc
t deci on
D ef i ne f a un
12
C al lt d he
13
E t nd f he
unc
E xec u
16
R et t urn t he
7
, c l os
e_
–7.
I f t G he
T K cl ha as
be s
de n
f i ne
d, t hen
t scr he
i pt ne
t ds
o
r ue
n t he w i nd unc
D ef i ne a f un
S envi
r onm
s. t Load
var
i abl
i e not s
, t ha
t s op t s he scr
ent
P he
var
i abl
H P G TK
W I N , t hen
as um
i pt w he
st o t op scr he
l i br ar f y or W i ndow
t e hat
n c al
l ed
i pt cl and
e.
P H P ri s uni
s. o ng L a n
siyt nux
em
and
l oad
t L he
i nux
. t ose
G he
TK
w i ndow
.
di al og
( ) , t ha
) m et ho of d t $ he
t deci on
l ar at i on.
di al o og
t i on po
i nt . I f yo
nf i r m ( ) f un . I f yo r u et f urn ow
di s est
t deci on c t i on
es d a i al og bo
al (w se r oye
t c l o t ose
t i on w i n do
u do no
c t i t on
bj ec t
x. T hi f s un
d he
t ( ) , t ha t ca t ch es w he ct i on ( ) . T he de l et e_
of r t h e a p pl i c a ec
t c l os
c t i on t ak
es t w a o r gu
mo
t us ake
e a de c er
hi i ch t s he de
t ai t n u he
ev
en ser
l t be
i nd
n a us c l er i o c ks ev en t ( ) ia s sp
w . " d e l e t e_ l et e_
f au
i al w og
e ve t co
n
w i she ha
ow
t s: $b
ut t on an $ d di al og
. S e t he
n t he " X " i n t he up pe r - r i gh t co r ne r of t he m ai n ap pl i ca t i on i al m et oh d t ha t riun s w he en ve r a us cl er i cks t he " X i " n
ec
nt i " a s va ec
.
l i d co
t i on po
t s ex o
i t a he
vi or of t he de
l et e_
n n ec
i nt , t he p ev
l i c at en
t i o n p o i n tf o w a r
n t he w i nd i on t w he yo n
d.
l ar at i on. , co
m en
d a e sc r i p t i o o n f t h a e r g u m e n t s.
r oy(
n
H P _O
t ( ) m et t hod
l i n 3 e for 0
t t e co he
E t nd f he –3
st r oy()
r - r i g corne ht
st r oy c o
15
t l e i 3 nes
i ndow
D ef i ne a f un ct i on , de l et e_ ev en w i nd ow an d r un t s eh co nf i r m f un de
ex c u
l ar at i on.
c t i on
est
t h e u p pe
18
, de
t k: : m ai n_qui
d e sc r i p t i o for n
17
d, t hen
ri s uni
10
7
f i ne
t em
t e G he
–1
de n
er of s tP he
D ef i ne a f un
3
be
ac t
E xec ut
14
at i o n
.
9
–1
l an
D E S C R IP T IO N
2
1
n f i r m at i o n d i al o g b o x
- 5. d i al o g . p h p L i n e- b y- L i n e E xp
L IN E
8–
d co
nf i r m ( ) , t o co
nf i r m t ha
t he us w er
i sh
es t o qu
i t t he ap
pl i c a
t i on
.
ow
i n do
ia s ut om
w , si m i l t ar o t he at i c a
l dl y es
t r oy
ed
. d u on
' t as
si gn c o a
n
ec
t i on t i o t ) ,
.
L IN E
D E S C R IP T IO N
19
A l l ow
t $w he
20
C r eat new a e
21
S et t he
i t fl e or t d he
2
S et t def he
aul
23
S et t d he ow
exi
ec t i al o og
hi f s unct
c al
$di l ed
bj ec t
.
t si of ze
t di he
al w og
i ndow
m a as
oda
i ndo
w t a as
S et t resi he
po ze
27
C r eat n a e
28
U t se
29
C r eat n a e
30
U t se eh con ar gu m en
l i f cy
en
_ sh
al l ow
_g
obj
bu
t t o on
ew
ec t ew
i nd r i nk
c t i on
co
n n ec
. Th
xel
mi s
ow
ean
ec t
ec t
ai w n
s.
t s hat
t m he
ze(
ai ap n
c al
$l ed
bj ec t
abel
c al
pl i c at
wi on
i ndow
canot
bu
t w i ndo ow
w do no es
a t c ause
b s ut w or u ks
nd Li er
t s hr e bo
ow
t o be m ad o w t o ov
e gr ea er
ext n nu
31
se
as
. I t n hi ca s
, c l o se
i l dren
t er ha
( t h i sh s
n i to s r i gi na
i d i e t d s ef a u l t si ze se
se
_yes.
T hi i s a used s
t he de
st r oy(
no.
T hi i s a used s
t on_
c h a c s l os
, w a e r se e
e_
nd
t he G t kD
A s var ai gn
3
P ac k
t l he
P t ac k
O he
36
S t how
c he
37
E t nd f he
38
C r eat ne a e
39
C on
34–
35
) f un
t s "O he
K " bu
o u l a d l w a b ys
abel
c t i on t b o c a e t s "C he
d i a l o g ) . Y o u ca
i ng t he di al og w i nd
t e t o G he ec t
l l ed w hen
t t i ng t s s o hri
an
c el
" but
t hi bu s
41
C on
42
A t d but he
ec t
lbut
t i ons
ance
w obj
t deci on
m en
t s:
s e e t t f o a l se
).
i l d w i nd
o w s.
ox. i c ked.
i al b og
ox.
ow
ob
j ec
t $d
i al og
ect m et ho h d a as i on ( suc h as c l i c ked
e nt , w hi ch ia s n ad . S i nc w e a e r s e en t im s
d i t i o n al va di ng t w a o r gu
a ki n t g h c e o n u a r e c rea
e n xt r a ) an d t he
r i a b l e t ha m en
e c t i o n ) , yo m u t i n g t h e co
t i s s en
tt o t h e
t s, an t d he us
td e f i n t e h e
n n e ct i o n , i n t h i s
i al og'
i al b og
ox
ox
ac t s
i on_ar
t kD
i al og
t en
t , you
ne
ed t a o s i
gn va a
r i ab
l n e am
f e or t ha
t ob
j ec t
. H er yo e
u
. ea.
'ac t s
i on_
ar ea.
t o t he de
l et e_
.
l ar at i on.
l et e_ d ou
but t ' he
' vb s
t n G he
ec
ct al $ l ed
ev
t si nc t obj on
t on t o w he
c al
of t b he usi
w .
d of t he w i nd h "X e
t ed t o di r ec
$blut ed
m et hod i ndow
r c l i t c ks
e w e w an ec t
c l i c ked'
w i ndo
nt 'm et ho
l l ed w he t n h u e se
et ho
C r eat new a e
box.
w w i ndo ct t he ' de
40
t be o
n t k t o h s e i ze o f a n c h y
i al b og t t on cil s
t i on t n d he
n a d a t h i r d a r g um
s" f or c on
i al og
t kD
i nt t o v he
s of t d he
m et h o i d c a s
i l t - i "boxe n
nam e
ent
unc
ha bu s
t e t o he G t kD
obj
ont
j ec t
l n e am
K an C d
l ef t hi m s
r i t em
lsi ze.
t t i on t n d he
a l l t y a ke o s nl o y ne b d y e f a ul t ( w hi ch i t s h o e b j e ct t ha
i al og ob
r i ab i abl
ne
r t a askb
_ d ia lo g ( ) .
si gn va a
32
hi tl e hi s
o 0 r 1) ar gu
( ) m et oh t d ca o t use he cl ose_ di al og( ) f un c t i on t b o c al e l ed .N ot t e aht t he con d on at t he en d. N or m al l y, t he con en ct ( ) m et oh d ah t s w o ar gu m en t s: t he act
ge
t e f d u n c t i o u n su
S i nce
w c es d
x.
ol ea ( n t r ue or f al se/
w t b o s e m a l l t er h a i n t c h s
i nd
t t on
use but
en
d e f a u l t o b j e c t ( $ b u t t o n ) a n d t h e a d d i t i o n a l o b j e c t ( $ d i a l o g ) i n t h e f u n c t i o n f o r w h i c h yo ca
a be
.
l $ ed
l l $ ed
. A t r ansi o n n W i nd
) m et ho t d ake
i n do
ts h we
ow
t bl y r oke
t he w i nd
A l l ow
i nd
r r en
. T resi he
— A l l ow
r i n k—
t t c a on
t of t m he
— A l l o w t h we
r ow
t i o n t h i at c s a l l ed ( su
f un
pi 10 x 0
. T hi i s cu s
( ) m et ho t d ca o
bu
t ag
ow
or t w he
a l l ow
l abel
he con
f u nc
10 t be o
wl i ndow
r ansi
a u t o _ sh
C r eat new a e
al og.
i ndow
t ed ti n he O S f t or he w i nd
26
i on.
st s.
i al w og
c r ea
ec t t by used t be o
di al obj og
S et t d he
25
obj
i al w og
w i nd 24
i ndow
t ng ad( he
ow
" b ut t o i n t n h u e p pe t ld y es
t r oy t he w i nd
ow
t on. ut t on t o co he ) m et hod.
nf i r m f unct
ev
nt ( ) f un
r r i g ht co
i on.
.
ct i on t ha
r n e r of t he a p
t you l i ca
de
f i ne e d ar l i er . T he ' de
t i o n . I t n he p r e vi o u e s xa
l et e_
ev
m p l e s, w e
nt '
L IN E
D E S C R IP T IO N
43
I s ue
4
C al Gtl he
t he sho
w _a
l l ( ) f un
t k: : m ai n( ) m et t hod
c t i on c al
lt o t he $w
r o t un scr he
i nd
ow
ob
j ec t
so t ha
t ev
r yt hi ng w i t hi n t he ob
j ec t
di s i spl
aye
d.
i pt .
T o p
A S i m pl P e H P G TK T hi n s ext
ap
pl i c at
i on use
t he i r r es pe ct i f ve i n so m e of t he previ W he yo n 12-8
t ed m as
am
pl o e ut pu
S cr i p t 12-
T K w i dg
l i cat
et t s c reat o
i on a e sm
al lap
i el ds , t he cl n i t ck eh " G en erat e… " bu ou sc s r i pt i s n t hi b s o k. T eh us ernam
h u av c rea
f or ex
Gs
A p
an pa y
sw
a ords
ne s
ed
pl i c at
i on t ha
t t on t c reat o e an d pa ed
, yo c a u
t en
c od
es pa
cl n
i t ck
he " W r i t T e F o i l bu e"
t.
p 6 asw
o r d _g
en
. p hp
1 .
i f (! c l a s s _ e x i s t s (' g t k ' ) {
3 .
i f ( st r t ou
4 . 5 .
p p er(
su
bs
t r ( P H P _O
S ,0 ,3 ) ) = = ' W I N ' )
d l (' p h p _ g t k . d l l ' ); e l se
6 .
d l (' p h p _ g t k . s o ' );
7 . } 8 . f u n ct i o d n e st r o y() 9 .
{
G t k: : m a i n _ q u i t ( ) ;
1 0 . } 1 1 . fun
c t i o n ge
n e ra te (){
12.
g l ob
13.
$ t e $ = xt
14.
$ o u t p u t ->i
15.
$ u se
r _ i n - > se
t _ t e xt(
'') ;
16.
$ p a s _ i n - > se
t _ t e xt(
'') ;
a l $ us
er_i
u se
n, $ p as
s_
i n , $ o ut p u t ;
r _ i n - > g e t _ t e xt ( . ) " : . " e n c o n s e rt (nu
l l nu ,
l l nu ,
l l $te ,
d e d ( $ p a s _ i n - > g e t _ t e xt ( ) . ) " \ n " ; xt)
;
1 7 . } 1 8 . f u n c t i o e n n c o d ed 19.
r et u r n m d 5($t
( $ t ex
t ){
e xt ) ;
2 0 . } 2 1 . fu
n c ti o n w
2.
g l ob
23.
$ t e xt = $ ou
24.
$f i l = e f op
25.
f w ri t e ($ f i l e , $ t e x t );
26. 27.
f c l o s e $( f i l e ;) $ o u t p u t - > d e l e t e _ t e xt ( 0 , - 1 ) ;
28.
$ co
29.
$ o u t p u t - > i n se
ri t e () {
a l $ ou
t p ut ; t p ut - > ge en
( " pa
s.
t _ ch
ars(
0 , - 1);
t xt " , " w " ) or di e("
m pl et e = " P a s w
o r d ws
rt (nu
C A N N O T O P E N F I LE
r i t t e n t o f i l e ! \ n";
l l , n u l l , n u l l , $ co
m p le t e ) ;
3 0 . } 3 1 . $w
i ndow
3 2 . $w
i nd
& = new ow
- > se
G t kW t _d
i ndow
ef au
(); l t _s
i ze
( 30
0, 30
0);
3 3 . $ w i n d o w - > c o n n e c t ( ' d e st r o y' , ' d e st r o y' ) ; 3 4 . $u
ser
_l ab
el & =
ne
3 5 . $u
ser
_i & = n
ne
w G t kE
3 6 . $user
&n = _box
ew
w G t kLa G t kH
be
l ( " U ser
nt r y( ) ; B ox(
);
na
m e: " ) ;
sw
or ds.
Y ou en use t a er
a e e n cn r yp t ed us ernam a e dn pa sw c om rd sw a ord r e di sp l ay ed i n a t ex t bo i x n t he m i d
");
t t on t w o
r i t t e he da
r na
m e an
d pa
sw
or d i nt o
bi an t i on t ha t ca b n u e se l e of t he ap pl i ca t i on . t t a a o t ex
t f i l e. S e
d F i gu
re
3 7 . $ u se r _ b o x->p
a c k _ st a r t ( $ u se
r _ l a b e l , f a l se
3 8 . $ u se r _ b o x->p
a c k _ st a r t ( $ u se
r _ i n , f a l se
3 9 . $p
as _
l ab
el & =
ne
4 0 . $p
as_i
&=n
ne
w G t kE
4 1 . $pas_box
&n =
w G t kLa
ew
be
l ( " P as w
,0 ) ;
,0 ) ;
or d: " ) ;
nt r y( ) ;
G t kH
B ox(
);
4 2 . $ p as s_ b ox - > p a c k_
st a r t ( $ pa
s_
l ab
4 3 . $ p as s_ b ox - > p a c k_
st a r t ( $ pa
s_
i n, f a l se
4 4 . $b
ut t on('
ut t on = 1 & new
, f a l se
, f a l se
G t kB
G en
er at U e
e l , f a l se
, f al se
, f al se ser
,0 ) ;
, 0);
nam
e: P as w
or d! ' ) ;
4 5 . $ b u t t o n 1 - > c o n n e c t( ' c l i c k e d ' , ' g e n e r a t e ' ) ; 4 6 . $o
ut pu & t =
4 7 . $b
ut t on = 2 & ne
ne
w G t kTe
xt ( ) ;
w G t kB
ut t on
( ' W r i t T e F o i l e' ) ;
4 8 . $ b u t t o n 2 - > c o n n e c t( ' c l i c k e d ' , ' w r i t e ' ) ; 4 9 . $vbox 5 0 . $v bo
& = enw G t kVB x- > pa c k_ st art
5 1 . $vb
ox-
5 2 . $v bo
> pa
ck_st
x- > pa
c k_
5 3 . $ vb o x- > pa 5 4 . $v bo
x- > pa
5 5 . $w
ow
i nd
5 6 . $ w i nd
st art
c k_
st art c k_
- >a ow
ox( ( $u
); se r _b
ar t ( $p
( $vbo
- > sho
( $b
);
bo
ut t on
x) ; 1);
($ o u tp u t);
st art d
ox
as _
( $b
ut t on
2);
x) ; w _a
ll( ) ;
5 7 . G t k: : m a i n ( ) ; 5 8 . ? >
F i g u r 12 e
S cr i p t 12
- 6. p as
sw
- 8. p as
o r d _g
en
w o r d _g
l an
at i o n
D E S C R IP T IO N I f t G he
T K cl ha as
n o t h i ng 3
.p h p
. p h p L i n e- b y- L i n e E xp
L IN E 2
en
C t heck
not s
be
de n
f i ne
d, t hen
ex c u
t l e i 3 nes
–7.
I f t G he
T K cl ha as
. f he
i r st t hr char e
ac t
er of s tP he
H P _O
S envi
r onm
ent
var
i abl
e.
be s
de n
f i ne
d, t hen
t scr he
i pt ne
t ds d o o
L IN E
D E S C R IP T IO N
4
I fi Wti s
I N ,t hen
5–7
I f t P he
H P _O
8–
10
S envi
r onm
ent
D ef i ne a f un
c t i on
t e G he
10
E t nd f he
unc
7
ri s uni
l i br ar y.
E xec ut
–1
t em
P H P G TK
9
1
sy he
, de
t k: : m ai n_qui
D ef i ne f a un
A si
c t i on
$ he
13
A s t i gn user he
14
I nse
, ge
use
var
i abl
i e not s
, t ha
t s op t s he scr
P he
H P G TK
W I N , t hen
as um
i pt w he
t e hat
n c al
st o t op scr he
l i br ar f y or W i ndow
l ed
P H P ri s uni
ne
r at e()
, t ha
as _
i n, an $o d
er user ed
t en
r na
nam
c r yp
tu a s
t ose
G he
TK
r na
m e/ pa
sw
m a e nd en
c od
t vari
ab
pas w
ed pa
g l as es
l ob
or t d t o $t he
sw
ext
or i d nt t o he t ext
al t so var
ha i abl
bo usi x
— A G D K Font
obj
S i ze—
T he nu
S t r i ng
— T he t ex
ec t
or obj
m be
ec t
r of cha
r ac t
t t b o i e ns
er you s
ert
ed
w it sh i o nse
16
C l ea
r t he use
r - en
t er ed t ext
ti n he P asw
17
E t nd f he
–3
0
unc
t deci on f unct
$en
c ode
t e he pasw
t deci on
D ef i ne f a un
23
G et t he en
i d nsi
de t hi f s un
er an p d r i nt i s t t a o
ex
use e
c t i on
t bo
, t hat
am
t i r e t ext
var f r om
, t ha i abl
r t ( ) m et ho f d t or he t ext
T h e sta
d .
r t i ng b a l an st k
r i ng i nt t o he en
t r bo y
or f d i el b d i y nse
r t i ng b a l an st k
r i ng i nt t o he en
t r bo y
d - 1 as argum
24
O pe n a f i l e f w or r i t i ng use r na m e/ pa sw
25
W r i t e t he
2 6
Cl o s t e h f e i l e .
t o f he
nt er p ed
( ) f unct
i on and
i n g t h e c rypt
t w r i t t es oba
ob
j ec t
ent
as w
ob
j ec t
. i nse
r t ( ) t ake
f s ou
c r ypt
i on m et hod
r
x. x.
or d.
r et ur i n t t o he cal
( ) f un
he en t lso usi
co
c t i on
ha
de u d se t i t c an
l i ng f un
c t i on
. Y ou c an
chan
ge t he en
).
ng t he ge
r na
be used t _ch
m e/ pa i nsi
sw
t ords
de t hi f s unct
ar s( ) m et ho
d an
fao
i l e.
i on. d pl ac e
i t i nt o t he $t ext
var
i ab
l e. T he ge
s:
rt p o si t i o n o f t h e t e x t i (0 the s
T he e nd p os
ext
l u e a s r e u se
m f e i el b d i y nse
de t s e he
a e gl s
t he t ext
w a o r gum
U si ng 0 an
enco
p l e by us
, w r i t e() t put
t akes
x
.
l ar at i on.
c t i on
gn t he $ou
m et hod
na
or u d si ng t he m d5 d (f s o r ex
unc
A si
t y he us
l ar at i on. i on,
u rn e
2
t b er d
.
it n he U ser
21
i nux
rt.
t er ed t ext
E t nd f he
t L he
.
r - en
20
l oad
.
r t he use
i t yo
t i on en
t he b can y
ng t he i nse
C l ea
su
and
e.
15
E ncod
em
.
bi na
t t h e f i r st t h r e e a r g u m e n t a s n s u l l so t h a t t h e d e f a u l t va
19
w i ndow
c om rd
F o r si m p l i c i t y, I se
D ef i a ne
siyt nux
.
i pt cl and
se
ut pu
and e
C ol or — A G D K c ol
20
o ng L a n
s: Font
18–
s.
tio n .
- ent
ent
s. t Load
t ( ) m et t hod
r _i n, $p
r t he use
ar gum
i ndow
l ar at i on.
i n si d e t h e a p p l i c a t gn
st r oy()
t deci on
12
W ng
f i rst p o si t i o n ).
i t i o n of t he t e xt . en
t ca s
us
es t he en
t i r e t ex
t i n t he t ex
t ob
j ec
t o be c o
l l ec
t ed
.
. N ot e t ha t i f you ah ve an exi st i ng f i l e w i t h t he sam e na m e, i t w i l lbe w r i t t en ove r w i t h t he en w or c o d m bo s. Y ou m ust al se so t pe r m i si on on s t he f i lso e t ha t i t can be w r i t t en t b o P y H P . i l e.
t _ch
ar s( )
to
L IN E
D E S C R IP T IO N
27
D el et t e t he
28
C r ea
29
W r i t e t he st r i ng t o t he t ext ag
ext t i n t he
st a e
ext
ar ea.
t r i ng of t ext
no
t i f yi ng t he use ar ea
r t ha
t he t ext
t you
w i l lne
. N ot e t ha
ha be s
en w r i t t en
ed t o c l ose
an
.
d r est
ar t he ap
pl i c at
i on i f you
w i sh t o c r ea
t e pa
sw
or ds
ai n.
30
E t nd f he
unc
t deci on
31
C r eat ne a e
32
S et tsi he
3
C on
ne
w he
n t he us cl er
l ar at i on.
w w i ndo of ze
w obj
tw he
i ndow
ct t he ' de
st r oy'
ec
ct al $ l ed
x 30 t be o
pi 30
m et ho
i t c ks l abel
obj
35
C r eat new a e
t ext
- ent
r obj y
36
C r eat ne a e
w hbo
ixwn
hi t ch pl o t ace
37
P ac k
t l he
38
P t ac k
t he
39
obj
ec t
ec t
f or uster he ec t
obj
40
C r eat new a e
t ext
- ent
r obj y
41
C r eat ne a e
w hbo
ixwn
hi t ch pl o t ace
42
P ac k
t l he
43
P t ac k
t he
4
C r eat new a e
45
C onect
46
C r eat new a e
t ext
47
C r eat ne a e
w but
48
C on
49
C r eat t vbox new a e
50
P t ac k
cont hbox he
51
P t ac k
hbo he
52
P ac t k " he
G enr
53
P ac k
t he
ext
54
P t ac k
" he
5 5
Ad
56
S how
57
Exe
- ent
"t he
ec t
ec t t ob on
cont x
ec t
al of l ct he
ent
c ut e t he s c r i pt .
sw
" but
t on t o gen he
spl
j ec t
f or t " he
or l d abel
t and
ext
ext
ai ni t ng U he
ser
ai ni t ng P he
as w it on x. nt t o vbox. he
i ndow.
r i t e( ) f unct
nam
i on.
.
but and
nt t o v he
ow. of s wt he
put
boxes
t on.
er at e( ) f unct
t t on t o w he
t i on
" but
W r i t T e F o i l e" but
her
" but
at e…
t ay out he
t d ot he
i l e" but
x t o t he wi nd ont
pa he
G enr
i nt t o vbo he
W r i F t To e
t andl
- ent
r obj y
- ent
r obj y
ec t
s.
or d.
f or "t he
tdi o
at e… obj
de
.
f or t pasw he
r i t T e F o i l e" bu hol o
l e abe
i nt t o hbox. he ec t
obj
nam
.
at e…
t "W he
t h v e bo
ec t
ec t
G enr
t you
e.
or l d abel
i nt t o hbox he
obtj on
ct i on t ha
.
nam
f or t pasw he
r obj y
) f un
.
i nt t o hbox. he
ec t
ec t
st r oy( ow
.
l abel
obj
ec t
t o he de
l e abel
user he
i nt t o hbox he
C r eat new a e
but
ow
t of t he w i nd
f or uster he
r obj y
ext
s.
nam
- ent
abel
xel
d of t he w i nd
C r eat new a e
ext
w .
he " X " on t he t op r i gh
34
abel
w i ndo
t on. i on.
t ons. l e abel
ent and
r i y nt t o vbox. he
or l d abel
e and
nt r i y nt t o vbox. he
box
.
ec t
s.
f i ne
d ea
r l i er . T he ' de
st r oy'
m et ho
d cia s
l l ed
T o p