Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

/

6 2010-11

. .
12/10/2010


1: HTTP ................................................................................................ 1
............................................................................................................................... 6
GET ................................................................................................................................................. 6
HEAD ............................................................................................................................................... 7
POST ............................................................................................................................................... 7
- ............................................................. 9
2: ............... 13
3: Adobe Dreamweaver...................................................... 17
Site Dreamweaver .................................................................... 17
........................................................................................................... 17
Site ..................................................................................................................... 18
1 ........................................................................................................................................................ 19
2 ........................................................................................................................................................ 20
3 ........................................................................................................................................................ 21
4 ........................................................................................................................................................ 22
5 ........................................................................................................................................................ 23
6 ........................................................................................................................................................ 24
........................................................................................................................ 25
Dreamweaver........................................................................... 29
CSS .......................................................................................................................................... 31
4: PHP ( ..) .................................................................. 33
Sessions .................................................................................. 33
5: PHP .................................................................. 39
Navicat MySQL Server ............................................................................................ 40
........................................................................................................... 40
......................................................................................................................... 40
.................................................................................................................................... 43


...................................................................................... 46
................................ 48
................................................. 50
................................................................................................................... 54
.................................................. 54
.................................................................................................................... 55
...................................................................................... 56
, .................................................................................... 59

1: HTTP

1 : HTTP
telnet

.
telnet Server IP ,
TCP ( 1).
telnet 23

Server (remote terminal).

Web Server, TCP 80.

PUTTY
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html.

.
,
Save.

1 PUTTY

3 TELNET

1: HTTP

4 HTTP GET HTTP/1.0


Web Server.

5 HTTP/1.0 HEAD
Server.

6 GET
Server.

7 GET HTTP/1.1
Host.

8 GET HTTP/1.1
Host.

9 POST
POST HTTP/1.1 Web Server .

4 GET

5 HEAD

6 GET

1: HTTP

7 GET HTTP/1.1

8 GET HTTP/1.1

9 POST

HTTP World Wide Web.


,

HTTP,


.
, .

GET
1.

GET HTTP/1.0 Web Server


http://weblab.teipir.gr/investigations/http/test1.txt.

2.

Server.

GET HTTP/1.1 .

Host. Server.
Host .

3.

Server. bytes .

GET HTTP/1.1 .

Connection: close.
Server. Connection: keep-alive.
Server. TCP/IP

1: HTTP
4.

GET HTTP/1.0 HTTP/1.1 Web Server

http://weblab.teipir.gr/investigations/http/get_test01.php.

GET (a, b, f ) HTTP :

r = a f b, f (+, -, *, /).
f ISO-

8859-7. .
.

HEAD
1.

GET

HEAD. Server.

POST
POST
.
(executable scripts).
1.

Web Server.

http://weblab.teipir.gr/investigations
/http/post_test01.php POST (a, b, c)

HTTP : r = a2 + b2 + c.
Content-Type: application/x-www-form-urlencoded. POST

GET
( ?).

. Content2.

Length. .

Web

Server

http://weblab.teipir.gr/investigations

/http/post_test02.php. POST

keimeno. Server .

( 1).


1 URL 928 (Windows Greek)

1: HTTP

-
HTTP

http://weblab.teipir.gr.

, .


GET / HTTP/1.1
Host: weblab.teipir.gr
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
Accept: text/xml,application/xml,application/xhtml+xml, text/html;
q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.7,el;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-7,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: PHPSESSID=e01760d780ea7c304bc571d2ddcd30b7
HTTP/1.x 200 OK
Date: Sun, 11 Dec 2005 23:51:27 GMT
Server: Apache
X-Powered-By: PHP/4.4.0-pl1-gentoo with Hardening-Patch
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,pre-check=0
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 2273
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-7
---------------------------------------------------------GET /site.css HTTP/1.1
Host: weblab.teipir.gr
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
Accept: text/css,*/*;q=0.1
Accept-Language: en-us,en;q=0.7,el;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-7,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://weblab.teipir.gr/
Cookie: PHPSESSID=e01760d780ea7c304bc571d2ddcd30b7
HTTP/1.x 200 OK
Date: Sun, 11 Dec 2005 23:51:27 GMT
Server: Apache
Last-Modified: Thu, 08 Dec 2005 17:37:57 GMT
Etag: "498a-1182-bab30740"
Accept-Ranges: bytes
Content-Length: 4482
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: text/css
---------------------------------------------------------GET /images/nav/front_page.png HTTP/1.1
Host: weblab.teipir.gr
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
Accept: image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.7,el;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-7,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://weblab.teipir.gr/


Cookie: PHPSESSID=e01760d780ea7c304bc571d2ddcd30b7
HTTP/1.x 200 OK
Date: Sun, 11 Dec 2005 23:51:28 GMT
Server: Apache
Last-Modified: Tue, 06 Dec 2005 22:37:17 GMT
Etag: "f1c41-17d0-ad842140"
Accept-Ranges: bytes
Content-Length: 6096
Keep-Alive: timeout=15, max=98
Connection: Keep-Alive
Content-Type: image/png

GET / HTTP/1.1
Host: weblab.teipir.gr
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;
q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.7,el;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-7,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: PHPSESSID=e01760d780ea7c304bc571d2ddcd30b7
Cache-Control: max-age=0
HTTP/1.x 200 OK
Date: Sun, 11 Dec 2005 23:52:32 GMT
Server: Apache
X-Powered-By: PHP/4.4.0-pl1-gentoo with Hardening-Patch
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,pre-check=0
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 2273
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-7
---------------------------------------------------------GET /site.css HTTP/1.1
Host: weblab.teipir.gr
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
Accept: text/css,*/*;q=0.1
Accept-Language: en-us,en;q=0.7,el;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-7,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://weblab.teipir.gr/
Cookie: PHPSESSID=e01760d780ea7c304bc571d2ddcd30b7
If-Modified-Since: Thu, 08 Dec 2005 17:37:57 GMT
If-None-Match: "498a-1182-bab30740"
Cache-Control: max-age=0
HTTP/1.x 304 Not Modified
Date: Sun, 11 Dec 2005 23:52:33 GMT
Server: Apache
Connection: Keep-Alive
Keep-Alive: timeout=15, max=100
Etag: "498a-1182-bab30740"
---------------------------------------------------------GET /images/nav/front_page.png HTTP/1.1
Host: weblab.teipir.gr
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
Accept: image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.7,el;q=0.3

