Top Banner
  МІНІСТЕРСТВО ОСВІТИ І НАУКИ УКРАЇНИ ХАРКІВСЬКИЙ НАЦІОНАЛЬНИЙ УНІВЕРСИТЕТ РАДІОЕЛЕКТРОНІКИ МЕТОДИЧНІ ВКАЗІВКИ ДО ЛАБОРАТОРНИХ РОБІТ З ДИСЦИПЛІНИ «ПРОЕКТУВАННЯ ТА РОЗРОБКА WEB-СИСТЕМ» Харків 2013
77

лабыWEB-проект2013

Oct 05, 2015

Download

Documents

PHP и MySQL, веб-проектирование, работа с протоколом HTTP.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • WEB-

    2013

  • WEB-

    8.05150102-

    ...

    2013

  • WEB-" 8.05150102- / . .. : , 2013. - 76 .

    : ..

  • ..4 1 HTTP. ..5 1.1 .5 1.2 5 1.3 ..7 1.4 ..10 1.5 10 2 .11 2.1 ...11 2.2 ..11 2.3 13 2.4 ..18 2.5 18 3 cookies..19 3.1 ...19 3.2 ..19 3.3 20 3.4 ..26 3.5 26 4 . PHP..27 4.1 ...27 4.2 ..27 4.3 41 4.4 ..46 4.5 46 5 PHP MySQL..47 5.1 ...47 5.2 ..47 5.3 50 5.4 ..61 5.5 61 6 ...62 6.1 ...62 6.2 ..62 6.3 68 6.4 ..74 6.5 74

  • WEB- " 8.05150102- . WEB- PHP INTERNET. WEB- " , PHP, INTERNET . WEB-" :

    - HTTP; - PHP; - ; - ; - HTTP PHP; - cookies; - ; - PHP MySQL; - , .

    PHP, INTERNET.

  • 1 HTTP. PHP

    1.1 HTTP -

    PHP. .

    1.2 HTTP - ,

    ' . Hyper Text Transfer Protocol, - . INTERNET. HTTP , - - . HTTP - () .

    HTTP , FTP SMTP. -.

    () : 1. ; 2. ; 3. , ,

    , . ' .

    HTTP1.1 ' Host: ( , IP-).

    , http://my_site.ua/my_page.php ( URL, ), HTTP :

    GET /my_page.php HTTP/1.1 Host: my_site.ua User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;

    rv:1.9.0.4) Gecko/2008102920 AdCentriaIM/1.7 Firefox/3.0.4 Accept-Language: en-us,en;q=0.5 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive , , :

  • URI HTTP/ . ' Host ,

    . '. - _: . HTTP .

    : HTTP/1.1 200 OK Cache-Control: private, max-age=0 Date: Sun, 23 Nov 2008 10:34:39 GMT Expires: -1 Content-Type: text/html; charset=UTF-8 Server: nginx/0.6.31 Content-Length: 62 : HTTP/ :

    200 OK ; 403 Forbidden ; 404 Not Found .

    , , HTML

    . GET

    POST. GET URI. , 2 name age GET, HTTP :

    GET /my_page.php?name=Vasya&age=20 HTTP/1.1 Host: my_site.ua User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;

    rv:1.9.0.4) Gecko/2008102920 AdCentriaIM/1.7 Firefox/3.0.4 Accept-Language: en-us,en;q=0.5 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

  • Keep-Alive: 300 Connection: keep-alive POST .

    POST, : POST /my_page.php HTTP/1.1 Host: my_site.ua User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;

    rv:1.9.0.4) Gecko/2008102920 AdCentriaIM/1.7 Firefox/3.0.4 Accept-Language: en-us,en;q=0.5 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive name=Vasya&age=20

    , PHP GET

    $_GET, POST $_POST. HTTP PHP header().

    : void header (string string [, bool replace [, int http_response_code]]) , Content-Type, text/html;

    charset=UTF-8, header : header('Content-Type: text/html; charset=UTF-8'); HTTP

    echo: echo 'Hello world!'; ,

    . 1.3

    1.3.1 GET GET -

    . get.php.

    - PHP. :

  • echo ''; echo ', ' . $_GET['first_name'] . ' ' .

    $_GET['surname'] . ''; echo ''; ?> . : http://localhost//get.php?first_name=Vasya&surna

    me=Pupkin GET : first_name,

    Vasya surname, Pupkin. , HTML , ' . .

    1.3.2 get.php ,

    : http://localhost//get.php ,

    , $_GET . , , . :

  • . first_name surname, , , , , ' . .

    1.3.3 POST , POST,

    HTML . HTML GET POST. method form.

    post.php :

    (' )

    POST get.php. , ' . .

  • 1.3.4 post.php ,

    , first_name surname . (post.php) . , , , , ' .

    1.4 1 (. ). 2 . 3 , , . 4 . 5 , ,

    . 1.5 1 GET POST

    HTTP? 2 ? 3 PHP ? 4 PHP HTTP ?

  • 2 2.1

    , PHP. 2.2 PHP -

    . :

    strstr(): string strstr ( string $haystack , mixed $needle [, bool $before_needle ] ) $haystack $needle FALSE, . : $string = strstr('- ', ''); $string

    strlen(): int strlen ( string $string ) . : $strlen = strlen(''); $strlen 13

    substr(): string substr ( string $string , int $start [, int $length ] ) $string $start ' $length. $start . : substr('abcdef', 1); // bcdef substr('abcdef', 1, 3); // bcd substr('abcdef', 0, 4); // abcd substr('abcdef', 0, 8); // abcdef substr('abcdef', -1, 1); // f

    str_replace(): mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

  • $search $replace $subject . : $string = str_replace('', '', ' , ''); $string , '

    : strtoupper($string)

    . strtolower($string)

    . ucfirst($string)

    . ucwords($string)

    . trim ( string $str [, string $charlist ] )

    , ( ' $charlist) .

    , ' implode():

    string implode ( string $glue , array $pieces ) $pieces , ', $glue

    , ' . explode(): array explode ( string $delimiter , string $string [, int $limit ] ) $string , , $delimiter

    $string.

    , , . . .

    PHP POSIX Perl- , Perl- , .

    :

  • preg_match int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] ) $subject $pattern, 1, , 0 .

    preg_replace mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit [, int &$count ]] ) $subject $pattern $replacement.

    2.3

    . 2.3.1 , book_form.php.

    :

  • } echo ''; echo ': '; echo ' \' : '; echo ' : '; echo ' : '; echo ''; echo ''; echo ''; ?>

    , . , .

    2.3.2 implode explode . ,

    . , . explode , , ' implode . :

  • echo ''; echo '

    '; echo ''; echo ' :'; foreach($parameters as $key => $param_current) { echo $key . ': '. $param_current . ''; } echo ''; echo ': '; echo ' \' : '; echo ' : '; echo ' : '; echo ' : '; echo ''; echo ''; echo ''; ?> , ,

    . 2.3.3

    : .

    strtoupper , ,

    , . ucwords

    ..

    , 4

    :

  • $parameters = array(); if (isset($_POST['name']) && !empty($_POST['name'])) {

    parameters['name'] = strtoupper(parameters['name']); } else { parameters['name'] = ''; } if (isset($_POST['author']) && !empty($_POST['author'])) {

    parameters['author'] = ucwords(parameters['author']); } else { parameters['author'] = ''; } if (isset($_POST['date']) && !empty($_POST['date'])) { if (preg_match('/^[0-3]\d\.[01]\d\.\d{4}$/', $_POST['date']) { parameters['date'] = $_POST['date']; }

    else { parameters['date'] = ' '; }

    } else { parameters['date'] = ''; } if (isset($_POST['year']) && !empty($_POST['year'])) { if (strlen(parameters['year']) 0) { $parameters['keywords'] = $array_temp[0];

  • } else { $parameters['keywords'] = '

    '; }

    } else { $parameters['keywords'] = ''; } echo ''; echo '

    '; echo ''; echo ' :'; foreach($parameters as $key => $param_current) { echo $key . ': '. $param_current . ''; } echo ''; echo ': '; echo ' \' : '; echo ' : '; echo ' : '; echo ' : '; echo ''; echo ''; echo ''; ?> ,

    . . 2.3.4 , :

    ,

    ,

  • 2.4 1 (. ). 2 . 3 , , . 4 . 5 , , .

    2.5 1 PHP ? 2 implode explode? 3 ? ?

  • 3 COOKIES

    3.1 PHP.

    cookies. 3.2 , HTTP

    . -. , HTTP, ' . , , . IP- . , ' .

    PHP , ' . , - ( ) . () , . , . cookies.

    Cookies , -, - , . . Cookies - javascript , . cookies .

    cookie PHP :

    bool setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly ]]]]]] )

    $name ' , $value , $expire cookie ( 1970

    ). PHP time() ,

  • cookie . 0, cookie ,

    $path , cookie. , cookie http://localhost//, $path '//'.

    , php.net.

    cookie HTTP , setcookie HTTP (echo, print() ).

    cookie, $_COOKIE.

    PHP session_start(). , . , , , . $_SESSION, .

    , , , cookies, , session_destroy().

    3.3

    3.3.1 cookies , cookies

    . cookies .

    , cookies_counter.php. :

  • else { $message = ' '; setcookie('counter', 1, time()+60*60*24, '/'); } echo ''; echo ''; echo ''; echo ' cookies'; echo ''; echo ''; echo $message; echo ''; ?> .

    . 3.3.2 cookies ,

    cookie. cookie setcookie, $expire .

  • echo ''; echo ''; echo ''; echo ' cookies'; echo ''; echo ''; echo $message; echo ''; echo ''; ?> ,

    cookie. . , . .

    3.3.3 , ' '

    . , first_session_1.php. :

  • echo ' \' '.$_SESSION['name'].' '.$_SESSION['age'].' ';

    } else { echo ' \' ';

    echo ''; echo '\': '; echo ': '; echo ''; echo '';

    } echo ' '; echo ''; ?> ,

    first_session_2.php. :

  • , .

    , ( , ).

    first_session_1.php :

  • echo '\': '; echo ': '; echo ''; echo '';

    } echo ' '; echo ''; ?> first_session_2.php : ,

    . .

  • 3.3.4 first_session_1.php first_session_2.php

    : , , . cookies.

    3.4 1 (. ). 2 . 3 , , . 4 . 5 , , . 3.5

    1 HTTP PHP? 2 cookies? 3 ?

  • 4 . PHP

    4.1

    ,

    PHP. 4.2

    PHP -

    . : - - - - - - 4.2.1 , PHP ,

    . . , , , , '. , , , . fopen(). ? , fopen ' . ' , : , . :

    resource fopen ( '_, _[, use_include_path])

    . : ' , , ( , ) , , , , include_path. , , . .

    '_ , ' URL- . '

  • (, http://... ftp://...), ' URL URL . , PHP , ' URL ( allow_url_fopen ). allow_url_fopen=off, fopen . ' , , ' . , , PHP .

    use_include_path, 1 TRUE, fopen() include_path. , include_path PHP, , . fopen() include() require().

    _ : r ;

    . r+ ;

    . w ;

    . , .

    w+ ; . , .

    a ; . , .

    a+ ; . , .

    x ; . , fopen() false . , . PHP 4.3.2 .

    x+ ; . , fopen() false . , . , PHP 4.3.2, .

  • , , , .

  • , - , ', fopen(), . fclose(). :

    fclose ( ) TRUE, ' ,

    FALSE . , , , fopen().

    , ' ,

    . . , ' , .

    fwrite ,

    fopen(), fwrite(). :

    int fwrite ( , [, ]) ,

    . , , , , .

    fwrite() false, .

    . my_file.html. :

  • , , my_file.html ' .. , , , .

    : , my_file.html,

    , $add_text,

    4.2.2 readdir(): string readdir ([ resource $dir_handle ] ) ,

    opendir(). readdir() . , , closedir($handle). :

    . ,

    fopen(), , . , . , , : file, readfile, file_get_contents, fread, fgets ..

  • fread .

    , . fread() :

    string fread ( , )

    ( ), , , . , ' , , , fopen(). , .

    fread() .

    , '. , , . PHP . filesize(' ). false. , .

    . my_file.html

  • fgets fgets() .

    , fread(), , , , ':

    string fgets ( [, ]) fgets()

    (1) , . , (1) . , PHP . , , ( ' PHP 4.2.0), 1 (1024 ) , , 1024 . PHP 4.3, , . fgets() false. PHP 4.3 .

    , fread() fgets(),

    , . PHP , , . feof(), ' .

    , my_file.html:

  • fgetss fgets() fgetss().

    , html-, , , , . fgetss() :

    string fgetss( , [, ])

    , '. . my_file.html : . my_file.html, , : : . . fgetc ,

    , . fgetc(). , :

    string fgetc ( ) ,

    , , FALSE, .

    , , :

  • echo $content,""; } fclose($h); ?> , ,

    ' fopen() '. PHP , , ' . readfile(), file() file_get_contents(). .

    readfile : int readfile ( '_ [, use_include_path]) readfile() , '

    '_, . use_include_path TRUE, ' , include_path.

    () , FALSE. @ .

    .

    my_file1.html , . "Error in readfile".

    readfile()

    , URL- ' , .

  • . , - . file() file_get_contents().

    file file()

    . , readfile(), , :

    array file ( '_ [, use_include_path]) ?

    , ( ' '_). . file(), , false. use_include_path , include_path. , . PHP 4.3 .

    , my_file.html : file(): : 0: 1: file_get_contents PHP 4.3 '

    . file_get_contents(). , , , include_path. :

    string file_get_contents ('_ [, use_include_path])

  • file(), . , , .

    4.2.3 file_exists : bool file_exists (' ) file_exist() , , '

    . , TRUE, FALSE. . , , clearstatcache(). file_exists() .

    is_writable ,

    , is_writable() is_writeable().

    : bool is_writable (' ) TRUE, ( )

    . , ( nobody www). is_writable .

  • is_readable ,

    , is_readable().

    : bool is_readable (' ) is_writable(). 4.2.4 mkdir : int mkdir(string pathname, int mode); , pathname. ,

    mode , 0. true false .

    : mkdir("/path/to/my/dir", 0700); 4.2.5 PHP,

    unlink(). : bool unlink ( '_) , ' '_, TRUE

    FALSE . , (, ).

  • rmdir(). .

    : int rmdir(string dirname); 0. 4.2.6 , , ,

    html-. , enctype form multipart/form-data, input file.

    . : , ,

    , , . , , . .

    , .

    $_FILES.

    '- ' critics.htm 15136 , print_r($_FILES); :

    Array ([myfile] => Array ( [name] => critics.htm [type] => text/html [tmp_name] => C:\WINDOWS\TEMP\php49F.tmp [error] => 0 [size] => 15136 ) ) $_FILES :

    $_FILES['myfile']['name'] ', .

  • $_FILES['myfile']['type'] mime- , . text/html.

    $_FILES['myfile']['size'] .

    $_FILES['myfile']['tmp_name'] ' , .

    $_FILES['myfile']['error'] , ' .

    'myfile' ' ,

    . , . (name, type ..) - .

    PHP ' $_FILES['myfile']['error'] ' :

    0 , 1 , , ,

    upload_max_filesize php.ini 2 , , ,

    MAX_FILE_SIZE html 3 4

    , upload_tmp_dir php.ini. move_uploaded_file().

    move_uploaded_file() : bool move_uploaded_file (_'_,

    _). , ,

    _'_, HTTP POST. , , _ ( , ' ).

    _'_ , , move_uploaded_file()

  • FALSE. , . . , _, , move_uploaded_file() .

    4.3

    4.3.1 PHP PHP,

    , .

    -, . my_dir. - my_dir. , view_files.php. :

  • } else { echo " "; } echo ''; ?>

    . my_dir. .

    :

  • } } } break; default: break; } } if ($handle = opendir('my_dir')) { $files = array(); while (false !== ($file = readdir($handle))) { if ($file!='.' && $file!='..') { $files[$file] = (is_dir('my_dir/'.$file)) ? 'dir' : 'file'; } } closedir($handle); if (!empty($files)) { echo ''; foreach ($files as $file => $type) { echo ''.$type.': '.$file.' (x)'; } echo ''; } else { echo " "; } } else { echo " "; } echo ''; ?>

    . .

    . :

  • echo ' '.$_FILES['myfile']['name'].' '; } else { echo ' '; } } else { echo ' '; } } break; default: break; } } if ($handle = opendir('my_dir')) { $files = array(); while (false !== ($file = readdir($handle))) { if ($file!='.' && $file!='..') { $files[$file] = (is_dir('my_dir/'.$file)) ? 'dir' : 'file'; } } closedir($handle); if (!empty($files)) { echo ''; foreach ($files as $file => $type) { echo ''.$type.': '.$file.' (x)'; } echo ''; } else { echo " "; }

  • echo ' : '; } else { echo " "; } echo ''; ?>

    , . .

    4.3.2 ,

    . 4.4 1 (. ). 2 . 3 , , . 4 . 5 , , . 4.5

    1 PHP? 2 ? 3 ?

  • 5 PHP MYSQL

    5.1 MySQL,

    , . 5.2

    PHP ,

    MySQL. web- html- , . .

    , , , - ' . mysql_connect.

    mysql_connect mysql_connect ( [ server [, username [, password [, new_link [, client_flags]]]]]) ' MySQL

    ' FALSE . :

    server = 'localhost:3306' username = ' password = ,

    ' , '. , new_link, - '.

    client_flags - : MYSQL_CLIENT_COMPRESS ( ), MYSQL_CLIENT_IGNORE_SPACE ( ), MYSQL_CLIENT_INTERACTIVE ( interactive_timeout - wait_timeout - ').

    ' , mysql_close().

    , ' nina "123":

  • , . mysql_query() FALSE, .

    , mysql_query()

    PHP, mysql_result() mysql_fetch_array().

    mysql_result mysql_result ( result, row [, field]) mysql_result() .

    field , ' ' ' tablename.fieldname. ('select foo as bar from...'), .

    , , (, mysql_fetch_row(), mysql_fetch_array() ..). , mysql_result(). , , ( ) , .

    mysql_result() , .

    mysql_fetch_array mysql_fetch_array ( result [, result_type]) ,

    (, ) , FALSE, .

    mysql_fetch_array() - mysql_fetch_row(). , .

    , . , . , , , "photo" .

    select Artifacts.photo as art_image, Persons.photo as pers_image from Artifacts, Persons

  • , mysql_fetch_array() , mysql_fetch_row(), .

    result_type mysql_fetch_array() : MYSQL_ASSOC, MYSQL_NUM MYSQL_BOTH. PHP 3.0.7. : MYSQL_BOTH.

    MYSQL_BOTH, , , . MYSQL_ASSOC , MYSQL_NUM - .

    : , , .

    5.3

    -

    . : , .

    5.3.1 phpMyAdmin .

    http://localhost/Tools/phpMyAdmin. MySQL, ( ). ( ). Create new database Create.

    . SQL SQL :

    CREATE TABLE authors(

    id int PRIMARY KEY AUTO_INCREMENT, name varchar(255)

    ); CREATE TABLE books(

    id int PRIMARY KEY AUTO_INCREMENT, name varchar(255), year year(4), author_id int

    ); Go. ,

    : authors books.

  • 5.3.2 ,

    (, , ) . -, library.php ( $database ):

  • $books[$row['id']] = array( 'name' => $row['name'], 'year' => $row['year'], 'author_id' => $row['author_id'], 'author_name' => $row['author_name'] ); } } else { $books = false; } echo ''; if ($authors) { echo ''; echo 'id\''; foreach ($authors as $id => $name) { echo ''.$id.''.$name.''; } echo ''; } else { echo ' '; } echo ''; if ($books) { echo ''; echo 'id '; foreach ($books as $id => $info) { echo ''.$id.''.$info['name'].''.$info['year'].''.$info['author_name'].''; } echo ''; } else { echo ' '; } echo ''; ?>

  • , , , . . :

  • $name = mysql_escape_string($_POST['name']); $year = mysql_escape_string($_POST['year']); $author = mysql_escape_string($_POST['author']); if (!mysql_query('INSERT INTO books VALUES(NULL, "'.$name.'", "'.$year.'", '.$author.')')) { echo ' '; } } else { echo ' '; } break; default: break; } } // $result_resource = mysql_query('SELECT id, name FROM authors'); if (mysql_num_rows($result_resource) > 0) { while ($row = mysql_fetch_array($result_resource)) { $authors[$row['id']] = stripslashes($row['name']); } } else { $authors = false; } // $result_resource = mysql_query( 'SELECT books.id, books.name, books.year, books.author_id, authors.name AS author_name FROM books INNER JOIN authors ON books.author_id=authors.id'); if (mysql_num_rows($result_resource) > 0) { while ($row = mysql_fetch_array($result_resource)) { $books[$row['id']] = array( 'name' => stripslashes($row['name']), 'year' => $row['year'], 'author_id' => $row['author_id'], 'author_name' => stripslashes($row['author_name']) );

  • } } else { $books = false; } echo ''; if ($authors) { echo ''; echo 'id\''; foreach ($authors as $id => $name) { echo ''.$id.''.$name.''; } echo ''; } else { echo ' '; } echo ' '; echo ''; echo '\': '; echo ' '; echo ''; echo ''; echo ''; if ($books) { echo ''; echo 'id '; foreach ($books as $id => $info) { echo ''.$id.''.$info['name'].''.$info['year'].''.$info['author_name'].''; } echo ''; } else { echo ' '; } if ($authors) { echo ' '; echo '';

  • echo ': '; echo ' : '; echo ': '; foreach ($authors as $id => $name) { echo ''.$name.''; } echo ''; echo ''; echo ''; echo ''; } echo ''; ?>

    . .

    . :

  • $name = mysql_escape_string($_POST['name']); if (!mysql_query('INSERT INTO authors VALUES(NULL,"'.$name.'")')) { echo ' '; } } else { echo ' '; } break; case 'add_book': if (isset($_POST['name']) && !empty($_POST['name']) && isset($_POST['year']) && !empty($_POST['year']) && isset($_POST['author']) && !empty($_POST['author'])) { $name = mysql_escape_string($_POST['name']); $year = mysql_escape_string($_POST['year']); $author = mysql_escape_string($_POST['author']); if (!mysql_query('INSERT INTO books VALUES(NULL, "'.$name.'", "'.$year.'", '.$author.')')) { echo ' '; } } else { echo ' '; } break; case 'edit_author': if (isset($_POST['id']) && is_numeric($_POST['id']) && isset($_POST['name']) && !empty($_POST['name'])) { $name = mysql_escape_string($_POST['name']); if (!mysql_query('UPDATE authors SET name="'.$name.'" WHERE id='.$_POST['id'])) { echo ' '; } } else { echo ' '; }

  • break; default: break; } } // $result_resource = mysql_query('SELECT id, name FROM authors'); if (mysql_num_rows($result_resource) > 0) { while ($row = mysql_fetch_array($result_resource)) { $authors[$row['id']] = stripslashes($row['name']); } } else { $authors = false; } // $result_resource = mysql_query( 'SELECT books.id, books.name, books.year, books.author_id, authors.name AS author_name FROM books INNER JOIN authors ON books.author_id=authors.id'); if (mysql_num_rows($result_resource) > 0) { while ($row = mysql_fetch_array($result_resource)) { $books[$row['id']] = array( 'name' => stripslashes($row['name']), 'year' => $row['year'], 'author_id' => $row['author_id'], 'author_name' => stripslashes($row['author_name']) ); } } else { $books = false; } echo ''; if ($authors) { echo ''; echo 'id\''; foreach ($authors as $id => $name) {

  • echo ''.$id.''.$name.''; } echo ''; } else { echo ' '; } echo ' '; echo ''; echo '\': '; echo ' '; echo ''; echo ''; echo ''; if ($books) { echo ''; echo 'id '; foreach ($books as $id => $info) { echo ''.$id.''.$info['name'].''.$info['year'].''.$info['author_name'].''; } echo ''; } else { echo ' '; } if ($authors) { echo ' '; echo ''; echo ': '; echo ' : '; echo ': '; foreach ($authors as $id => $name) { echo ''.$name.''; } echo ''; echo ''; echo ''; echo '';

  • } echo ''; ?>

    . edit.php

    :

  • echo '\': '; echo ' '; echo ''; echo ''; } } break; default: break; } } echo ''; ?>

    , . . .

    5.4 1 (. ). 2 . 3 , , . 4 . 5 , , . 5.5

    1 . 2 mysql_query() ? 3 ?

  • 6

    6.1 , ,

    . 6.2

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

    , ,

    , , , , , , .

    , . :

    function '_ (1, 2,... ){ _ return ", "; }

  • '_ (1, 2 ..) PHP. . , $. _ - - PHP- ( ' ). , return php- (-, ). , , , . , .

    ? ' , :

  • $data_str .= "checked"; } $str = ""; // add_label($str); // echo $str .">"; // ?> ,

    . , .

    , , . , "".

    , ,

    , . ' , .

    , . , ,

  • . ' , , .

    : , . : ... : , . : ... : : Warning: Missing argument 3 for add_article() in c:\users\nina\tasks\func\def_bad.php on line 2 , ,

    . global: global $var1, $var2;

  • function Test_g(){ global $a; $a = $a*2; echo ' $a=',$a; } echo ' $a=',$a,', '; Test_g(); echo ""; echo ' $a=',$a,', '; Test_g(); ?> : $a=1, $a=2 $a=2, $a=4 ,

    , . , . static: static $var1, $var2;

    - , .

  • , , , - .

    , - - . return. , , - , '. return , , .

    , , . , .

    return,

    echo. - , ( ), - :

    $my_age = Age(1981, 2004);

    . , (). , :

  • } else { $year = date("Y") - $b_year - 1; $day = 31 - ($b_day - date ("d")); $month = 12 - ($b_month - date("m")); } return array ($day,$month,$year); } $age = Full_age("07","08","1974"); echo " $age[2] , $age[1] $age[0] "; // " 29 , 11 5 " ?>

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

    list()

    - . 6.3 ,

    . -, , . functions.php. GET

  • POST ( isset() empty()):

    ( -):

  • if (unlink('my_dir/'.$_GET['file'])) { echo ' '.$_GET['file'].' '; } else { echo ' '; } } } break; case 'upload': if (isset($_FILES['myfile'])) { if ($_FILES['myfile']['error']==0) { if (move_uploaded_file($_FILES['myfile']['tmp_name'], 'my_dir/'.$_FILES['myfile']['name'])) { echo ' '.$_FILES['myfile']['name'].' '; } else { echo ' '; } } else { echo ' '; } } break; default: break; } } if ($handle = opendir('my_dir')) { $files = array(); while (false !== ($file = readdir($handle))) { if ($file!='.' && $file!='..') { $files[$file] = (is_dir('my_dir/'.$file)) ? 'dir' : 'file';

  • } } closedir($handle); if (!empty($files)) { echo ''; foreach ($files as $file => $type) { echo ''.$type.': '.$file.' (x)'; } echo ''; } else { echo " "; } echo ' : '; } else { echo " "; } echo ''; ?>

    . , :

    checkParam(array(param1, param2, param3), get); , ,

    . ,

    : function readdir($dir) { if ($handle = opendir($dir)) { $files = array(); while (false !== ($file = readdir($handle))) {

  • if ($file!='.' && $file!='..') { $files[$file] = (is_dir($dir.$file)) ? 'dir' : 'file'; } } closedir($handle); return $files; } else { return false; } }

    - :

  • else { echo ' '; } } } break; case 'upload': if (isset($_FILES['myfile'])) { if ($_FILES['myfile']['error']==0) { if (move_uploaded_file($_FILES['myfile']['tmp_name'], 'my_dir/'.$_FILES['myfile']['name'])) { echo ' '.$_FILES['myfile']['name'].' '; } else { echo ' '; } } else { echo ' '; } } break; default: break; } } $files = readdir('my_dir'); if ($files) { if (!empty($files)) { echo ''; foreach ($files as $file => $type) { echo ''.$type.': '.$file.' (x)'; }

  • echo ''; } else { echo " "; } echo ' : '; } else { echo " "; } echo ''; ?>

    , 5, . : , , , . true false .

    , , .

    6.4 1 (. ). 2 . 3 , , . 4 . 5 , , . 6.5

    1 . 2 ? 3 ? 4 ?

  • ,

    __________________.. ________________2012.

    WEB-

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

    ___________2012.

    : ..

    ..

    __________,

    __________,

    . 2012

  • WEB-

    8.05150102-

    :

    ..

    2012, . . 6084 1/16. . . . . 1.5 .-. 50 .

    . 1 113 .

    . . 61166, , . , 14

    - -

    61166, , . , 14