Рабочая тетрадь курса
Рабочая тетрадь курса
Рабочая тетрадь курса
. 1.
v.08.2009
. 1.
1: Apache .
. .... 7
2: .................................................. 23
3: PHP ........... 49
4: PHP ...... 59
5: PHP ........................................... 69
6: HTTP ........................................... 83
............................................................................................... 93
HTML CSS
HTML
HTML/XHTML CSS ,
W3C
, ,
(, , SQL)
Web-.
web-
XML XSLT.
Web Office 2007
mySQL
Microsoft Virtual PC
http://www.microsoft.com/windows/virtualpc/default.mspx
Microsoft Virtual PC
Microsoft Virtual PC
Microsoft Virtual PC
[Right ALT] + [Enter]
Alt + Ctrl + Del
[Right ALT] + [Del]
1: .
Apache.
.
1
1: .
Apache. PHP.
PHP
Apache
Apache
PHP
PHP Apache
PHP Apache
PHP
PHP
1: .
?
?
""?
" "?
?
""?
Apache?
Apache?
1: .
- HTML?
<html>
<head>
<title>
</title>
</head>
<body>
<p>
HTML-
</p>
</body>
</html>
index.html
<html>
<p>
HTML-
</p>
</body>
</html>
- PHP?
<html>
<head>
<title>
</title>
</head>
<body>
<p>
PHP :
<?print PHP_VERSION;?>
</p>
</body>
</html>
php
index.php
<html>
<p>
PHP : 5.2.3
</p>
</body>
</html>
10
1: .
Apache?
http://httpd.apache.org
Apache
11
1: .
Apache
12
1: .
Apache. .
1
1. : (Start) -> (Control panel) ->
(Administrative tools) -> (Services)
2. Apache
3.
(Start)
4. , (Start)
2
1.
2.
http://localhost
Enter
3. ,
3
1. (Services)
(Stop)
2. :
a. (Start) -> (Run)
b.
cmd
Enter
3.
net start apache
Enter
4. 3 4 2
13
1: .
Apache
1.
C:\Program files\Apache Group\Apache\htdocs
2.
3. CD
4. CD_drive:\work work.exe
5. work.exe
6. work.exe
7. ,
14
1: .
httpd.conf
.htaccess
15
1: .
, , .htaccess
1
1.
2. :
Options Indexes FollowSymLinks
DirectoryIndex index.php
3. .htaccess
4.
5.
http://localhost
Enter
6. , You don't have permission to access
2
1.
2.
3.
4.
5.
16
.htaccess
Indexes -()
3 4 1
, htdocs
1: .
PHP?
PHP
17
1: .
PHP Apache
18
1: .
PHP
HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z\ (5.2.0)
HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y\ (5.2.0)
HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x\ (5.2.0)
HKEY_LOCAL_MACHINE\SOFTWARE\PHP\
php.ini
Windows (, :\Windows)
19
1: .
PHP
20
1: .
1
1.
2. :
<?php
phpinfo();
?>
3. info.php
C:\Program files\Apache Group\Apache\htdocs
4.
5.
http://localhost/info.php
Enter
21
1: .
PHP Apache
httpd.conf
php.ini
22
2: PHP
PHP
2
2: PHP
PHP
24
2: PHP
PHP
,
php- . :
<?php
// .
?>
<?
?>
"short_open_tag" php.ini
"on".
XML.
<%
<SCRIPT LANGUAGE="PHP">
%>
</SCRIPT>
"asp_tags" php.ini
"on".
PHP
:
;
;
:
1; 2;
25
2: PHP
:
<?php
#
//
phpinfo(); //
?>
:
<?php
/*
,
phpinfo();
*/?>
/* */
<h1><?= " " ?></h1> // ,
<h1><?php echo " " ?></h1>
26
2: PHP
($)
$
. ,
,
.
$i
$_1
$_myVar
$firstName
$x525_676
$1
$7Lucky
$~password
$Last!Visit
$my-var
$foo = 'Bob';// $foo Bob
27
2: PHP
mod2\vars.php :
1
1. name ,
"" ( !)
2. age ,
40
2
1. echo( print)
" : _", : " : "
name
2.
" _ ", : " 40 "
age
3. age.
28
2: PHP
PHP .
:
boolean ()
integer ( )
float ( )
string ()
:
array ()
object ()
:
resource
NULL
29
2: PHP
: boolean
. -
TRUE, FALSE.
$foo = True; // $foo TRUE
TRUE FALSE -.
,
FALSE:
0 ()
0.0 ()
"0"
NULL (
)
TRUE
: integer float
$int = 1234; //
$int = -123; //
$int = 0123; //
$int = 0x1A; //
// ()
$flt = 1.234;
$flt = 1.2e3;
$flt = 7E-10;
30
2: PHP
: string ( )
echo " ";
: string ( )
echo ' ';
echo '
Enter, ';
echo ' : \n ';
$ = "";
echo ' $a ';
31
2: PHP
mod2\types.php :
1
1. name ,
"" ( !)
2. age ,
40
2
1. echo( print)
" : _", : " : "
name
2.
" _ ", : " 40 "
age
3. ,
4. ,
HTML- ( Intrnet Explorer: -> HTML-)
32
2: PHP
: string (heredoc)
$str = <<< LABEL
,
,
heredoc-.
HTML- <PRE>.
,
.
LABEL;
, .
.
( ), .
: NULL
NULL :
NULL.
-
.
unset().
echo $a;
$a = null;
$a = 1;
unset($a);
echo $a;
33
2: PHP
$beer = 'Heineken';
echo "$beer's taste is great"; //?
//?
$str = 'Hello, world!';
//
$first = $str{0};// H
//
$third = $str{2};// l
//
$len = strlen($str);// 13
$pos = $len 1;// 12
$last = $str{$pos};// !
$last = $str{strlen($str)-1};// !
34
2: PHP
:
$a + $b // $a $b
$a - $b // $a $b
$a * $b // $a $b
$a / $b // $a $b
$a % $b //
$a $b
5/2 2.5, 5%2 1
$a += $b // , $a = $a + $b.
.
:
$a = "Hello ";
$b = $a . "World!"; // $b
Hello World!
$a = "Hello ";
$a .= "World!";
Hello World!
// $a
$a = "Hello";
$b = "World!";
print $a . " " . $b;// Hello World!
/* */
echo $a, " ", $b;
35
2: PHP
isset(_) - ,
. true false.
empty(_) ,
- . true
false.
gettype(_). :
NULL
integer
string
double //float
boolean
settype(_, "") -
.
() _ // (int) $stringvar
36
2: PHP
: if
True
False
: if
if ()// true false
;
$shop = true;
if ($shop)
echo " ";
echo " ";
if (){
1;
2;
}
$shop = true;
if ($shop){
echo " ";
echo " ";
}
37
2: PHP
:
$a == $b // TRUE $a $b.
$a === $b // TRUE $a $b
$a != $b // TRUE $a $b.
$a !== $b // TRUE $a $b
, .
$a < $b // TRUE $a $b.
:
$a and $b
$a or $b
TRUE.
// TRUE $a, $b
!$a
// TRUE $a TRUE.
$a && $b
$a || $b
TRUE.
// TRUE $a, $b
38
2: PHP
: if-else
False
True
: if else
if ()
;
else
;
$shop = "open";
if ($shop == "open"){
echo " ";
}else{
echo " ";
}
echo " ";
? 1 : 2;
$a = 1;$b = 2;
$result = ($a > $b) ? $a : $b;
39
2: PHP
: elseif
if
TRUE
TRUE
FALSE
elseif
?
FALSE
else
: elseif
$day = 2;
if ($day == 1)
print("");
elseif ($day == 2)
print("");
elseif ($day == 3)
print("");
elseif ($day == 4)
print("");
elseif ($day == 5)
print("");
elseif ($day == 6)
print("");
elseif ($day == 7)
print("");
else
print(" ");
40
2: PHP
if-elseif-else
mod2\if.php :
1
1. age
2. age
2
1. if, :
" "
, age
18 59()
2. if, :
" "
, age 59
3. if, :
" "
, age
1 17()
4. if, :
" " , age
41
2: PHP
: switch
case a
true
break
break
break
false
case b
true
false
case z
true
false
default
: switch
switch (){
case 1:
1;
[break;]
case 2:
2;
[break;]
[default: ]
}
$day = 4;
switch ($day) {
case 1: print(""); break;
case 2: print(""); break;
case 3: print(""); break;
42
2: PHP
switch
mod2\switch.php :
1
1. mod2\switch.php
2. day
2
1. switch :
" ",
day
1 5()
2. :
" ",
day 6 7
3. :
" ",
day
1 7()
43
2: PHP
Array ()
$user[]= "John";// 0
$user[]= "root";// 1
$user[]= "p@ssw0rd";// 2
//,
$user[0]= "John";// 0
$user[1]= "root";// 1
$user[2]= "p@ssw0rd";// 2
$user[] = "312-34-85";// 3
//
$user = array("John", "root", "p@ssw0rd");
//,
$user = array(0=>"John", 1=>"root",
2=>"p@ssw0rd");
$cnt = count($user); //
echo $user[1];//root
Array ():
$user["name"]= "John";
$user["login"]= "root";
$user["password"]= "p@ssw0rd";
//
$user[] = "312-34-85";// 0
echo $user["name"];//John
//,
$user = array(
"name"=>"John",
"login"=>"root",
"password"=>"p@ssw0rd",
"312-34-85");
44
2: PHP
mod2\array.php :
1
1. bmw :
"model"
"speed"
"doors"
"year"
2. :
"X5", 120, 5, "2006"
3. toyota opel bmw.
4. toyota :
"Carina", 130, 4, "2007"
5. opel :
"Corsa", 140, 5, "2007"
2
:
name - model - speed - doors - year, :
bmw - 120 - 5 2006
45
2: PHP
Array ():
$users = array(
0 => array(
"login" => "Administrator",
"password" => "h734yuiw8"
),
1 => array(
"login" => "John",
"password" => "78dfud776s"
)
);
46
2: PHP
defined("_") .
echo PI //3.14
mod2\constant.php
:
1
1.
2
1. , ,
2.
3.
47
2: PHP
48
3: -
PHP -
3
3: -
PHP
for
: for
while
: while
do...while
:
foreach
:
50
3: -
:
++
--
PRE /
++$a
$a
$a.
--$a
$a
$a.
POST /
$a++
$a,
$a .
$a--
$a,
$a .
$a = 1;
echo " : " . $a++; // : 1
echo " : " . $a; // : 2
$a = 1;
51
3: -
: for
1
2...
4...
for ( ; ; ){
1;
3...
2;
...
}
$sum = 1;
for ($i=1; $i<=30; $i++){
$sum += 3;
print($sum);
}
for
mod3\for.php :
1
1. for, 1 50
52
3: -
: while
while (){
1;
2;
...
}
$sum = 1
while ($i<=30){
$sum += 3;
$i++;
print($sum);
}
while
mod3\while.php :
1
1. while, 1 50
53
3: -
: do while
do{
1;
2;
...
}while()
$i = 1;
$sum = 1;
do{
$sum += 3;
$i++;
print($sum);
}while($i<=30)
$i = 1;
while ($i < 10){
print($i);
$i++;
if ($i == 5)
break;
}
$i = 0;
while ($i < 10){
$i++;
if ($i == 5)
continue;
print($i);
}
54
3: -
mod3\table.php :
1
1. cols rows
2.
1 10
2
1. HTML-
:
a. cols
b. rows
c. ,
2. for
3
1.
2.
55
3: -
: foreach ()
foreach ($array as $value){
;
}
//$value -
$user = array("John",
"root",
"p@ssw0rd",
"312-34-85");
foreach($user as $val){
print("$val<BR>");
}
: foreach ()
foreach ($array as $key => $value){
;
}
//$key -
//$value -
$user["name"]= "John";
$user["login"]= "root";
$user["password"]= "p@ssw0rd";
$user[]= "312-34-85";
foreach($user as $index => $val){
print(" $index $val<BR>");
}
56
3: -
foreach
mod3\menu.php :
1
1. menu
2. , :
a. ,
: Home, About, Contact...
b. , ,
: index.php, about.php, contact.html...
2
1. foreach, ,
menu
57
3: -
for
while
do...while
foreach
58
4: PHP -
PHP
4
4: PHP -
60
4: PHP -
:
,
.
/* */
function sayHello(){
sayHello();
/* */
if(function_exists("sayHello")){}
:
function sayHello($name){
echo "Hello, $name!", "<hr>";
}
// , 1
sayHello("");
// , 2
$name = "";
sayHello($name);
// , 3
$func = "sayHello";
$func("");
61
4: PHP -
mod4\table.php :
1
1. getTable()
2. : cols, rows, color
2
1.
2.
3.
4.
mod3\table.php
,
getTable()
,
cols, rows color
3
1. getTable()
62
4: PHP -
:
function sayHello($name=""){
echo "Hello, $name!", "<hr>";
}
sayHello(""); // Hello, !
sayHello(""); // Hello, !
sayHello(); // Hello, !
:
mod4\ table.php :
4
1. getTable()
5
1. getTable()
2. getTable()
3. getTable()
63
4: PHP -
:
$a = 1; //
function Test(){
echo $a; //
}
Test(); // .
$a = 1; $b = 2;
function Sum(){
global $a, $b;
$b = $a + $b;
}
Sum();
echo $b; // 3
//
function Sum(){
$GLOBALS["b"] = $GLOBALS["a"] +
$GLOBALS["b"];
}
:
function Test(){
$a = 0;
echo $a++;
}
Test(); // 0
Test(); // 0
Test(); // 0
function Test(){
static $a =
echo $a++;
}
Test(); //
Test(); //
Test(); //
64
0;
0
1
2
4: PHP -
:
function getSum($num1, $num2){
//
echo getSum(10, 435);
65
4: PHP -
mod4\menu.php :
1
1. getMenu()
2. menu, ,
3. vertical
TRUE.
, -
2
1. mod3\menu.php
2. , menu
3. ,
4. getMenu()
5. ,
menu vertical
3
1. getMenu()
4
1. getMenu()
FALSE
66
4: PHP -
function factorial($n)
{
if ($n == 0) return 1;
return $n * factorial($n-1);
}
$result = factorial(5)
echo "5! = " . $result;
67
4: PHP -
getTable() getMenu()
68
5: -
PHP -
5: -
PHP
SSI
70
5: -
TRUE FALSE
,
.
is_array(expression)
is_bool(expression)
is_float(expression)
is_integer(expression)
is_numeric(expression)
is_string(expression)
is_null(expression)
intval(expression [, int base])
.
floatval(expression)
.
max .
acos
.
cos .
min .
decbin
.
log -
.
pi .
rad2deg
.
round
.
sqrt .
rand ,
.
71
5: -
addslashes - .
stripslashes - .
explode - .
htmlentities -
HTML .
trim - .
str_replace -
.
strip_tags - HTML PHP .
strlen - .
strpos -
.
strstr - .
substr
array_pop - .
array_shift - .
array_rand -
.
array_reverse -
.
count -
.
in_array - ,
.
array_key_exists - ,
.
implode - .
72
5: -
PHP
1
2
73
5: -
?
intval
(PHP 4, PHP 5)
intval
base
( 10)
var , 0
. 0,
1.
mod5\strings.php :
1
1. login "root"
2. password
"megaP@ssw0rd"
3. email
"[email protected]"
2
1. ,
login ()
2. ,
password ()
3. ,
email "@"
74
5: -
$today = getdate([int timestamp]);//
$today["seconds"]// 0 59
"minutes"// 0 59
"hours"// 0 23
"mday"// 1 31
"wday"// . 0 ()
"mon"// 1 12
"year"// , 4
"yday"// 0 365
"weekday"// Sunday
Saturday
"month"// , January
December
0//
date(str format [,timestamp])
echo date("h:I A l F dS, Y")
//04:01 PM Tuesday December 17th, 2006
()
d
D
F
G
H
i
j
l
m
M
n
r
s
w
W
Y
z
// , 2 01
// , 3 Mon
// , January
// 24- 0
// 24-
//
// 1
// , Sunday
// 01
// , 3 Jan Dec
// 1
// : Thu, 21 Dec 2000 16:01:07 +0200
// 00 59
// 0 ()
//
// , 4
// ( 0)
75
5: -
int time()
,
Unix (The Unix Epoch, 1 1970, 00:00:00
GMT) .
mod5\date.php :
1
1.
2.
3.
4.
now
birthday
now ()
birthday
2
1. " "
2. ,
3. " "
76
5: -
__LINE__ // .
__FILE__ // .
__FUNCTION__ // .
PHP_EXTENSION_DIR //
PHP_OS //
PHP_VERSION //
PHP_CONFIG_FILE_PATH // php.ini
...
$GLOBALS //,
$_ENV // ,
$_COOKIE // cookie
$_GET //,
, GET
$_POST //, ,
POST
$_FILES //,
$_REQUEST //,
_GET, _POST, _COOKIES _FILES
$_SESSION //
77
5: -
: _SERVER
$_SERVER //,
DOCUMENT_ROOT
GATEWAY_INTERFACE
HTTP_ACCEPT
HTTP_ACCEPT_CHARSET
HTTP_ACCEPT_ENCODING
HTTP_ACCEPT_LANGUAGE
HTTP_CONNECTION
HTTP_HOST
HTTP_REFERER
HTTP_USER_AGENT
PATH_TRANSLATED
PHP_AUTH_PW
PHP_AUTH_TYPE
PHP_AUTH_USER
78
PHP_SELF
QUERY_STRING
REMOTE_ADDR
REMOTE_PORT
REQUEST_METHOD
REQUEST_URI
SCRIPT_FILENAME
SCRIPT_NAME
SERVER_ADMIN
SERVER_NAME
SERVER_PORT
SERVER_PROTOCOL
SERVER_SIGNATURE
SERVER_SOFTWARE
5: -
SSI
include(); include_once();
require(); require_once();
<h1>
Hello, world!
</h1>
<body>
<?php
include "test.php";
?>
</body>
<body>
<h1>
Hello, world!
</h1>
</body>
SSI:
// .
if ($condition)
include $file;
else
include $other;
// .
if ($condition){
include $file;
}else{
include $other;
}
79
5: -
SSI
mod5\site\index.php
:
1
1. lib.inc.php
2
1. , (top.inc.php)
3
1. , (menu.inc.php)
4
1. , (bottom.inc.php)
mod5/site/index.php
80
5: -
mod5\site\lib.inc.php
:
1
1. mod4\menu.php
2. getMenu()
3. lib.inc.php
2
1. mod4\table.php
2. getTable()
3. lib.inc.php
mod5\site\menu.inc.php
:
1
1. menu
2. :
""=>"index.php",
"Page1"=>"page1.php",
"Page2"=>"page2.php",
"Page3"=>"page3.php",
"Table"=>"table.php"
2
1. getMenu()
mod5\site\index.php
81
5: -
SSI
!!!
82
6: HTTP
HTTP
6: HTTP
HTTP
HTTP 1.1
GET POST
:
84
6: HTTP
URI(/index.html);
(HTTP/1.1);
,
, , .
:
,
(200 OK);
, ,
(..
) .
HTTP :
Host: www.specialist.ru
Accept: */*
Accept-Language: ru
Referrer: http://yandex.ru/yandsearch?text=Rehc
User-Agent: Mozilla 4.0 (compatible; MSIE 6.1,)
HTTP/1.1 200 OK
Server: Microsoft IIS 6
Content-Type: text/html
Content-Length: 16345
Last-Modified: Sun, 03 Jul 2005 18:00:00 GMT
<html> . . .
</html>
85
6: HTTP
GET
POST
<form action="">
:
<input name="login"
type="text">
:
<input name="pwd"
type="password">
<input type="submit">
</form>
86
6: HTTP
GET
GET /action.php?login=Vasya&pwd=Parol HTTP/1.1
Host: www.specialist.ru
Accept: */*
Accept-Language: ru
Referrer: http://yandex.ru/yandsearch?text=Rehc
User-Agent: Mozilla 4.0 (compatible; MSIE 6.1,)
POST
POST /action.php HTTP/1.1
Host: www.specialist.ru
Accept: */*
Accept-Language: ru
Referrer: http://yandex.ru/yandsearch?text=Rehc
User-Agent: Mozilla 4.0 (compatible; MSIE 6.1,)
Content-Length: 20
login=Vasya&pwd=Parol
87
6: HTTP
GET:
$name = $_GET["name"];
$age = $_GET["age"] * 1;
POST:
$name = $_POST["name"];
$age = $_POST["age"] * 1;
<input
<input
<input
<input
type=checkbox
type=checkbox
type=checkbox
type=checkbox
name='kurs[]'
name='kurs[]'
name='kurs[]'
name='kurs[]'
//
$courses = $_POST["kurs"];
// ...
count($courses);
88
value='PHP'>
value='ASP'>
value='Perl'>
value='JS'>
6: HTTP
GET
mod6\menu.inc.php
:
1
1. index.php
2. "index.php" id, GET
3. id .
: index.php?id=page1
mod6\index.php :
1
1. id
2. id id
GET
3. switch, id,
89
6: HTTP
-
mod6\calculator.php
:
1
1.
2.
3.
4.
,
,
, ,
( !)
5.
2
1. ,
90
6: HTTP
HTTP 1.1
91
6: HTTP
Web-.
web-
XML XSLT.
Web Office 2007
mySQL
?
E-mail
:
http://forum.specialist.ru/Discussions.aspx?id=9
http://www.specialist.ru/Events/Seminars
92
==
===
S
N
A
P
I
T
94