10

1: HTTP
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-7,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://weblab.teipir.gr/
Cookie: PHPSESSID=e01760d780ea7c304bc571d2ddcd30b7
If-Modified-Since: Tue, 06 Dec 2005 22:37:17 GMT
If-None-Match: "f1c41-17d0-ad842140"
Cache-Control: max-age=0
HTTP/1.x 304 Not Modified
Date: Sun, 11 Dec 2005 23:52:33 GMT
Server: Apache
Connection: Keep-Alive
Keep-Alive: timeout=15, max=99
Etag: "f1c41-17d0-ad842140"

11

2:

2:

PSFTP

(http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html).
PUTTY . ,

, ,
.

10

11

User variables for ,


System variables ( ),

Path. Path ,

(Command Prompt).


. Edit,

PUTTY,
;.

, ;c:\Program Files\Putty 32bit

, ;c:\Program Files (x86)\Putty 64bit .


PSFTP SSH (Secure Shell)
.
13



(SFTP Server). , Web Server
weblab.teipir.gr.

Z:\web_pages,

. PSFTP .

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:

C:\>Z:
Z:\>cdweb_pages
Z:\web_pages>psftp?
PuTTYSecureFileTransfer(SFTP)client
Release0.60
Usage:psftp[options][user@]host
Options:
Vprintversioninformationandexit
pgpfpprintPGPkeyfingerprintsandexit
bfileusespecifiedbatchfile
bcoutputbatchfilecommands
bedon'tstopbatchfileprocessingiferrors
vshowverbosemessages
loadsessnameLoadsettingsfromsavedsession
luserconnectwithspecifiedusername
Pportconnecttospecifiedport
pwpasswloginwithspecifiedpassword
12forceuseofparticularSSHprotocolversion
46forceuseofIPv4orIPv6
Cenablecompression
ikeyprivatekeyfileforauthentication
noagentdisableuseofPageant
agentenableuseofPageant
batchdisableallinteractiveprompts

SFTP
weblab.teipir.gr .

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:

Z:\web_pages>psftplweb_tue39pwnotgonnatell weblab.teipir.gr
Usingusername"web_tue39".
Serverrefusedourkey
Remoteworkingdirectoryis/
psftp>ls
Listingdirectory/
drwxrxrx3rootweb4096Oct1118:52.
drwxrxrx3rootweb4096Oct1118:52..
drwxrxrx2web_tue39web4096Oct1118:52web_pages
psftp>cdweb_pages
Remotedirectoryisnow/web_pages
psftp>ls
Listingdirectory/web_pages
drwxrxrx2web_tue39web4096Oct1118:52.
drwxrxrx3rootweb4096Oct1118:52..
rwxrxrx1web_tue39web343Oct1118:52index.html
psftp>

cd,

lcd.

14

2:

mkdir

, .

1:
2:
3:
4:
5:
6:
7:
8:
9:

psftp>mkdirimages
mkdir/web_pages/images:OK
psftp>ls
Listingdirectory/web_pages
drwxrxrx3web_tue39web4096Oct1323:12.
drwxrxrx3rootweb4096Oct1118:52..
drwxrxrx2web_tue39DomainUsers4096Oct1323:12images
rwxrxrx1web_tue39web343Oct1118:52index.html
psftp>

, . PSFTP
. Notepad Windows (

, Word),

XHTML. ,
XHTML. ,

1:

<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=utf8"/>
<title>MyFirstWebPage</title>
</head>
<body>
<h1>HelloWorld</h1>
<p></p>
</body>
</html>

2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Z:\web_pages\index.html

/web_pages Web Server


. , PSFTP

put.

1:

psftp>putindex.html
2: local:index.html=>remote:/web_pages/index.html
3: psftp>

Web Browser

http://weblab.teipir.gr/~_/index.html. o Web Server


index.html, index.php login.php
, index.html
URL.
Web Browser ,
Z:\web_pages\images. , .

http://weblab.teipir.gr/projects/fastfood/fastfood_logo.jpg

http://weblab.teipir.gr/projects/fastfood/sandwich.jpg

http://weblab.teipir.gr/projects/fastfood/construction.gif

15


PSFTP
.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:

psftp>help
!runalocalcommand
byefinishyourSFTPsession
cdchangeyourremoteworkingdirectory
chmodchangefilepermissionsandmodes
closefinishyourSFTPsessionbutdonotquitPSFTP
deldeletefilesontheremoteserver
dirlistremotefiles
exitfinishyourSFTPsession
getdownloadafilefromtheservertoyourlocalmachine
helpgivehelp
lcdchangelocalworkingdirectory
lpwdprintlocalworkingdirectory
lslistremotefiles
mgetdownloadmultiplefilesatonce
mkdircreatedirectoriesontheremoteserver
mputuploadmultiplefilesatonce
mvmoveorrenamefile(s)ontheremoteserver
openconnecttoahost
putuploadafilefromyourlocalmachinetotheserver
pwdprintyourremoteworkingdirectory
quitfinishyourSFTPsession
regetcontinuedownloadingfiles
renmoveorrenamefile(s)ontheremoteserver
reputcontinueuploadingfiles
rmdeletefilesontheremoteserver
rmdirremovedirectoriesontheremoteserver
psftp>

, index.html

HTML img. , index.html,

Web Server . images

index.html.

src img :

URL, src="http://weblab.teipir.gr/~_/sandwich.jpg"

Web Server, src="/~_/images/sandwich.jpg"

(index.html), src="images/sandwich.jpg"

(addressing modes) .
construction.html index.html

.
construction.gif construction.html. index.html
(.. sandwich.jpg), , construction.html

16

3: Adobe Dreamweaver

3 : ADOBE DREAMWEAVER
SITE DREAMWEAVER

Edit > Preferences New Document.
:
Default document:

PHP

Default encoding:

Unicode (UTF-8)

Use when opening existing files that dont

Tick

specify an encoding

, Dreamweaver
Unicode (UTF-8).

17

SITE
Web Site project Site

. Site New Site.

18

3: Adobe Dreamweaver

1
Site .

Sites . ,
, .

Site , ,
Site http://weblab.teipir.gr/~username, username

19

2
, .
No, I do not want to use a server technology,

20

3: Adobe Dreamweaver

3
Site.

, Z web_pages.
, .
,

Web Server .

21

4
Internet

. FTP
Web Server. Web Server weblab.teipir.gr.

Web Server /webpages.



FTP login FTP password. Save Use

Secure FTP (SFTP). Web Server

/web_pages

, Test Connection

Web Server.

. firewall

SSH (TCP Port 22) Internet


Proxy Server.

22

3: Adobe Dreamweaver

5

.

, No, do not enable check in and check out.

23

6

.

Done.

24

3: Adobe Dreamweaver
6, Site ,
.


, New File.
Basic page HTML.

25


, .
:

Code

HTML

Design

(WYSIWYG Editor)

Split

HTML (Code view)


(Design view)

26

3: Adobe Dreamweaver

.
.

Web Server

Linux,


index.html ,

Web Site.

Site
Web Server . Dreamweaver Site

, .

Site (PUT). , ,
Web Server (GET).

GET

Web Server .

,
. ,

Synchronize.

Site
, (GET PUT)

,
. Web Server Site
, URL Web Browser .

27


URL:
http://weblab.teipir.gr/~web_t31/index.html

: ,
server
web browser.

28

3: Adobe Dreamweaver

DREAMWEAVER

(fast food)
.
, ,

.

, ,

PHP ( ) MySQL (
). ,

),

- .
index.html web site BODY.
XHTML CSS

2x2 . id
PageLayout.
. .

id=SiteLogo

height: 66px width: 900px

id=SiteOptions

id=PageBody

width: 120px

width: 780px

- (SiteLogo),
. ,
. images,

fastfood_logo.jpg

images .
65 pixels, height width.
(SiteOptions) .

, :

index.html.

construction.html.

construction.html.

contact.html.

29


(PageBody), :

( ),
1 (Heading 1).

sandwich.jpg images.

, contact.html.

contact.html index.html SiteLogo


SiteOptions. PageBody ,

.
.
construction.html index.html SiteLogo
SiteOptions. PageBody

, .
construction.gif images.

30

3: Adobe Dreamweaver

CSS

(
) .

, CSS. ,
.

(root directory),
index.html.

stylesheets. .

CSS , New

File. Basic page

CSS. fastfood.css .

/stylesheets/fastfood.css

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:

body{
backgroundcolor:#FFFFFF;
fontfamily:Verdana,Arial,Helvetica,sansserif;
fontsize:12px;
lineheight:16px;
margintop:0;
marginbottom:0;
marginleft:0;
marginright:0;
color:#00000;
left:0;
paddingleft:0;
paddingright:0;
paddingtop:0;
paddingbottom:0;
}

a{color:#0C18F5;}
a:visited{color:#C2106F;}
a:hover{color:#147327;textdecoration:underline;}

img{border:0;}

table{
marginleft:auto;
marginright:auto;
}

p{
fontfamily:Verdana,Arial,Helvetica,sansserif;
fontsize:12px;
lineheight:16px;
margintop:0;
marginbottom:0;
marginleft:0;
marginright:0;
}

p.center{textalign:center;}
31

40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:

h1{
fontfamily:Verdana,Arial,Helvetica,sansserif;
fontsize:18px;
color:#59594B;
margintop:8;
marginbottom:8;
marginleft:0;
marginright:0;
}

.small_text{
fontfamily:Verdana,Arial,Helvetica,sansserif;
fontsize:10px;
lineheight:14px;
color:#00000
}

. XHTML
small_text ;


CSS .
HEAD :

<link href="/~_/stylesheets/fastfood.css" rel="stylesheet" type="text/css" />


style small_text .
<p class=small_text>Hello World</p>
/ small_text p body; , ;

site server
web browser.

CSS id
SiteLogo, SiteOptions PageBody.
id PageLayout. XHTML.

CSS,
fastfood.css.

, .

32

4: PHP ( ..)

4 : PHP ( ..)
,

, (scripts),

Browser
Server (Server-Side execution), client (Client-Side execution).

PHP (Server-Side scripting language),

SESSIONS

PHP

. , ,


, .

Server .

.
,
,
(trapdoor hashing functions). MD5 (Message
Digest 5).

admin (/admin).


. PHP ,

New File. Dynamic page


PHP. login.php .
/admin/login.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:

<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML 1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=utf8"/>
<title></title>
<linkhref="/~_/stylesheets/fastfood.css"rel="stylesheet"type="text/css"
/>
<styletype="text/css">
<!
tr{padding:2px;}

td{
margin:2px;
padding:2px;
border:1pxsolid#000000;
}
>
</style>
</head>

33

20:
21:
22:
23:
24:
25:
26:

<body>
<?php

if(isset($_GET["LoginError"])){
switch($_GET["LoginError"]){

case"Failed":

echo'<pclass="red_text">
,.</p>';

break;

case"Unauthorized":

echo'<pclass="red_text">
.</p>';

break;

default:

echo'<pclass="red_text">.</p>';

break;
}
}

?>
<p>&nbsp;</p>
<formname="LoginBox"id="LoginBox"method="post"action="login_check.php">

<tablestyle="margin:auto;">

<tr><tdcolspan="2"><p></p></td></tr>
<tr>
<tdstyle="textalign:right"><p>:</p></td>
<tdstyle="textalign:left"><inputtype="text"name="UserName"id="UserName"
maxlength="12"/></td>
</tr>
<tr>
<tdstyle="textalign:right"><p>:</p></td>
<tdstyle="textalign:left"><inputtype="password"name="LoginPassword"
id="LoginPassword"size="8"maxlength="8"/></td>
</tr>
<tr>
<tdcolspan="2"style="textalign:center">
<p><inputtype="submit"name="LoginSubmit"id="LoginSubmit"value=""
/></p>
</td>
</tr>
</table>

</form>
</body>
</html>

27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:

login.php

.

login_check.php.

PHP Web Server -


login_check.php.

PHP login.php
GET LoginError ( isset).

(switch-case). , LoginError
34

4: PHP ( ..)
,
. ,

Browser URL login.php?LoginError=Failed


login.php?LoginError=Unauthorized .
.

, includes validate_user.php.

PHP
XHTML. ,

.
/fastfood/includes/validate_user.php

1:
2:
3:

<?php

$USERS[panos]=array("FirstName"=>"","LastName"=>"",
"Password"=>"zebra123","Position"=>"Administrator");
$USERS[xristina]=array("FirstName"=>"","LastName"=>"",
"Password"=>"tango678","Position"=>"Administrator");
$USERS[george]=array("FirstName"=>"","LastName"=>"",
"Password"=>"foxtrot981","Position"=>"Sales");

functiongetUser($username,$password){
global$USERS;

if((isset($USERS[$username]))
&&($USERS[$username][Password]==$password))

return$USERS[$username];
else

returnnull;
}

?>

4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:

, $USERS,
.

- .

getUser
$USERS,

global. ( ,

isset) ,
.

, null.

, ,
.

, functions.php includes.
.
. :
o

isAdministrativeUser

.
o

forceAdministrativePage isAdministrativeUser
, ,
35


HTTP Headers
10 .


( ).
/includes/functions.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:

<?php

@session_start();

functionisAdministrativeUser(){
if(isset($_SESSION['Authenticated'])&&

($_SESSION["Authenticated"]==true)&&

($_SESSION['Position']=="Administrator")){

returntrue;
}
else{

returnfalse;
}
}

functionforceAdministrativePage(){
if(!isAdministrativeUser()){

header("ContentType:text/html;charset=utf8");

header("Refresh:10;url=/~_/admin/login.php");

die(".");
}
}

?>

admin login_check.php.
.

/admin/login_check.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:

<?php

if(isset($_POST['UserName'])&&isset($_POST['LoginPassword'])){
include_once("../includes/validate_user.php");

$username=strtolower(trim($_POST['UserName']));
$password=trim($_POST['LoginPassword']);

$AuthUser=getUser($username,$password);

if(isset($AuthUser)){

@session_start();

$_SESSION['Authenticated']=true;

$_SESSION['UserName']=$username;

$_SESSION['FirstName']=$AuthUser['FirstName'];

$_SESSION['LastName']=$AuthUser['LastName'];

$_SESSION['Position']=$AuthUser['Position'];

header("Location:/~_/admin/index.php");

die();
}
}

header("Location:/~_/admin/login.php?LoginError=Failed");

?>
36

4: PHP ( ..)

login.php.
, validate_user.php

include_once.
,

. , POST
trim (
, ) strtolower (

).

getUser . ,
.

, (session_start)

. admin/index.php

. die
. ,

logout.php,
.

,
.
/admin/logout.php

1:
2:
3:
4:
5:
6:
7:

<?php
session_start();
session_unset();
session_destroy();
setcookie(session_name(),'',time()42000,'/');
header("Location:/~_/index.html");
?>

left.php

SiteOptions PHP
left.php SiteOptions.
/includes/left.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:

<p><ahref="/~_/index.html"></a></p>
<p><ahref="/~_/view_categories.php"></a></p>
<p></p>
<p><ahref="/~_/contact.html"></a></p>
<br/>
<?php

include_once("functions.php");

if(!isAdministrativeUser()){
echo'<p><ahref="/~_/admin/login.php"></a></p>';
}else{
echo'<p><ahref="/~_/admin/index.php"></a></p>';
echo'<p><ahref="/~_/logout.php"></a></p>';
}
?>

PHP,

.
,

37


.
,

admin, index.php

/admin/index.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:

<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=utf8"/>
<title></title>
<linkhref="/~_/stylesheets/fastfood.css"rel="stylesheet"type="text/css"
/>
</head>
<body>
<p><?php

include_once("../includes/functions.php");

if(isAdministrativeUser()){
echo".";
var_dump($_SESSION);//
?>
<h2style="textalign:center"></h2>
<pstyle="textalign:center"><a
href="/~_/admin/show_products.php"></a></p>
<pstyle="textalign:center"></p>
<?php

}else{
echo".";
die();/**/
}
?></p>
<!>
</body>
</html>

var_dump

(debugging).

Browser
Server.


. ,
,

, functions.php

. ,
$_SESSION[Position]
.

38

5: PHP

5 : PHP

PHP, MySQL.

39

NAVICAT MYSQL SERVER



Navicat ,
.
, .

. , :


( ).

).


40

5: PHP
,
(New Connection).

, .

41

Connection Name:

web_xxx

Host name/IP address:

weblab.teipir.gr

Port:

FQDN IP

3306

TCP


User name:

web_xxx

Password:
Save Password:

( )

xxxxxxxx


,
Test Connection .

, .
- Advanced
Settings.

Settings Save Path:


Z:\

,
)
Encoding:

65001 (UTF-8)

Use MySQL character set:


(
, )

Use Compression:


Auto Connect

42

5: PHP

,
. - Tables

43


,
, .

, Filter Wizard.

/ ,
,
. ,

, Click here (ctrl+r) to apply


44

5: PHP
Control+R.
.

.
. MySQL.

Save Save As. ,
.

,
.

45



. Query
. .

SQL ,
Run.

SELECT ,

, .

46

5: PHP

(.. INSERT, UPDATE, REPLACE)

.
.

: (
), decimal.

47

( )

.
,
(categories),

(products).
( categories.id products.cat_id).

Navicat, ,
SQL. .

(Primary keys) int(10) unsigned auto increment


( ).

Table "categories" DDL

1:
2:
3:
4:
5:

CREATETABLE`categories`(
`id`int(10)unsignedNOTNULLauto_increment,
`title`varchar(60)collateutf8_general_ciNOTNULL,
PRIMARYKEY(`id`)
)ENGINE=MyISAMDEFAULTCHARSET=utf8COLLATE=utf8_bin;

: UTF8 2 bytes,
(, , ), 1 byte.
(bytes)
char/varchar, .
(ISO-8859-7).
DDL.

48

5: PHP

Table "products" DDL

1:
2:
3:
4:
5:
6:
7:
8:
9:

CREATETABLE`products`(
`id`int(10)unsignedNOTNULLauto_increment,
`cat_id`int(10)unsignedNOTNULL,
`title`varchar(60)collateutf8_general_ciNOTNULL,
`price`decimalNOTNULL,
`description`textcharactersetutf8NOTNULL,
`available`enum('True','False')NOTNULLdefault'True',
PRIMARYKEY(`id`)
)ENGINE=MyISAMDEFAULTCHARSET=utf8COLLATE=utf8_bin;

products.price decimal 2
.

products.available, enum

(False, True) .

,
.

49


PHP,

PHP.

includes .
mydbclass.php.
.

/includes/mydbclass.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:

<?php

classmyDB{

private$dbUser='';
private$dbPassword='';
private$dbHost='';
private$dbName='';
private$dbLink=false;

publicfunction__construct($host,$user,$password){

$this>dbUser=$user;

$this>dbPassword=$password;

$this>dbHost=$host;

$this>Connect();
}

publicfunctionConnect(){

$this>dbLink=mysql_connect($this>dbHost,$this>dbUser,$this
>dbPassword);

if($this>dbLink==false)

die('Couldnotconnect:'.mysql_error());
}

publicfunctionSelectDB($dbname){

$this>dbName=$dbname;

mysql_select_db($this>dbName)

ordie('Couldnotselectdatabase:'.$this>dbName);
}

publicfunctionClose(){

mysql_close($this>dbLink);

publicfunctionPrintQueryResults($query){

$result=$this>MakeQuery($query);

echo"\n<table>\n";

50

5: PHP

44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:

echo"<thead>\n";

echo"<tr>\n";

echo"<th><strong>/</strong></th>\n";

$fields=$this>GetFieldNames($result);

foreach($fieldsas$field_name){

echo"<th><strong>$field_name</strong></th>\n";

echo"</tr>\n";

echo"</thead>\n";

echo"<tbody>\n";

$i=1;

while($record=$this>GetRecord($result)){

echo"<tr>\n";

echo"<tdvalign=\"top\"><strong>$i.</strong></td>\n";

foreach($recordas$field_value){

echo"<tdvalign=\"top\">$field_value</td>\n";

echo"</tr>\n";

$i++;

echo"</tbody>\n";

echo"</table>\n";
}

publicfunctionMakeQuery($query){

$result=mysql_query($query,$this>dbLink)ordie("Query'$query'failed:
".mysql_error());

return$result;
}

publicfunctionGetRecord($result){

returnmysql_fetch_array($result,MYSQL_ASSOC);
}

publicfunctionGetFieldNames($result){

$fields=$this>GetFieldCount($result);

for($i=0;$i<$fields;$i++){

$FieldNames[]=mysql_field_name($result,$i);

return$FieldNames;
}

publicfunctionGetFieldCount($result){

returnmysql_num_fields($result);
}

publicfunctionGetRecordCount($result){

returnmysql_num_rows($result);
}

51

105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:

publicfunctionGetLastInsertID(){

returnmysql_insert_id($this>dbLink);
}

publicfunctionGetAffectedRows(){

returnmysql_affected_rows($this>dbLink);
}

publicfunctionGetResultAsArray($result){

while($record=$this>GetRecord($result)){

$data[]=$record;

return$data;
}
}

?>
, mydbclass-test.php includes
.

/includes/mydbclass-test.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:

<?php

include_once("mydbclass.php");

$db=newmyDB('weblab.teipir.gr','web_mon11','xxxxx');
$db>SelectDB('web_mon11');

$query="SELECT*FROMproducts";
$db>PrintQueryResults($query);

$query="SELECT*FROMproductsWHEREid=1";
$result=$db>MakeQuery($query);

$record=$db>GetResultAsArray($result);
$record=$db>GetRecord($result);
echo$record['product_name'];

$query="SELECT*FROMproducts";
$result=$db>MakeQuery($query);
$records=$db>GetResultAsArray($result);

print_r($records);
echo$records[2]['product_name'];

$db>Close();

?>

( ). MakeQuery
.

52

5: PHP
dbconnect.php,
.
.
/includes/ dbconnect.php

1:
2:
3:
4:
5:
6:
7:
8:

<?php

include_once("mydbclass.php");

$db=newmyDB('weblab.teipir.gr','web_mon11','xxxxx');
$db>SelectDB('web_mon11');

?>

,
, - myDB.

53



.
.

. ,

( view_categories.php).
/view_categories.php

1:

<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=utf8"/>
<title></title>
<linkhref="/~_/stylesheets/fastfood.css"rel="stylesheet"type="text/css"
/>
</head>

<body>
<h1></h1>
<p>
.</p>
<ol>
<?php

require_once("includes/dbconnect.php");

$query="SELECT*FROMcategoriesORDERBYtitleDESC";
$result=$db>MakeQuery($query);
$categories=$db>GetResultAsArray($result);

foreach($categoriesas$category){
$query="SELECTCOUNT(*)ASProductCountFROMproductsWHERE
cat_id=".$category['id'];
$result=$db>MakeQuery($query);
$record=$db>GetRecord($result);

echo'<li><a
href="view_products.php?cat_id='.$category['id'].'">'.$category['title'].'</a>
('.$record['ProductCount'].')</li>';
}

?>
</ol>
</body>
</html>

2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:

27:
28:
29:
30:
31:
32:

.
(

view_products.php).
/view_products.php

54

5: PHP

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:

<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=utf8"/>
<title></title>
<linkhref="/~_/stylesheets/fastfood.css"rel="stylesheet"type="text/css"
/>
</head>

<body>
<tablestyle="margin:auto">
<tr>
<tdstyle="borderbottom:#9900002pxsolid;textalign:center">/</td>
<tdstyle="borderbottom:#9900002pxsolid;"></td>
<tdstyle="borderbottom:#9900002pxsolid;textalign:right"></td>
</tr>
<?php

require_once("includes/dbconnect.php");

$catid=$_GET['cat_id']+0;

$query="SELECT*FROMproductsWHEREcat_id=$catidORDERBYtitleDESC";
$result=$db>MakeQuery($query);

if($db>GetRecordCount($result)){
$products=$db>GetResultAsArray($result);

$i=1;

foreach($productsas$product){

echo'<trstyle="margin:4px;">';

echo'<tdstyle="textalign:center;verticalalign:top;fontsize:110%;font
weight:bold;">'.$i.'.</td>';

echo'<tdvalign="top">';

echo'<p><strong>'.$product['title'].'</strong></p>';

echo'<pclass="small_text"><i>'.$product['description'].'</i></p>';

echo'</td>';

echo'<tdstyle="textalign:right;verticalalign:top;
color:#000099;"><strong>';

if($product['available']=='True')

echosprintf("%01.2f",$product['price']);

else

echo'';

echo'&euro;</strong></td>';

echo'</tr>';

$i++;
}
}else{
echo'<tr><tdcolspan="4"style="textalign:center">
</td></tr>';
}

?>
</table>
</body>
</html>


55

( show_products.php).
view_categories.php view_products.php.
.

onchange . ,

document.getElementById(catselform).submit(); browser
( action ).

(selected=selected)

,
onchange .
option , ,

0.

(submit), ,
.
/admin/show_products.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:

<?php
include_once("../includes/functions.php");
ForceAdministrativePage();
?>
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=utf8"/>
<title></title>
<linkhref="/~_/stylesheets/fastfood.css"rel="stylesheet"type="text/css"
/>
</head>

<body>
<?phprequire_once("../includes/dbconnect.php");?>
<formaction="<?=$_SERVER['PHP_SELF']?>"method="get"name="catselform"
id="catselform"enctype="application/xwwwformurlencoded">
<h2style="textalign:center"></h2>
<pstyle="textalign:center"class="small_text">(<ahref="index.php"
target="mainFrame"></a>)</p>
<p>&nbsp;</p>
<pstyle="textalign:center">
<selectname="catid"id="catid"
onchange="document.getElementById('catselform').submit();">
<optionvalue="0"></option>
<?php

$query="SELECT*FROMcategoriesORDERBYtitleDESC";
$result=$db>MakeQuery($query);
$categories=$db>GetResultAsArray($result);

if(isset($_GET['catid']))
$catid=$_GET['catid']+0;
else
$catid=0;

56

5: PHP

33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:

foreach($categoriesas$category) {
$query="SELECTCOUNT(*)ASProductCountFROMproductsWHERE
cat_id='".$category['id']."'";
$result=$db>MakeQuery($query);
$record=$db>GetRecord($result);

if($category['id']==$catid)

$selection='selected="selected"';
else

$selection='';

echo'<optionvalue="'.$category['id'].'"'.$selection.'>'.$category['title'].'
('.$record['ProductCount'].')</option>';

?>
</select>
</p>
</form>
<?php

if($catid!=0){
?>
<p>&nbsp;</p>
<h2style="textalign:center"></h2>
<pstyle="textalign:center"class="small_text">(<a
href="product_edit.php?catid=<?=$catid?>"></a>)</p>
<p>&nbsp;</p>
<tablestyle="margin:auto">
<tr>
<tdstyle="borderbottom:#9900002pxsolid;textalign:center">/</td>
<tdstyle="borderbottom:#9900002pxsolid;"></td>
<tdstyle="borderbottom:#9900002pxsolid;textalign:right"></td>
<tdstyle="borderbottom:#9900002pxsolid;textalign:right"></td>
</tr>
<?php

$query="SELECT*FROMproductsWHEREcat_id='$catid'ORDERBYtitleDESC";
$result=$db>MakeQuery($query);

if($db>GetRecordCount($result)){

$products=$db>GetResultAsArray($result);

$i=1;

foreach($productsas$product){

echo'<trstyle="margin:4px;">';

echo'<tdstyle="textalign:center;verticalalign:top;fontsize:110%;
fontweight:bold;">'.$i.'.</td>';

echo'<td>';

echo'<p><strong>'.$product['title'].'</strong></p>';

echo'<pclass="small_text"><i>'.$product['description'].'</i></p>';

echo'</td>';

echo'<tdstyle="textalign:right;verticalalign:top;color:#000099;
paddingleft:10px;paddingright:10px"><strong>';

if($product['available']=='True')

echosprintf("%01.2f",$product['price']);

else

echo'';

echo'&euro;</strong></td>';

echo'<tdstyle="paddingleft:10px"><a
57

89:

90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:

href="product_edit.php?catid='.$catid.'&pid='.$product['id'].'"></a>';

echo'<a
href="product_db_action.php?action=delete&catid='.$catid.'&pid='.$product['id'].'"
onclick="returnconfirmDelete();"></a></td>';

echo'</tr>';

$i++;

}
}else{

echo'<tr><tdcolspan="4"style="textalign:center">
</td></tr>';
}

?>
</table>
<?
}
?>
<scripttype="text/javascript"language="javascript">

functionconfirmDelete(){
returnconfirm('!!!\n\n/
;');

</script>
</body>
</html>

88-89
.

.
, event onclick

JavaScript 104-106. confirm


(
true) ( false). return

event onclick, ,

, browser .

58

5: PHP


product_edit.php admin

. 9-39

, pid

GET.

, $available_checked (HTML

checkbox) $tbgcolor ( ).

. , $pid (

) new.

UPDATE INSERT .
, ,

.
/admin/ product_edit.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:

<?php

require_once("../includes/functions.php");

ForceAdministrativePage();

require_once("../includes/dbconnect.php");

if(isset($_GET['pid'])){
$page_title="";

$query='SELECT*FROMproductswhereid="'.$_GET['pid'].'"';
$result=$db>MakeQuery($query);
$products=$db>GetResultAsArray($result);
$product=$products[0];

$product_title=$product['title'];
$product_description=$product['description'];
$pid=$product['id'];
$catid=$product['cat_id'];
$price=$product['price'];
$availability=$product['available'];
if($availability=="True")

$available_checked='checked="checked"';
else

$available_checked='';
$tbgcolor="#CCFF99";
}else{
$page_title="";
$product_title='';
$product_description='';
$pid='new';
$catid=0;
$price='';
$available_checked='';
$tbgcolor="#FFFFFF";

?><!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
59

39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:

<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=utf8"/>
<title><?=$page_title?></title>
<linkhref="/~_/stylesheets/fastfood.css"rel="stylesheet"type="text/css"
/>
<scripttype="text/javascript"language="javascript">

functionValidateForm(){
if((document.getElementById('product_title').value=="")

||(document.getElementById('price').value=="")){

alert("!\n\n.");

returnfalse;
}else

returntrue;
}
</script>
<styletype="text/css">
<!
tr{padding:2px;}

td{
margin:2px;
padding:2px;
border:1pxsolid#000000;
}
>
</style>
</head>

<body>
<h1style="textalign:center"><?=$page_title?></h1>
<pstyle="textalign:center"class="small_text">(<ahref="index.php">
</a>)</p>
<p>&nbsp;</p>
<formaction="product_db_action.php"method="post"name="LoginBox"id="LoginBox"
onsubmit="returnValidateForm()">
<inputtype="hidden"name="pid"value="<?=$pid?>"/>
<tablestyle="textalign:center;border:thinsolid#000000;background
color:<?=$tbgcolor?>;">

<trbgcolor="#FFCC00"><tdcolspan="2"><pstyle="textalign:center"><strong>
</strong></p></td></tr>

<tr>
<tdstyle="textalign:right"><p>:</p></td>
<td><inputtype="text"name="product_title"id="product_title"
value="<?=$product_title?>"maxlength="20"/></td>
</tr>

<tr>
<tdstyle="textalign:right"><p>:</p></td>
<tdstyle="textalign:left"><selectname="catid">
<?php

$query='SELECT*FROMcategories';
$result=$db>MakeQuery($query);
$categories=$db>GetResultAsArray($result);

foreach($categoriesas$category){
if($category['id']==$catid)

$category_selected='selected="selected"';
60

5: PHP

95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:

else

$category_selected='';
echo'<optionvalue="'.$category["id"].'"'.$category_selected.'>'.
$category["title"].'</option>';
}

?>
</select></td>
</tr>

<tr>
<tdstyle="textalign:right"><p>:</p></td>
<td><inputtype="text"name="price"id="price"value="<?=$price?>"maxlength="4"
size="4"/></td>
</tr>

<tr>
<tdstyle="textalign:right"><p>:</p></td>
<td><textarearows="5"cols="15"name="description"
id="description"><?=$product_description?></textarea></td>
</tr>

<tr>
<tdstyle="textalign:right"><p>&nbsp;</p></td>
<tdstyle="textalign:left"><inputtype="checkbox"name="available"id="available"
<?=$available_checked?>/></td>
</tr>

<tr>
<tdcolspan="2"style="textalign:center">
<p><inputtype="submit"name="LoginSubmit"value=""/>
<inputtype="reset"name="rbutton"value=""/>
</p></td>
</tr>
</table>
</form>
</body>
</html>

61

,

product_db_action.php admin
. .

POST

. , GET

pid. GET action

( /). /

, POST pid .

, pid catid

$_REQUEST, GET POST. ,


,

/admin/product_db_action.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:

27:
28:
29:
30:
31:
32:
33:
34:
35:

<?php

require_once("../includes/functions.php");
ForceAdministrativePage();

$pid=$_REQUEST['pid'];
$catid=$_REQUEST['catid'];

if(isset($_GET['action'])&&($_GET['action']=="delete")){
$query="DELETEFROMproductsWHEREid='".($pid+0)."'";
}else{
if(isset($_POST['available']))

$available='True';
else

$available='False';

$product_title=$_POST['product_title'];

$price=str_replace(",",".",trim($_POST['price']));
$price=$price+0;
$description=$_POST['description'];

if($_POST[pid]=="new"){

$query="INSERTINTOproducts(title,cat_id,price,description,available)

values('$product_title',$catid,'$price','$description','$available')";
}else{

$query="UPDATEproductsSETtitle='$product_title',price='$price',
cat_id='$catid',description='$description',available='$available'WHERE
id='".($pid+0)."'";

}
}

require_once("../includes/dbconnect.php");
$result=$db>MakeQuery($query);

header("Location:show_products.php?catid=$catid");

?>

62

5: PHP
,
. , :
1.

Trim, .

2.

String Replace, ,

3.

0.

, ,
.. 2,34 2.34, a3,14 0.

63

You might also like