Free Essay

Căn Bản Php

In:

Submitted By luxubuah
Words 7561
Pages 31
COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Moân hoïc: PHP Baøi 1 Nhöõng vaán ñeà chính seõ ñöôïc ñeà caäp trong baøi hoïc: Giôùi thieäu PHP Caáu hình IIS, Apache Web Server Caøi ñaët PHP. o Caøi ñaët PHP. o Caáu hình öùng duïng PHP Giôùi thieäu PHP. o PHP Script. o Ghi chuù trong PHP o In noäi dung baèng PHP PHP vieát taét cuûa chöõ Personal Home Page ra ñôøi naêm 1994 do phaùt minh cuûa Rasmus Lerdorf, vaø noù tieáp tuïc ñöôïc phaùt trieån bôûi nhieàu caù nhaân vaø taäp theå khaùc, do ñoù PHP ñöôïc xem nhö moät saûn phaåm cuûa maõ nguoàn môû. PHP laø kòch baûn trình chuû (server script) chaïy treân phía server (server side) nhö caùch server script khaùc (asp, jsp, cold fusion). PHP laø kòch baûn cho pheùp chuùng ta xaây döïng öùng duïng web treân maïng internet hay intranet töông taùc vôùi moïi cô sôû döõ lieäu nhö mySQL, PostgreSQL, Oracle, SQL Server vaø Access. Löu yù raèng, töø phieân baûn 4.0 trôû veà sau môùi hoã trôï session, ngoaøi ra PHP cuõng nhö Perl laø kòch baûng xöû lyù chuoãi raát maïnh chính vì vaäy baïn coù theå söû duïng PHP trong nhöõng coù yeâu caàu veà xöû lyù chuoãi.

1. GIÔÙI THIEÄU PHP

2. CAØI ÑAËT PHP
Caøi ñaët PHP treân neàn Windows thì söû duïng php-4.0.6-Win32.zip, sau khi caøi ñaët öùng duïng naøy treân ñóa cöùng seõ xuaát hieän thö muïc PHP, trong thöï muïc naøy seõ coù taäp tin php4ts.dll vaø php.exe cuøng vôùi thö muïc sessiondata. Ngoaøi ra, trong thö muïc WINDOW hoaëc WINNT seõ xuaát hieän taäp tin php.ini, taäp tin naøy cho pheùp baïn caáu hình cho öùng duïng PHP. Chaúng haïn, khi söû duïng session, PHP caàn moät nôi ñeå löu tröõ chuùng, trong taäp tin naøy maëc ñònh laø session.save_path = C:\PHP\sessiondata, neáu baïn caøi ñaët PHP vôùi thö muïc PHP treân ñóa D thì baïn caàn thay ñoåi ñöôøng daãn trong khai baùo naøy. Töông töï nhö vaäy, khi coù loãi trong trangPHP thì loãi thöôøng xuaát hieän khi trieäu goïi chuùng, ñeå che daáu caùc loãi naøy thì baïn caàn khai baùo display_errors = Off thay vì chuùng ôû traïng thaùi display_errors = On. Ngoaøi ra, trang PHP cuõng coù theå trình baøy moät soá warning khi chuùng phaùt hieän cuù phaùp khoâng hôïp lyù, chính vì vaäy ñeå che daáu caùc warning naøy thì baïn cuõng caàn khai baùo traïng thaùi Off thay vì On nhö assert.warning = Off.

3. CAÁU HÌNH ÖÙNG DUÏNG PHP
Sau khi caøi ñaët heä ñieàu haønh Windows NT hay 2000 trôû veà sau, baèng caùch khai baùo môùi moät web site hay virtual site trong moät site ñang coù theo caùc böôùc nhö sau: 1. Taïo moät thö muïc coù teân myPHP ñeà löu tröõ caùc taäp tin PHP 2. Khôûi ñoäng IIS (töï ñoäng khôûi ñoäng neáu Windows NT/2000)

3.1. Caáu hình IIS

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

3. 4. 5. 6.

Choïn Start | Programs | Administrative Tools | Internet Information Server Neáu taïo virtual site thì choïn Default Web Ste | R-Click | New | Virtual Site Trong tröôøng hôïp taïo môùi Site thì Default Web Ste | R-Click | New | Site Neáu choïn tröôøng hôïp 4 thì baïn cung taáp dieãn giaûi cuûa site nhö hình 1-1

Hình 1-1: Khai baùo dieãn giaûi 7. Choïn nuùt Next vaø khai baùo IP vaø port, trong tröôøng hôïp baïn khoâng söû duïng port 80 cho öùng site khaùc thì choïn giaù trò maëc ñònh. Tuy nhieân neáu coù nhieàu öùng duïng tröôùc ñoù ñaõ caáu hình trong IIS thì baïn coù theå thay ñoåi port khaùc, ví duï choïn port 85 nhö hình 1-2.

Hình 1-2: Khai baùo IP vaø Port Löu yù raèng, port 80 laø port chuaån ñieàu naøy coù nghóa laø khi trieäu goïi treân trình duyeät baïn khoâng caàn goõ port, ví duï http://localhost/. Ñoái vôùi tröôøng hôïp port khaùc thì baïn phaûi goõ töông töï nhö http://localhost:85/

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

8. Choïn Next, baïn choïn thö muïc cuûa öùng duïng, ñoái vôùi tröôøng hôïp naøy chuùng ta choïn vaøo thö muïc myPHP, chaúng haïn trong tröôøng hôïp naøy chuùng ta choïn htö muïc myPHP nhö hình 1-3.

Hình 1-3: Choïn thö muïc myPHP 9. Keá ñeán choïn quyeàn truy caäp web site, trong tröôøng hôïp ñang thieát keá thì baïn choïn vaøo Browse. Ngoaøi ra, neáu baïn cho pheùp ngöôøi söû duïng internet coù theå thöïc thi taäp tin thöïc thi töø xa thì choïn vaøo tuyø choïn execute.

Hình 1-4: Quyeàn truy caäp 10.Choïn Next vaø Finish, trong cöûa soå IIS xuaát hieän öùng duïng coù teân myPHP (khai baùo trong phaàn dieãn giaûi) nhö hình 1-5.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Hình 1-5: Taïo thaønh coâng öùng duïng PHP trong IIS 11.Sau khi taïo öùng duïng xong, baïn choïn teân öùng duïng myPHP | R-Click } Properties | cöûa soå xuaát hieän nhö hình 1-5.

Hình 1-5: Caáu hình PHP trong IIS 12.Baèng caùch choïn vaøo nuùt Configuration, cöûa soå seõ xuaát hieän nhö hình 1-6.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Hình 1-6: Theâm PHP Engine 13.Choïn nuùt Add, vaø khai baùo nhö hình 1-7.

Hình 1-7: Khai baùo PHP Engine 14.Ñeå kieåm tra uùng duïng, baïn môû cöûa soå IE vaø goõ treân thanh ñòa chæ chuoãi nhö sau: http://localhost:85/ , keát quaû xuaát hieän nhö hình 1-8.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Hình 1-8: ÖÙng duïng PHP ñaõ ñöôïc khôûi ñoäng

3.2. Caøi ñaët Apache Web Servr
Ñeå caøi ñaët Apache Web Server, baïn theo caùc böôùc sau 1. Chep tap tin apache_1.3.22-win32-x86.exe xuong dia cung 2. Chay tap tin nay va cai dat len dia C:\Program Files\, sau khi ket thuc thanh cong phan cai dat Apache, baïn baét ñaàu caáu hình öùng duïng PHP. 3. Cheùp ba doøng leänh töø taäp tin install.txt trong thö muïc C:\PHP
ScriptAlias /php/ "c:/php/" AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php.exe"

4. Paste vaøo taäp tin httpd.conf trong thö muïc Group\Apache\Conf\

C:\Program Files\Apache

5. Chon Start | Programs | Apache HTTP Server | Control Apache Server | Start 6. Viet trang test.php voi noi dung 7. Chep tap tin test.php Group\Apache\htdocs\ vao thu muc C:\Program Files\Apache

8. Sau ñoù goõ treân trình duyeät http://localhost/test.php

4. GIÔÙI THIEÄU PHP 4.1. Yeâu caàu
PHP döïa treân cuù phaùp cuûa ngoân ngöõ laäp trình C, chính vì vaäy khi laøm vieäc vôùi PHP baïn phaûi laø ngöôøi coù kieán thöùc veà ngoân ngöõ C, C++, Visual C. Neáu baïn xaây döïng öùng duïng PHP coù keát noái cô sôû döõ lieäu thì kieán thöùc veà cô sôû döõ lieäu MySQL, SQL Server hay Oracle laø ñieàu caàn thieát.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

4.2. Giôùi thieäu
PHP laø kòch baûn trình chuû (Server Script) ñöôïc chaïy treân neàn PHP Engine, cuøng vôùi öùng duïng Web Server ñeå quaûn lyù chuùng. Web Server thöôøng söû duïng laø IIS, Apache Web Server, ...

4.3. Thoâng dòch trang PHP
Khi ngöôøi söû duïng goïi trang PHP, Web Server trieäu goïi PHP Engine ñeå thoâng dòch (töông töï nhö ASP 3.0 chæ thoâng dòch chöù khoâng phaûi bieân dòch) dòch trang PHP vaø traû veà keát quaû cho ngöôøi söû duïng nhö hình 1-9.
Parse Web Server Taäp tin PHP

Request

Parse Request

Response Response

PHP Engine

P

Hình 1-9: Quaù trình thoâng dòch trang PHP

4.4. Kòch baûn (script)
Noäi dung cuûa PHP coù theå khai baùo laãn loän vôùi HTML, chính vì vaäy baïn söû duïng caëp daáu giaù ñeå khai baùo maõ PHP. Chaúng haïn, chuùng ta khai baùo: 1-Giaù trò bieán Str: 2-Giaù trò bieán i: 3-Giaù trò cuõ theå:

Chaúng haïn baïn khai baùo trang hello.php vôùi noäi dung nhö ví duï 1-1 sau: Ví duï 1-1: Trang hello.php ::Welcome to PHP Greeting:

Keát quaû traû veà nhö hình 1-10 khi trieäu goïi trang naøy treân trình duyeät.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Hình 1-10: Keát quaû trang hello.php Trong tröôøng hôïp coù nhieàu khai baùo, baïn söû duïng Scriptlet, ñeàu naøy coù nghóa laø söû duïng caëp daáu treân nhö vôùi caùc khai baùo PHP vôùi cuù phaùp cuûa C nhö sau: -Khai baùo treân laø Scriptlet Giaù trò cuûa paging: -Khai baùo naøy laø Script

Löu yù raèng, keát thuùc moãi caâu leänh phaûi duøng daáu ; Ví duï, baïn khai baùo ñoaïn PHP treân trong taäp tin script.php nhö ví duï 1-2 Ví duï 1-2: Trang script.php ::Welcome to PHP Giaù trò cuûa paging:

Keát quaû traû veà nhö hình 1-11 khi trieäu goïi trang naøy treân trình duyeät.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Hình 1-11: Keát quaû trang hello.php

Löu yù raèng, neáu baïn muoán söû duïng script hay scriptlet nhö ASP thì baïn khai baùo trong taäp tin php.ini nhö sau: asp_tags = On ; Allow ASP-style tags. maëc ñònh laø Off

Khi ñoù trong trang PHP, thay vì baïn khai baùo

Thì baïn coù theå khai baùo nhö sau:

4.5. Ghi chuù trong PHP
Ghi chuù trong kòch baûn PHP töông töï ngoân ngöõ laäp trình C, ñeå ghi chuù moät doøng thì baïn söû duïng caëp daáu /. Chaúng haïn khai baùo sau laø ghi chuù:

Trong tröôøng hôïp coù nhieàu doøng caàn ghi chuù baïn söû duïng caëp daáu /* vaø */, ví duï khai baùo ghi chuù nhö sau: Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER /* Khai baùo bieán ñeå ñoïc döõ lieäu trong ñoù totalRows laø bieán traû veà toång soá maåu tin */ $result = mysql_query($stSQL, $link); $totalRows=mysql_num_rows($result);

WWW.HUUKHANG.COM

Ngoaøi ra, baïn cuõng coù theå söû duïng daáu # ñeå khai baùo ghi chuù cho töøng doøng, ví duï khai baùo sau laø ghi chuù:

4.6. In keát quaû treân trang PHP
Khaùc vôù caùc kòch baûn nhö ASP, JSP, Perl, ñoái vôùi PHP ñeå in ra giaù trò töø bieán, bieåu thöùc, haøm, giaù trò cuï theå thæ baïn coù theå söû duïng script nhö treân:
Giaù trò cuûa paging:

Tuy nhieân, ñeå söû duïng cuù phaùp cuûa PHP khi in ra giaù trò töø bieán, bieåu thöùc, haøm, giaù trò cuï theå thì söû duïng khai baùo echo nhö sau: $stSQLs=”select * from Customers”; echo $stSQLs;

Chaúng haïn, khai baùo echo nhö ví duï 1-3. Ví duï 1-2: Trang echo.php ::Welcome to PHP

Keát quaû traû veà nhö hình 1-12 khi trieäu goïi trang naøy treân trình duyeät.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Hình 1-11: Keát quaû trang hello.php

5. KEÁT LUAÄN
Trong baøi naøy, chuùng ta taäp trung tìm hieåu caùch caøi ñaët PHP vaø Apache Web Server, sau ñoù caáu hình öùng duïng PHP trong IIS hay söû duïng caáu hình maëc ñònh cuûa chuùng. Ngoaøi ra, baïn laøm quen caùch khai baùo maõ PHP trong trang .php cuøng vôùi script hay scriptlet.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Moân hoïc: PHP Baøi 2

Baøi hoïc naøy chuùng ta seõ laøm quen vaø tìm hieåu cuù phaùp vaø moät soá phöông thöùc cô baûn cuûa PHP:
Caâu leänh. Kieåu döõ lieäu vaø bieán Khai baùo vaø söû duïng haèng. Döõ lieäu maûng Chuyeån ñoåi kieåu döõ lieäu

1. KHAÙI NIEÄM VEÀ CUÙ PHAÙP PHP

Cuù phaùp PHP chính laø cuù phaùp trong ngoân ngöõ C, caùc baïn laøm quen vôùi ngoân ngöõ C thì coù lôïi theá trong laäp trình PHP. Ñeå laäp trình baèng ngoân ngöõ PHP caàn chuù yù nhöõng ñieåm sau: Cuoái caâu leänh coù daáu ; Bieán trong PHP coù tieàn toá laø $ Moãi phöông thöùc ñeàu baét ñaàu { vaø ñoùng baèng daáu } Khi khai baùo bieán thì khoâng coù kieãu döõ lieäu Neân coù giaù trò khôûi ñaàu cho bieán khai baùo Phaûi coù chi chuù (comment) cho moãi feature môùi Söû duïng daáu // hoaëc # ñeå giaûi thích cho moãi caâu ghi chuù Söû duïng /* vaø */ cho moãi ñoaïn ghi chuù Khai baùo bieán coù phaân bieät chöõ hoa hay thöôøng

2. KHAI BAÙO BIEÁN
Khi thöïc hieän khai baùo bieán trong C, baïn caàn phaûi bieát tuaân thuû quy ñònh nhö: kieãu döõ lieäu tröôùc teân bieán vaø coù giaù trò khôûi ñaàu, tuy nhieân khi laøm vieäc vôùi PHP thì khoâng caàn khai baùo kieåu döõ lieäu nhöng söû duïng tieàn toá $ tröôùc bieán. Xuaát phaùt töø nhöõng ñieàu ôû treân, khai baùo bieán trong PHP nhö sau: $variablename [=initial value];
$licount=0; $lsSQL=”Select * from tblusers where active=1”; $nameTypes = array("first", "last", "company"); $checkerror=false;

Chaúng haïn, khai baùo nhö ví duï 2-1 (variables.php) ::Welcome to PHP

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Variable

3. KIEÅU DÖÕ LIEÄU
Baûng caùc kieåu döõ lieäu thoâng thöôøng Boolean Integer Float String Object Array True hay false giaù trò lôùn nhaát xaáp xæ 2 tyû ~1.8e308 goàm 14 soá leõ Löu chuoãi kyù töï chieàu daøi voâ haïn Kieåu ñoái töôïng Maûng vôùi nhieàu kieåu döõ lieäu

3.1. Thay ñoåi kieåu döõ lieäu
Ñeå thay ñoåi kieåu döõ lieäu, baïn coù theå söû duïng caùch eùp kieåu nhö trong caùc ngoân ngöõ laäp trình C hay Java. Chaúng haïn, khai baùo eùp kieåu nhö ví duï 2-2 (box.php): ::Welcome to PHP Variable

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Löu yù raèng, PHP töï ñoäng nhaän bieát giaù trò chuoãi ñaèng sau soá seõ khoâng ñöôïc chuyeån sang kieåu döõ lieäu soá nhö tröôøng hôïp treân. Ngoaøi ra, baïn coù theå söû duïng haøm settype ñeå chuyeån ñoåi döõ lieäu naøy sag döõ lieäu khaùc, ví duï chuùng ta khai baùo nhö ví duï 2-3 (settype.php). ::Welcome to PHP Change DataType of Variable

3.2. Kieåm tra kieåu döõ lieäu cuûa bieán
Ñeå kieåm tra kieåu döõ lieäu cuûa bieán, baïn söû duïng caùc haøm nhö sau: is_int ñeå kieåm tra bieán coù kieåu integer, neáu bieán coù kieåu integer thì haøm seõ traû veà giaù trò laø true (1). Töông töï, baïn coù theå söû duïng caùc haøm kieåm tra töông öùng vôùi kieåu döõ lieäu laø is_array, is_bool, is_callable, is_double, is_float, is_int, is_integer, is_long, is_null, is_numeric, is_object, is_real, is_string. Chaúng haïn, baïn khai baùo caùc haøm naøy nhö ví duï 2-4 (check.php). ::Welcome to PHP Check DataType of Variable

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

3.3. Thay ñoåi kieåu döõ lieäu bieán
Khi khai baùo bieán vaø khôûi taïo giaù trò cho bieán vôùi kieåu döõ lieäu, sau ñoù baïn muoán söû duïng giaù trò cuûa bieán ñoù thaønh teân bieán vaø coù giaù trò chính laø giaù trò cuûa bieán tröôùc ñoù thì söû duïng caëp daáu $$. Ví duï, bieán $var coù giaù trò laø "total", sau ñoù muoán söû duïng bieán laø total thì khai baùo nhö ví duï 2-5 (change.php). ::Welcome to PHP Change DataType of Variable

3.4. Kieåu Array
Kieãu maûng laø moät maûng soá lieäu do ngöôøi duøng ñònh nghóa, chuùng coù cuù phaùp nhö sau: $myarrs=array("first", "last", "company"); // maûng bao goàm caùc kieåu chuoãi hay coù theå khai baùo nhö sau $myarr[]=array(3); $myarr[0]="Number 0"; $myarr[1]="Number 1"; $myarr[2]="Number 2"; Thöù töï index trong maûng baét ñaàu töø vò trí 0. Chaúng haïn, baïn khai baùo maûng moät chieàu theo hai caùch treân nhö ví duï 2-6 (array.php). ::Welcome to PHP Array on demenssion

Neáu nhö baïn khai baùo maûng hai chieàu, thì cuù phaùp khai baùo nhö sau: $myarrs[][]=array(2,3);

Chaúng haïn khai baùo nhö ví duï 2-7 (arrays.php): ::Welcome to PHP Array two demenssions

3.5. Kieåu ñoái töôïng
Ñeå khai baùo ñoái töôïng, baïn söû duïng khaùi nieäm class nhö trong ngoân ngöõ laäp trình C hay java, ngoaøi ra phöông thöùc trong PHP ñöôïc bieát ñeán nhö moät haøm. Ñieàu naøy coù nghóa laø töø khoaù laø function. Neáu haøm coù teân truøng vôùi teân cuûa class thì haøm ñoù ñöôïc goïi laø constructor. Chaúng haïn, chuùng ta khai baùo class vaø khôûi taïo chuùng thì töï ñoäng constructor ñöôïc goïi moãi khi ñoái töôïng khôûi taïo, sau ñoù goïi haøm trong class ñoù nhö ví duï 2-8 (object.php). ::Welcome to PHP Object

WWW.HUUKHANG.COM

echo "I am a regular function named B in class A.\n"; echo "I am not a constructor in A.\n";

3.6. Taàm vöïc cuûa bieán
Taàm vöïc cuûa bieán phuï thuoäc vaøo nôi khai baùo bieán, neáu bieán khai baùo beân ngoaøi haøm thì seõ coù taàm vöïc trong trang PHP, trong tröôøng hôïp bieán khai baùo trong haøm thì chæ coù hieäu löïc trong haøm ñoù. Ví duï, chuùng ta coù bieán $a khai baùo beân ngoaøi haøm nhöng khi vaøo trong haøm thì bieán $ ñöôïc khai baùo laïi, bieán naøy coùtaàm vöïec beân trong haøm. Töông töï nhö vaäy, khi bieán $i khai baùo trong haøm thì chæ coù taàm vöïc beân trong haøm cho duø chuùng ñöôïc khai baùo laïi beân ngoaøi nhö ví duï 2-9 (scope.php). ::Welcome to PHP Scope of Variable

Ngoaøi ra, ñeå söû duïng bieán toaøn cuïc trong haøm, baïn söû duïng töø khoa global, khi ñoù bieán toaøn cuïc seõ coù hieäu löïc beân trong haøm. Ví duï khai baùo bieán $a beân ngoaøi haøm, sau ñoù beân trong haøm Test baïn söû duïng töø khoaù global cho bieán $a, khi ñoù bieán $a seõ ñöôïc söû duïng vaø giaù trò ñoù coù hieäu löïc sau khi ra khoûi haøm chöù khoâng goáng nhö tröôøng hôïp trong ví duï scope.php nhö ví duï 2-10 (global.php). ::Welcome to PHP

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER Scope of Variable

WWW.HUUKHANG.COM

4. HAÈNG TRONG PHP 4.1. Khai baùo vaø söû duïng haèng
Haèng laø giaù trò khoâng thay ñoåi keå töø sau khi khai baùo, baïn coù theå söû duïng phaùt bieåu Define ñeå khai baùo haèng nhö sau: define("MAXSIZE", 100);

Ñeå söû duïng haèng, baïn khai baùo nhö ví duï 2-11 (constant.php) ::Welcome to PHP Constant

4.2.

Kieåm tra haèng

Khi söû duïng haèng, maø haèng chöa toàn taïi thì baïn söû duïng haøm defined nhö ví duï 212 sau (defained.php):

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER ::Welcome to PHP Constant

WWW.HUUKHANG.COM

5. KEÁT LUAÄN
Trong baøi naøy, chuùng ta tìm hieåu caùch khai baùo haèng, bieán vaø söû duïng haèng bieán. Ngoaøi ra, baïn cuõng tìm hieåu caùch chuyeån ñoåi kieåu döõ lieäu, kieåm tra kieåu döõ lieäu, taàm vöïec cuûa bieán.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Baøi 3 PHEÙP TOAÙN VAØ PHAÙT BIEÅU COÙ ÑIEÀU KIEÄN TRONG PHP Chöông naøy chuùng ta seõ laøm quen vaø tìm hieåu toaùn töû, phaùt bieåu coù ñieàu kieän vaø voøng laëp cuûa PHP. Nhöõng vaán ñeà chính seõ ñöôïc ñeà caäp trong baøi hoïc naøy Toaùn töû. Pheùp gaùn trong PHP Phaùt bieåu coù ñieàu khieån. Voøng laëp.

1. KHAÙI NIEÄM VEÀ CAÙC TOAÙN TÖÛ TRONG PHP

Khi baïn laäp trình treân PHP laø söû duïng cuù phaùp cuûa ngoân ngöõ C, C++. Töông töï nhö nhöõng ngoân ngöõ laäp trình khaùc, toaùn töû giuùp cho baïn thöïc hieän nhöõng pheùp toaùn nhö soá hoïc hay treân chuoãi. Baûng sau ñaây giuùp cho baïn hình dung ñöôïc nhöõng toaùn töû söû duïng trong PHP, PHP ñònh nghóa toaù töû toaùn hoïc, quan heä, soá hoïc, bit vaø noät soá pheùp toaùn gaùn. Loaïi toaùn töû Toaùn töû + * / % > < >= < >= 2.2. Toaùn töû Not: ~ And !

Toaùn töû ~ ñaûo nghòch taát caû caùc bit cuûa tham soá, coøn toaùn töû ! ñaûo nghòch giaù trò cuûa giaù trò tröôùc ñoù. Chaúng haïn trong tröôøng hôïp naøy chuùng ta söû duïng cho bieåu thöùc hay bieán coù giaù trò boolean. Ví duï 3.2: Pheùp toaùn ~ and ! ::Welcome to PHP ~, ! Operator 2.3. Toaùn töû nhaân vaø chia: * and /

Baïn coù theå tham khaûo ví duï sau Ví duï 3.3: Pheùp toaùn * vaø /, + vaø ::Welcome to PHP

huukhang@yahoo.com

3-3

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Multi And Divide Operator 2.4. Toaùn töû modulus: %

Khi chia moät soá cho moät soá, baïn caàn keát quaû laø soá dö cuûa pheùp chia ñoù thì duøng toaùn töû modulus Ví duï 3.4: Pheùp toaùn % ::Welcome to PHP Mod Operator 2.5. Toaùn töû quan heä: >=,>,=, 2.7. Toaùn töû ?:

Toaùn töû naøy thay theá cho phaùt bieåu coù ñieàu kieän if...else, khi baïn caàn laáy keát quaû theo ñieàu kieän naøo ñoù, neáu coù theå khoâng caàn phaùt bieåu if-else, thì haõy thay theá baèng toaùn töû ?:, cuù phaùp cuûa chuùng nhö sau: str1=str2.equals(”khang”)?”Welcome to PHP”:”Good bye PHP”; Ví duï 3.7: Pheùp toaùn ?:

huukhang@yahoo.com

3-5

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

::Welcome to PHP Selection Operators 3. PHEÙP GAÙN

Khi gaùn moät giaù trò hay bieán vaøo moät bieán trong PHP, baïn phaûi duøng ñeán pheùp gaùn, nhöng trong PHP cuõng gioáng nhö trong C thì coù nhöõng pheùp gaùn ñöôïc ñôn giaûn hoaù hay noùi ñuùng hôn laø chuaån hoaù ñeå ruùt goïn laïi trong khi vieát.
3.1. Pheùp gaùn thoâng thöôøng nhaát nhö sau:

$j=i; $str1 =” Hello!”; $b=true;
3.2. Pheùp gaùn theâm moät giaù trò laø 1

$k=0; $k++;
3.3. Pheùp gaùn chuoãi

$strX="Hello"; $strX.=” world”; $strX.=”ABCc”.$x;
3.4. Pheùp gaùn theâm moät vôùi chính noù giaù trò

$k=0;$j=1; $k+=$j; töông töï nhö vaäy chuùng ta coù $k*=2, nghóa laø $k=$k*2
4. PHAÙT BIEÅU COÙ ÑIEÀU KIEÄN

Caùc phat bieåu coù ñieàu kieän nhö : IF (ñieàu kieän) { caâu leänh; } IF (ñieàu kieän) { caâu leänh; }ELSE { caâu leänh; }

huukhang@yahoo.com

3-6

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

IF (ñieàu kieän) { caâu leänh; }ELSEIF { caâu leänh; } switch (ñieàu kieän) { case Value1 caâu leänh1; break; } While (ñieàu kieän) Do - While (ñieàu kieän) Break Continue
4.1. Phaùt bieåu IF (ñieàu kieän) { caâu leänh; }

Söû duïng phaùt bieåu if ñeå choïn loïc keát quaû khi ñieàu kieän ñuùng, ví duï nhö sau: Ví duï 3.8: Phaùt bieåu IF ::Welcome to PHP IF Statement 4.2. Phaùt bieåu IF (ñieàu kieän) { caâu leänh; }ELSE { caâu leänh; }

Söû duïng phaùt bieåu if ñeå choïn loïc keát quaû khi ñieàu kieän ñuùng, vaø xuaát ra keát quaû khi ñieàu kieän sai, ví duï nhö sau: Ví duï 3.9: Phaùt bieåu IF - ELSE

huukhang@yahoo.com

3-7

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

::Welcome to PHP IF ELSE Statement 4.3. Phaùt bieåu ELSEIF

Phaùt bieåu elseif laø phaàn cuûa phaùt bieåu if else nhieàu nhaùnh, khi coù nhieàu ñieàu kieän choïn löïa thì baïn söû duïng elseif, cuù phaùp cuûa chuùng nhö sau: ::Welcome to PHP ELSEIF Statement 4.4. Phaùt bieåu Switch (ñieàu kieän)

Phaùt bieåu switch laø phaàn cuûa phaùt bieåu elseif nhieàu nhaùnh, khi coù nhieàu ñieàu kieän choïn löïa thì baïn söû duïng switch, cuù phaùp cuûa chuùng nhö sau:

huukhang@yahoo.com

3-8

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Switch(ñieàu kieän) { case Value1 caâu leänh1; break; case Value2 caâu leänh2; break; … default: caâu leänh default; } Break: duøng ñeå thoaùt ra khoûi switch khi thoaû moät case naøo ñoù trong switch, default: khi khoâng coù baát kyø giaù trò naøo thoaûn trong caùc case thì giaù trò cuoái cuøng laø defaule statement Ví duï 3.10: Phaùt bieåu Switch ::Welcome to PHP SWITCH Statement 4.5. Phaùt bieåu While(ñieàu kieän)

true.

Phaùt bieåu while thöïc thi nhöõng caâu leänh trong while khi ñieàu kieän coù giaù trò

Ví duï 3.11: Phaùt bieåu While ::Welcome to PHP While Statement 4.6. Phaùt bieåu For

sau:

Phaùt bieåu for duøng cho voøng laëp coù giôùi haïn cho tröôùc, cuù phaùp coù daïng nhö

Ví duï 3.12: Phaùt bieåu For

huukhang@yahoo.com

3-10

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

::Welcome to PHP FOR Statement 4.7. Phaùt bieåu do while

Phaùt bieåu do while cho pheùp duyeät vaø kieåm tra ñieàu kieän sau phaùt bieåu thöù nhaát, ñieàu naøy coù nghóa laø ít nhaát moät phaùt bieåu ñöôïc thöïc hieän. Ví duï 3.13: Phaùt bieåu Do While ::Welcome to PHP Do While Statement

Phaùt bieåu exit cho pheùp thoùat ra khoûi phaùt bieåu ñieàu kieän khi thoaû ñieàu kieän naøo ñoù. Ví duï 3.14: Phaùt bieåu exit ::Welcome to PHP Exit Statement 5. TOÙM TAÉT

Trong baøi hoïc naøy chuùng toâi giôùi thieäu ñeán cho caùc baïn caùc pheùp gaùn, caùc toaùn töû, ñoàng thôøi giuùp cho caùc baïn hieåu theâm vaøo caùc phaùt bieåu coù ñieàu kieän nhö while, for, switch, ….

huukhang@yahoo.com

3-12

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Moân hoïc: PHP Baøi 4

Baøi hoïc naøy chuùng ta seõ laøm quen vôùi bieán form vaø hai phöông thöùc $HTTP_POST_VARS vaø $HTTP_GET_VARS cuûa PHP:
Bieán form. Phöông thöùc $HTTP_GET_VARS Phöông thöùc $HTTP_POST_VARS

1. BIEÁN FORM
Bieán form trong PHP ñöôïc bieát ñeán nhö moät loaïi bieán, thay vì khai baùo thì bieán ñoù chính laø teân cuûa theû nhaäp lieäu trong trang submit hay tham soá treân querystring.

1.1. Bieán form töø form ñöôïc submit vôùi phöông thöùc POST
Trong trang baïn submit ñeán, neáu khai baùo teân cuûa theû naèm trong theû form coù teân laø xyz thì bieán form ñöôïc ñònh nghóa laø $xyz. Chaúng haïn, baïn khai baùo baùo theû form trong trang submit.php nhö ví duï 4-1. Ví duï 4-1: Khai baùo theû form
... Name: Gender : Male Female   ...

Khi ngöôøi söû duïng nhaäp giaù trò vaøo phaàn Name vaø choïn giôùi tính Male hay Female nhö hình 4-1, neáu nhaán nuùt submit thì trang ex1-1.php seõ trieäu goïi, trong trang naøy baïn coù theå laáy giaù trò nhaäp töø trang ex1.php baèng caùch söû duïng bieán form nhö ví duï 4-1-1. Ví duï 4-2: Duøng bieán form ::Welcome to PHP Form variable Name :

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER Gender :

WWW.HUUKHANG.COM

Trong ñoù, $fullname vaø $gender laø teân cuûa hai theû input trong trang ex1.php, trong tröôøng hôïp naøy chuùng ta söû duïng phöông thöùc POST cho form.

Hình 4-1: Nhaäp lieäu

Keát quaû traû veà nhö hình 4-1-1.

Hình 4-1-1: Keát quaû laáy töø trang submit baèng bieán form

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

1.2. Bieán form töø form ñöôïc submit vôùi phöông thöùc GET
Neáu baïn söû duïng phöông thöùc GET trong theû form, baïn coù theå laáy giaù trò cuûa caùc tham soá treân chuoãi QueryString baèng bieán form. Ví duï khai baùo theû form coù hai tuyø choïn nhö ví duï 4-2 vôùi phöông thöùc GET trong theû form. Ví duï 4-2: Khai baùo theû form
... Province : Ha Noi Ho Chi Minh Hue Industry : Automobile Foods Enginering Garment   ...

Khi trieäu goïi trang ex2.php treân trình duyeät, ngöôøi söû duïng choïn giaù trò trong hai tuyø choïn Province vaø Industry nhö hình 4-2.

Hình 4-2: Phöông thöùc GET

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Neáu nhaán Submit thì hai giaù trò choïn seõ ñöôïc truyeàn leân treân QueryString vôùi hai tham soá laø teân cuûa theû select. Ví duï trong tröôøng hôïp naøy keát quaû traû veà nhö hình 42-1.

Hình 4-2-1: Bieán form vôùi phöông thöùc GET Trong ñoù, hai tham soá vaø giaù trò töông öùng laø ex21.php?province=HAN&industry=FOO, baèng caùch söû duïng bieán form baïn coù theå laáy ñöôïc giaù trò naøy nhö ví duï 4-2-1. Ví duï 4-2-1: Khai baùo theû form ::Welcome to PHP Form variable Province : Industry :

Ñoái vôùi tröôøng hôïp baïn khoâng söû duïng theû form nhö hai tröôøng hôïp treân, chuùng ta cuõng coù theå laáy giaù trò töø chuoãi QueryString baèng bieán form. Chaúng haïn, baïn khai baùo trang chop pheùp ngöôøi söû duïng choïn kyù töï ñeå lieät keâ danh saùch khaùch haøng theo kyù töï ñoù nhö hình 4-3.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Hình 4-3: Choïn kyù töï Baèng caùch khai baùo caùc theû baïn ñònh nghóa 24 kyù töï nhö hình treân vôùi tham soá al coù giaù trò töông öùng: A | B | C | D | E | All

Khi ngöôøi söû duïng choïn moät kyù töï thì söû duïng bieán form laø teân cuûa tham soá (al), baïn coù theå laáy ñöôïc giaù trò cuûa kyù töï ñang choïn:
Select:

Tuy nhieân, laán ñaàu tieân trieäu goïi trang naøy maø khoâng coù tham soá treân QueryString, khai baùo bieán form seõ phun ra loãi nhö hình 4-3-1. Ñeå traùnh tröôøng hôïp naøy, baïn söû duïng haøm isset ñeå kieåm tra bieán toàn taïi hay khoâng, neáu toàn taïi thì baïn söû duïng bieán form naøy. Ví duï ñoái vôùi tröôøng hôïp naøy chuùng ta khai baùo nhö ví duï 4-3. Ví duï 4-3: Söû duïng bieán form ::Welcome to PHP Form variable List by Alphabet

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER A | B | C | D | E | All Select:

WWW.HUUKHANG.COM

Hình 4-3-1: Loãi phaùt sinh Chuù yù raèng, khi söû duïng bieán form baïn khoâng neân khai baùo bieán cuøng teân vôùi caùc tham soá hay teân cuûa theû nhaäp lieäu trong trang trieäu goïi tröôùc ñoù. Neáu khoâng thì giaù trò traû veà laø giaù trò cuûa bieán thöôøng thay vì bieán form.

2. PHÖÔNG THÖÙC $HTTP_GET_VARS
Ngoaøi caùch söû duïng bieán form trong tröôøng hôïp laáy giaù trò töø tham soá cuûa QueryString, baïn coù theå söû duïng haøm $HTTP_GET_VARS. Ví duï, chuùng ta khai baùo trang PHP nhö ví duï 4-4. Ví duï 4-4: Söû duïng $HTTP_GET_VARS

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER ::Welcome to PHP Form variable Province: Ha Noi Ho Chi Minh Hue

WWW.HUUKHANG.COM

Löu yù raèng, neáu baïn khoâng söû duïng haøm isset ñeå kieåm tra province toàn taïi hay khoâng thì trang php seõ phun loãi trong tröôøng hôïp laàn ñaàu tieân goïi ñeán trang ex4.php maø khoâng submit. Tuy nhieân, neáu baïn submit trang naøy thì keát quaû traû veà nhö hình 4-4.

Hình 4-4: Duøng $HTTP_GET_VARS Töông töï nhö vaäy trong tröôøng hôïp baïn khoâng söû duïng theû form maø giaù trò laáy töû chuoãi QueryString baèng caùch söû duïng $HTTP_GET_VARS nhö ví duï 4-5. Ví duï 4-5: Söû duïng $HTTP_GET_VARS ::Welcome to PHP

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Form variable List by Alphabet A | B | C | D | E | All Select:

Keát quaû traû veà nhö hình 4-5.

Hình 4-5: Söû duïng $HTTP_GET_VARS

3. PHÖÔNG THÖÙC $HTTP_POST_VARS
Töông töï nhö $HTTP_GET_VARS nhöng $HTTP_POST_VARS cho pheùp baïn laáy giaù trò laáy töø caùc theû nhaäp lieäu cuûa theû form trong traang submit tröôùc ñoù. Ví duï, baïn khai baùo trang nhaäp lieäu nhö ví duï 4-6. Ví duï 4-5: Khai baùo form vôùi phöông thöùc POST ::Welcome to PHP

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER Form variable User Name : Password :  

WWW.HUUKHANG.COM

Khi ngöôøi söû duïng nhaäp username vaø password nhö hình 4-6 vaø nhaán nuùt Login.

Hình 4-6: Ñaêng nhaäp Baèng caùch söû duïng $HTTP_POST_VARS ñeå laáy giaù trò username vaø password nhö ví duï 4-7. Ví duï 4-5: Söû duïng $HTTP_POST_VARS ::Welcome to PHP Form variable

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Username : Password :

Keát quaû trình baøy nhö hình 4-7.

Hình 4-7: Duøng $HTTP_POST_VARS

4. KEÁT LUAÄN
Trong baøi naøy, chuùng ta tìm hieåu caùch söû duïng bieán form vaø hai phöông thöùc $HTTP_POST_VARS, $HTTP_GET_VARS. Ngoaøi ra, baïn cuõng tìm hieåu caùch kieåm tra bieán toàn taïi hay khoâng baèng haøm isset(). Chuù yù raèng, khi söû duïng bieán form baïn traùnh tröôøng hôïp khai baùo bieán cuïc boä hay toaøn cuïc trong tang PHP cuøng teân vôùi theû nhaäp lieäu cuûa form tröôùc ñoù submit ñeán hay tham soá treân querystring.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Moân hoïc: PHP Baøi 5

Baøi hoïc naøy chuùng ta seõ laøm quen vôùi ñoái töôïng Session vaø moät soá ñoái töôïng khaùc:
Ñoái töôïng Session. Ñoái töôïng khaùc

1. ÑOÁI TÖÔÏNG SESSION
Trong PHP4.0 ñoái töôïng Session ñöôïc xem nhö moät ñoái töôïng cho pheùp baïn truyeàn giaù trò töø trang PHP naøy sang PHP khaùc. Ñeå söû duïng Session, baïn khai baùo thö muïc ñöôïc löu tröõ döõ lieäu do ñoái töôïng nay ghi ra. Session ñöôïc sinh ra vaø ñöôïc bieán maát khi ngöôøi söû duïng huyû chuùng, thôøi gian soáng cuûa chuùng ñaõ heát hoaëc ngöôøi söû duïng ñoùng trình duyeät. Chaúng haïn, trong tröôøng hôïp naøy chuùng ta söû duïng thö muïc C:\PHP\sessiondata ñöôïc khai baùo trong taäp tin php.ini. session.save_path = C:\PHP\sessiondata

Ngoaøi ra, khi muoán söû duïng Sessoin thì baïn phaûi khôûi taïo chuùng. Ñeå khôûi taïo Session baïn coù theå khôûi taïo trong trang PHP moãi khi truy caäp hay gaùn giaù trò cho Session. session_start(); Tuy nhieân, baïn coù theå caáu hình trong trang php.ini (1 laø start). session.auto_start = 0

1.1. Nhaän daïng Session
Moãi phieân laøm vieäc ñöôïc taïo ra töø Web Server thì seõ coù moät nhaän daïng duy nhaát coù giaù trò laø chuoãi do trình chuû Web taïo ra. Ñieàu naøy coù nghóa laø moãi khi ngöôøi söû duïng trieäu goïi trang Web cuûa Web Site laàn ñaàu tieân thì phieân laøm vieäc seõ ñöôïc taïo ra, khi ñoù moät nhaän daïng ñöôïc caáp cho phieân laøm vieäc ñoù. Ñeå laán giaù trò nhaän daïng cuûa Session do trình chuû Web caáp phaùt baïn söû duïng cuù phaùp:
$x= session_id();

Chaúng haïn, baïn khai baùo baùo ñeå laáy giaù trò session_id trong trang sessionid.php nhö ví duï 5-1. Ví duï 5-1: Nhaän daïng session

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER ::Welcome to PHP Session_ID

WWW.HUUKHANG.COM

Moãi ngöôøi söû duïng truy caäp ñeán Web Site seõ coù moät nhaän daïng khaùc nhö nhö hình 51.

Hình 5-1: Nhaän daïng duy nhaát

1.2. Khai baùo Session
Khi muoán khai baùo bieán session, baïn phaûi söû duïng haøm session_register coù cuù phaùp nhö sau: session_register("sessioname"); Khi muoán khôûi taïo session, baïn coù theå gaùn giaù trò cho session naøy nhö gaùn giaù trò cho bieán trong PHP, sau ñoù söû duïng haøm treân ñeå ñaéng kyù.
$sessioname=value; session_register("sessioname");

Trong tröôøng hôïp coù nhieàu session, baïn coù theå söû duïng haøm session_register ñeå ñaêng kyù cuøng moät luùc nhieàu session nhö sau:
$sessioname1=value1; $sessioname2=value2;

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

$sessioname3=value3; session_register("sessioname1","sessioname2","sessioname3");

Chaúng haïn, trong tröôøng hôïp naøy chuùng ta khai baùo trang sessionregister.php vaø ñaêng kyù 3 sessoin coù teân userid, email vaø fullname nhö ví duï 5-2 sau: Ví duï 5-2: Ñaêng kyù session ::Welcome to PHP Registered Session

Keát quaû traû veà nhö hình 5-2.

Hình 5-2: Ñaêng kyù Session

1.3. Laáy giaù trò töø session
Sau khi khai baùo khôûi aïo moät soá session vôùi giaù trò töông öùng cuûa session ñoù, baïn coù theå truy caäp caùc bieán session naøy ñeå laáy giaù trò torng trang PHP khaùc. Chaúng haïn, chuùng ta khai baùo trang getsession.php ñeå laáy caùc session cuûa PHP vöøa khai baùo trong ví duï treân nhö ví duï 5-3. Ví duï 5-3: Laáy giaù trò töø session Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

::Welcome to PHP Get Session

Khi trieäu goïi trang getsession.php treân trình duyeät baïn trình baøy giaù trò cuûa session userid, email vaø fullname nhö hình 5-3.

Hình 5-3: Laáy giaù trò cuûa session Tuy nhieân, trong tröôøng hôïp baïn truy caäp moät bieán session chöa khôûi taïo tröôùc ñoù thì l64i seõ phaùt sinh. Ví duï trong tröôøng hôïp naøy chuùng ta truy caäp bieán session coù teân $address nhö ví duï 5-4. Ví duï 5-4: Truy caäp session chöa toàn taïi ::Welcome to PHP

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER Get Session

WWW.HUUKHANG.COM

Khi trieäu goïi trang unregistersession.php treân trình duyeät thì loãi phaùt sinh nhö hình 5-4.

Hình 5-4: Loãi phaùt sinh Ñeå kieåm tra session ñoù coù toàn taïi hay chöa baïn söû duïng haøm session_is_register trong trang checksession.php. Ñoái vôùi tröôøng hôïp naøy chuùng ta caàn kieåm tra 4 session tröôùc khi truy caäp ñeán chuùng nhö ví duï 5-5. Ví duï 5-5: Kieåm tra session ::Welcome to PHP Get Session

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Khi trieäu goïi trang checksession.php thì keát quaû seõ trình baøy nhö hình 5-5.

Hình 5-5: Khoâng coù loãi phaùt sinh Chuù yù raèng, khi söû duïng ñeán session, baïn phai khôûi ñoäng chuùng baèng session_start() neáu khoâng thì phaûi khai baùo trong php.ini.

1.4. Huyû session
Khi khoâng coù nhu caàu söû duïng session nöõa thì baïn söû duïng haøm session_unregister ñeå loaïi session ñoù. Chaúng haïn, trong tröôøng hôïp naøy chuùng ta muoán loaïi boû session coù teân laø fullname baïn khai baùo trong trang sessionunregister.php nhö ví duï 5-6. Ví duï 5-6: Loaïi boû moät Session ::Welcome to PHP

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER UnRegister Session

WWW.HUUKHANG.COM

Khi trieäu goïi trang sessionunregister.php treân trình duyeät thìkeát quaû traû veà nhö hình 56.

Hình 5-6: Loaïi boû session Trong tröôøng hôïp loaïi boû taát caùc session ñang toàn taïi thì söû duïng haøm session_unset(). Ví duï duøng haøm naøy ñeå laïoi boû session vaø duøng haøm sessin_destroy ñeå huyû taát caû session ñoù khai baùo trong trang unset.php nhö ví duï 5-7. Ví duï 5-7: Xoaù taát caû session ::Welcome to PHP UnSet Session

WWW.HUUKHANG.COM

Keát quaû traû veà nhö hình 5-7.

Hình 5-7: Huyû session

2. COOKIE
Cookie ñöôïc xem nhö session, tuy nhieân chuùng löu tröõ thoâng tin treân trình khaùch. Ñeå söû duïng Cookie, baïn söû duïng haøm setcookie ñeå gaùn giaù trò nhö ví duï 5-8. Ví duï 5-8: Gaùn giaù trò cho cookie ::Welcome to PHP Cookie

Khi ngöôøi söû duïng trieäu goïi trang setcookie.php keát quaû traû veà nhö hình 5-8.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Hình 5-8: Ñaéng kyù cookie Ngaøi ra, baïn coù theå gaùn giaù trò cookie baèng session. Chaúng haïn, chuùng ta söû duïng haøm session_set_cookie_params ñeå gaùn cookie nhö ví duï 5-9. Ví duï 5-9: Gaùn cookie baèng session ::Welcome to PHP Session-Cookie

Baèng caùch söû duïng $HTTP_COOKIE_VARS ñeå laáy giaù trò cuûa cookie tröôùc ñoù trong trang httpcookievar.php nhö ví duï 5-10. Ví duï 5-10: Söû duïng $HTTP_COOKIE_VARS ::Welcome to PHP Get Cookie

Keát quaû trình baøy nhö hình 5-10.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Hình 5-10: Duøng $HTTP_COOKIE_VARS Baèng caùch söû duïng haøm session_get_cookie_params ñeå laáy giaù trò cuûa cookie tröôùc ñoù trong trang sessiongetcookie.php nhö ví duï 5-11. Ví duï 5-11: Söû duïng session_get_cookie_params ::Welcome to PHP Get Cookie

3. KEÁT LUAÄN
Trong baøi naøy, chuùng ta tìm hieåu caùch söû duïng bieán session vaø cookie.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

Moân hoïc: PHP Baøi 6

Baøi hoïc naøy chuùng ta seõ laøm quen caùch khai baùo haøm, cheøn taäp tin vaø taäp tin duøng chung:
Caùch khai baùo haøm. Xaây döïng taäp tin ñònh daïng noäi dung Taäp tin duøng chung

1. KHAI BAÙO HAØM TRONG PHP
Haøm do ngöôøi söû duïng ñònh nghóa cho pheùp baïn xöû lyù nhöõng taùc vuï thöôøng laëp ñi laëp laïi trong öùng duïng. Ñeå khai bao haøm, baïn söû duïng töø khoaù function vôùi cuù phaùp töông töï nhö sau: function functioname($parameter) { return value; }

Trong tröôøng hôïp haøm khoâng coù giaù trò traû veà thì haøm ñöôïc xem nhö thuû tuïc. Ngoaøi ra, baïn coù theå khai baùo tham soá tuyø choïn baèng caùch gaùn giaù trò maëc ñònh cho tham soá. Ví duï chuùng ta khai baùo: function functioname($parameter1, $parameter2=10 ) { return value; }

Ñoái vôùi tröôøng hôïp naøy thì tham soá $parameter1 laø tham soá baét buoäc vaø tham soá $parameter2 laø tham soá tuyø choïn, khi goïi haøm neáu khoâng cung caáp tham soá cho $parameter2 thì tham soá naøy coù giaù trò laø 10. Ví duï, baïn khai baùo trang function.php coù haøm getResult nhaän hai soá vaø pheùp toaùn sau ñoù tuyø thuoäc vaøo pheùp toaùn haøm traû veà keát quaû. Neáu ngöôøi söû duïng khoâng cung vaáp pheùp toaùn thì maëc ñònh laø pheùp toaùn +. ::Welcome to PHP Function

Neáu muoán ñònh nghóa function khoâng coù giaù trò traû veà, baïn coù theå khai baùo trong trang void.php nhö ví duï sau:
... function calloperator() { echo "result of default operator: ".getResult(10,20); echo ""; echo "result of * operator: ".getResult(10,20,"*"); } calloperator(); ?>

Trong tröôøng hôïp truyeàn tham soá nhö tham bieán, baïn söû duïng kyù hieäu & tröôùc tham soá, chaúng haïn chuùng ta khai baùo haøm coù tham bieán coù teân average nhö trong trang reference.php nhö sau: ::Welcome to PHP Function

echo "result of Average is : ".$bq; echo ""; function getAmounts($quantity, $price,$average) { $result=0; $result=$quantity*$price; $average=$result*6/12; return $result; } $bq=0; echo "result is : ".getAmounts(10,20,$bq); echo ""; echo "result of Average is : ".$bq;

Trong tröôøng hôïp treân thì haøm getAmount coù tham soá $average laø tham bieán coøn haøm getAmounts coù tham soá $average laø tham trò, vaø keát quaû traû veà cuûa bieán $bq khi goïi haøm getAmount laø 100 trong khi ñoù giaù trò cuûa bieán naøy trong haøm getAmounts laø 0.

2. XAÂY DÖÏNG TAÄP TIN ÑÒNH DAÏNG NOÄI DUNG
Khi trình baøy noäi dung treân trang HTML hay trang PHP, ñeå thoáng nhaát ñònh daïng chuoãi trong theû body hay theû div chaúng haïn baïn caàn khai baùo theû style trong theû . A{ COLOR: #003063; TEXT-DECORATION: none } A:hover { COLOR: #003063; TEXT-DECORATION: underline } A:link { FONT-WEIGHT: bold; COLOR: red; TEXT-DECORATION: none } A:visited { FONT-WEIGHT: bold; COLOR: black; TEXT-DECORATION: none } .title { FONT-WEIGHT: normal; FONT-SIZE: 22px } .text{ FONT: 11px Arial, Helvetica, sans-serif }

Trong ñoù, A töông öùng vôùi lieân keát (chuoãi trong theû ) coù ñònh daïng öùng vôùi tröôøng hôïp lieân keát, di chuyeån con chuoät, choïn lieân keát.
A{ COLOR: #003063; TEXT-DECORATION: none } A:hover {

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER COLOR: #003063; TEXT-DECORATION: underline

WWW.HUUKHANG.COM

} A:link { FONT-WEIGHT: bold; COLOR: red; TEXT-DECORATION: none } A:visited { FONT-WEIGHT: bold; COLOR: black; TEXT-DECORATION: none }

Chaúng haïn, chuùng ta khai baùo trang PHP vôùi noäi dung ñöôïc aùp duïng vôùi kieåu ñònh daïng khai baùo trong theû style nhö vuù duï 6-1. Ví duï 6-1: Khai baùo theû style Style trong PHP A{ COLOR: #003063; TEXT-DECORATION: none } A:hover { COLOR: #003063; TEXT-DECORATION: underline } A:link { FONT-WEIGHT: bold; COLOR: red; TEXT-DECORATION: none } A:visited { FONT-WEIGHT: bold; COLOR: black; TEXT-DECORATION: none } .title { FONT-WEIGHT: normal; FONT-SIZE: 22px; COLOR: #003063; } .text{ FONT: 11px Arial, Helvetica, sans-serif } Style Tag *** Quaûn Trò SQL Server 2000 *** Tìm hieåu caùch caøi ñaët, caáu hình, quaûn trò, backup & restore, import & export, thieát

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

keá, laäp trình, töï ñoäng hoaù taùc vuï quaûn trò, baûn sao döõ lieäu, baûo maät vaø choáng thaâm nhaäp döõ lieäu baèng. SQL Injection.

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER BODY RIGHT BOTTOM

Trong ñoù trang templates.PHP khai baùo cheøn top.htm, left.htm, right.htm vaø bottom.htm nhö ví duï 6-5. Ví duï 6-5: Khai baùo cheøn taäp tin trong templates.php Welcome to HUUKHANG.COM

Giaùo vieân: Phaïm Höõu Khang

COMPUTER LEARNING CENTER ">

Similar Documents

Premium Essay

Get Off the Phone

...Get Off the Phone Richard L. Weaver COMM/215 February 2, 2015 William Morgan Get Off the Phone Everyone who has ever owned a portable communication device has done it at one time or another. Many people do it habitually. It can even be construed as an addiction that is reaching epidemic proportions, not only in the United States but worldwide. Its negative effects are seen and heard about on a daily basis and it is dangerous to the point of causing death. The referred to issue is driving and talking or texting on the cell phone simultaneously. The purpose of this study is to determine the detrimental effects of cell phone usage while operating a motor vehicle and invoke an awareness of the dangers involved, particularly in the area of texting and driving. Proof of these dangers will be brought to bear via expert analysis and statistical facts. It will also examine the laws enacted in recent years to deter this activity. In a report issued in June 2006 by University of Utah psychologist Dr. Frank Drews et al stated that “We found that people are as impaired when they drive and talk on the cell phone as they are when they drive intoxicated at the legal blood alcohol limit of 0.08 percent.” Our brain does not have the cognitive ability to perform the two separate tasks of having a phone conversation and driving at the same time. The danger lies not within the “manual or visual interface with the device but in the conversation itself” (Rosenberger, 2013)...

Words: 1170 - Pages: 5

Free Essay

Business

...(NOT FOR ATTRIBUTION; FOR DISCUSSION PURPOSES ONLY) Preserving Cultural Heritage through Good Environmental Management in Vigan City, Ilocos Sur: A Contribution to the Philippines Country Environmental Analysis Draft for discussion Do not quote September 2008 1 Elmer S. Mercado, EnP World Bank Consultant. The findings, interpretations, and conclusions expressed herein are those of the author, and do not necessarily reflect the views of the World Bank and its affiliated organizations, or those of the Executive Directors of the World Bank or the governments they represent. This paper represents work in progress and comments to the author are invited (elmer_sm@yahoo.com). 1 (NOT FOR ATTRIBUTION; FOR DISCUSSION PURPOSES ONLY) Summary One of the critical challenges of urbanisation in developing countries is how to rein in the environmental impacts of progress with the need to maintain one’s sense of social history, culture and heritage. Like the cities of Seville in Spain, Kyoto in Japan, Rome in Italy or even Manila in the Philippines, Vigan City wanted to remove the ravages of political warlordism that plagued its recent past and reclaim its once rich Spanish colonial cultural heritage and prestige it held in the 19th century. When the city of Vigan decided to transform itself as a cultural heritage city, one of the core platforms of the city’s cultural and heritage conservation programme and master plan was the environmental conservation and management of its...

Words: 7511 - Pages: 31

Premium Essay

Btec Business Level 3 Unit 1 D1

...Languages: A high-level programming language that is interpreted by another program at runtime rather than compiled by the computer's processor as other programming languages (such as C and C++) are called scripting languages. These can be embedded within HTML, commonly are used to add functionality to a Web page, such as different menu styles, graphic displays or dynamic content. Type of Scripting Languages: There are two types of scripting languages, which are: I. Client Side Scripting II. Server...

Words: 2251 - Pages: 10

Premium Essay

Essay

...Texting and Driving Joaquin Colon DeVry University Prewriting What is your narrowed topic? Be detailed in your answer. You can use any of the versions you’ve developed for prior assignments. Texting and Driving. In a growing habit becoming more dangerous than drinking and driving for the simple fact of the range of people that can incurred in this habit. Who is your primary audience or reader? Why? Be detailed in your answer about your audience. My primary audience will be the youth because statistically are the more prone to text while driving. Young people have grown up in the technology revolution in which for the mentality is that nothing in the social media world can wait or will be absolute within days. In a sentence or short paragraph, what is your thesis statement, including your angle? Write what will appear in your essay. My point is that texting and driving is a problem that concern all ages and different back grounds for the fact that many lives are in jeopardy in the street because of this bad habit. What topic sentences will you use as the foundation of your communication? (If necessary, add more points.) * Is that text worth your life? * Be smart if it is that important pull over. * Don’t let technology decide for you. * Don’t turn your head, be the difference. What method of organization and development will you use to develop your paragraphs? * Introduction: * The main reason could be that 82% of young adults...

Words: 1990 - Pages: 8

Free Essay

Davao: No Smoking City

...WHO smoke-free city case study Advancing the enforcement of the smoking ban in public places – Davao City, Philippines © World Health Organization 2011 All rights reserved. Requests for permission to reproduce or translate WHO publications – whether for sale or for noncommercial distribution – should be addressed to the WHO Centre for Health Development, I.H.D. Centre th Building, 9 Floor, 5-1, 1-chome, Wakinohama-Kaigandori, Chuo-ku, Kobe City, Hyogo Prefecture, 651-0073, Japan (fax: +81 78 230 3178; email: wkc@wkc.who.int). The designations employed and the presentation of the material in this publication do not imply the expression of any opinion whatsoever on the part of the World Health Organization concerning the legal status of any country, territory, city or area or of its authorities, or concerning the delimitation of its frontiers or boundaries. Dotted lines on maps represent approximate border lines for which there may not yet be full agreement. The mention of specific companies or of certain manufacturers’ products does not imply that they are endorsed or recommended by the World Health Organization in preference to others of a similar nature that are not mentioned. Errors and omissions excepted, the names of proprietary products are distinguished by initial capital letters. All reasonable precautions have been taken by WHO to verify the information contained in this publication. However, the published material is being distributed without warranty of any kind...

Words: 6764 - Pages: 28

Premium Essay

Should Abortion Be Legalized?

...Should Abortion be legalized? Introduction To fully understand the issue of abortion, we must first understand exactly what abortion is and the history behind the issue. According to the Webster’s Dictionary (2012) abortion is defined as the “termination of a pregnancy after, accompanied by, resulting in, or closely followed by the death of the embryo or fetus.” An abortion can take place under two different conditions. The two conditions are therapeutic and elective. Therapeutic abortion is when a pregnancy is terminated due to medical condition(s) that may endanger a mother’s health. On the other hand elective abortion is the termination of a pregnancy under any other conditions outside of health (Medical News Today, 2009). Throughout history there were various methods that were used in terminating pregnancies. However even though the methods differed, the trimester or duration of the pregnancy determined what type of procedure is used. Also the severity of the side effects and pain differed by what type of procedure use. According to the Medical News Today (2009) the methods used are clinical, surgical, and herbs. The two main types of abortions are the clinical and surgical. Although both procedures have their risks the herbal tends to be considered “extremely dangerous” compared to clinical and surgical abortion due to its history of causing internal injuries (Medical News Today). Foremost, both the clinical and the surgical procedure are...

Words: 1028 - Pages: 5

Premium Essay

Narrative Essay

...illness in more than two dozen people. Third supporting idea: An outbreak at Jack in the Box restaurants that killed four children. Conclusion Many people have died due to this bacteria, therefore something should be done about it. E. Coli In Ground Beef: Cause of Many Illnesses and Deaths E. coli is a bacterium that is most commonly found in warm blooded organisms. There exists several types of E. coli, many of which are not harmful to human health, except for serotype O157:H7. This serotype can cause food poisoning in humans and even lead to death in some cases. Some signs and symptoms of E. coli O157:H7 are: abdominal pain, diarrhea, nausea, vomiting, fever and fatigue. A healthy adult has a higher chance of fully recovering from this serotype within five to seven days. On the other hand, young children, the elderly and people with weakened immune systems can develop potentially fatal HUS (hemolytic uremic syndrome), a type of kidney failure. A person can be at high risk to becoming ill if they consume things like: soft cheeses, raw milk, apple juice, cider, or undercooked ground beef (Nordqvist).There are many cases where people have become ill and even died because of E. coli in ground beef. On August 16, 2007, Stephanie Smith, a children’s dance instructor, thought she just had a stomach virus. She had aches and cramping, but were tolerable the first day, so decided to finish her classes....

Words: 1000 - Pages: 4

Free Essay

Same-Sex Marriage

...Worse: The Issue of Gay Marriage The legalization of same-sex marriage is a topic that has been argued in our society for several years. It is also a topic that has been opposed by many people not only because it can be hard to accept marriage between gay couples, but it can also be hard to throw away what is considered to be morals, tradition, the natural law of life and the norms of our society. As the population of homosexuals increases, so does the inequality and the discrimination. We have our society to blame for this. Our civil rights and the Constitution give us many liberties. Civil rights including life, liberty and the pursuit of happiness, which those who are homosexual are not allowed to chase. If a gay couple cannot be married to the person they love, than this interferes with the pursuit of happiness which violates their freedoms. With that being said, homosexual couples should get the same civil rights as those who are heterosexual regardless of their sexual orientation. As Americans, we pride ourselves in being a democratic nation and a nation of freedom. One of the most important parts of being a democracy is that we, the people, have a say in what happens in our nation through voting, this including same-sex marriage. As of 2010, gays and lesbians can legally marry in Vermont, New Hampshire, New York, Washington DC, Connecticut, Iowa, and Washington state (Belge). And although this is an improvement in comparison to 20 years ago, having only seven out of fifty...

Words: 1121 - Pages: 5

Premium Essay

Research Paper

...As we go about our daily lives, often times we run into situations that require some form of communication. There are many types and forms of communication such as body language, hand gestures, brail, pictures, language, and sound. All of which allows the user to get some point across. The idea behind each one is to allow somebody else to understand what you need him or her to understand. Thus conveying a point or idea is paramount to understanding others. Unfortunately there are limitations in such deliverance of information. Namely the user and recipient must understand the type of communication. If one does not know how to deliver or receive then we develop a form of miscommunication. Naturally the user or recipient has to improvise and develop a quick understanding of the form. Unfortunately with such a speculation, the understanding is very ambiguous and arbitrary. The user may mean one thing and the recipient might think the complete opposite. In a country as diverse as America, there are many walks of life present. There are communities with almost every imaginable ethnicity, and other areas that are solely one type of race. The segregation makes it difficult at times to communicate with others. The issue is further complicated due to the cultural factor. Some cultures excel at making custom idiomatic expressions, such as Americans. Other Asian cultures may excel in gestural expressions. Lastly sound is an important issue since certain languages or types of communications...

Words: 1947 - Pages: 8

Free Essay

Smoking as a Social Problem

...alcoholanddrugs.aspx 18 Appendix: 19 Questionnaire: 19 Interview Questions: 20 Executive Summary: This paper identifies the reasons as to why people smoke despite of all the threats it poses to their health. It also clarifies if it is the society as well, or the smoker alone who should be blamed for falling a victim to this social evil. It also tries to makes them aware of the hazards of smoking to discourage them from this abhorrent addictive habit, so that they remain safe from all the fatal diseases it brings along. To discover the involvement of society in making a smoker, a survey and multiple interviews were conducted. These research methods pointed out various factors which make things easier to understand. Survey conducted can be found in appendix. Results of data analyzed show that, whereas, some of the people claim smoking to be of stress reliever; quite a number of them adopted this habit from their social circle. Some think of it as a rebellious and cool activity whereas some are plain addicts. They also claimed, that work load or personal problems causes stress sometime leading to depression. Hence, a number of...

Words: 3128 - Pages: 13

Premium Essay

Personal Cloud

...it also allows people to make and share their own apps that run on ownCloud including text editors, task lists, and more. That means you can get a little more out of it then just file syncing if you want. At the core of it, ownCloud offers up super easy file syncing from your desktop to the cloud. Beyond that, you also get a music player built directly into ownCloud, a simple place to store contacts, a task manager, a syncing calendar, a bookmarking service, and a robust photo gallery. You'll be able to sync ownCloud with almost any desktop or mobile calendar and contacts app. That means if you want to ditch the likes of iCloud, ownCloud makes it easy to do. A recent update also added a simple install method so anyone can start using ownCloud right away. ------------------------------------------------- What information do you need to setup the account? You don't really need much to get started with ownCloud. Just gather up a web host that supports PHP5 and MySQL (or SQLite): This might sound a little jargon, but all it means is that you need to sign up for a service like Dreamhost (if you haven't already). If you already have a domain name like http://www.yourname.com through a web host (and you should), you can probably install ownCloud in a couple minutes. It sounds complicated, but you don't actually need to deal with things like PHP...

Words: 1213 - Pages: 5

Free Essay

Zain

...International business module code MOD001055 International Business: Element 010 – Assignment 3000 words (80%) Lecturer name INDRA BALAN Table of contents Introduction * Market share * Beginning specification Current situation for BLACKBERRY Market strategy Chronological of economy slowdown in the host country PESTEL analysis * POLITCAL * Economic factor * SOCIAL * TECNOLOGY * Legal * Environment CONCLUSION RECOMINDATION Introduction In this world there are different types of smart phone companies but we need to cover one Multinational company and that will BLACKBERRY limited. Basically black berry is founded in 1984 by Mike Lazaridisin in waterloo, Canada. Blackberry limited is also known as motion research limited, it is a Canadian wireless and telecommunication equipment company. The black berry first device 850 was introduced in 1999 with the name of two way pager. The name so the cell phone was chosen due to the resemblance of the keyboards button. And that also compose with the blue berry fruit. The first devices of original black berry are RIM857 – 850 are introduced with the Data TAC network operation. And after the new device name as Convergent smart phone was commonly known was introduced. With the specification of mobile telephone email services and the main production is text messaging. Market share In the year is 2003 they gained a huge market share in the industry of cell phone, by just concentrating...

Words: 3212 - Pages: 13

Premium Essay

Administrative Law

...Nick Montesano Buss 200 Administrative Law Essay The College Of New Jersey Dr. Laura Sanders 9/29/30 A National Dispute In the past decade there has been an increased controversial view of tobacco, alcohol, and marijuana. People have been divided on how to regulate these products in the market, causing much governmental controversy. There have been many groundbreaking and unprecedented court cases that have been shaping the public policy on which these substances stand on. These substances have an immediate and perilous effect on the health of all human beings. Tobacco is the leading cause of preventable death in the United States, alcohol causes impaired judgment and in turn causes people to do things that affect their health physically and emotionally, and marijuana has almost the same effect as alcohol. (New England Law) Health is the ultimate concern when studying these three substances, which would lead to the Family Smoking Prevention Act to survive the Hudson Test. The Granholm case would lead one to believe that states cannot discriminate against outsiders from sales, and the medical exceptions for marijuana are valid on the fact that it has a medical advantage to some citizens. I strongly believe that the federal government has a right to regulate certain aspects of these substances based upon the danger posed to the health of citizens. This paper will discuss certain court cases that shape my opinion for every substance...

Words: 3410 - Pages: 14

Premium Essay

Ant 101

...Progressive Party HIS204: American History since 1865 Progressive Party The Progressive Party was created as a result of President Theodore Roosevelt. The party was mostly focused on getting America's financial system back to normal and making essential modifications. The Progressive Party of 1912 had been called a political party in the United States and it was created by a split in the Republican Party. This was created by Theodore Roosevelt when he lost the Republican nomination to the in office President William Howard Taft and drew his delegates out of the conference (Mowry, 1946-1960). After that the party became as popular as the Bull Moose Party, later than the party’s symbol and later than Roosevelt’s show off that he was just "as strong as a bull moose". It has been said that the word progressivism became known in the late 19th century into the 20th century in reference to a more common reaction to the huge changes carried by industrialization. Political parties like the Progressive Party, formed at the beginning of the 20th century, as well as progressivism prepared vast steps beneath American leaders like Theodore Roosevelt, Woodrow Wilson, Franklin Delano Roosevelt and Lyndon Baines Johnson. The Progressive party was generally the outcome of presidential campaigns of 3 leaders that are Theodore Roosevelt, Robert La Follett, plusHenry Wallace. Some Progressive Party organizations struggled in this period and later in the...

Words: 1281 - Pages: 6

Free Essay

Hello

...Các nội dung cần ôn 1. OOP 2. Các đặc tính của OOP: tính trừu tượng, tính bao đóng, tính kế thừa, tính đa hình 3. networking 4. OOP la Object Oriented Programming 5. 3 đặc tính của nó 6. Abstraction (Tính trừu tượng) - Trừu tượng tức là chung chung, không cụ thể. Đặc tính này được thể hiện trong lớp trừu tượng (abstract class). Ví dụ: ta có lớp động vật (class dongvat) có các phương thức: mắt, màu lông,… và thuộc tính: ăn, uống, đi,… nhưng ta không thể biết được đó là động vật nào. Cũng như trong sinh học lớp 10 có nói đến ngành-lớp-bộ-họ-chi-loài trong đó có lớp thú, ta cũng đâu có biết đó là con gì, đúng không? Chỉ khi nào ta hiện thực lớp động vật này tức là cụ thể hóa đối tượng từ lớp này thì thông tin đối tượng lúc này mới chính xác. Ví dụ: ta có lớp chó (class dog) là con của lớp động vật (lớp cha). Một ví dụ khác, ta có 3 hình sau: hình chữ  nhật, hình thang, hình tam giác, cả 3 đều có chu vi, diện tích nhưng công thức tính của chúng hoàn toàn khác nhau. Như vậy trong OOP, ta sẽ có 1 lớp trừu tượng là hình học (class hinhhoc), trong class này có 2 phương tính tính chu vi và diện tích nhưng không ghi công thức tính (trừu tượng là đây). Ta sẽ hiện thức 3 hình trên (tức kế thừa từ lớp hình học) và viết các công thức tính tương ứng cho mỗi hình. - Tính trừu tượng còn bỏ qua những thứ không cần thiết của thông tin mà nó đang làm việc lên. Ví dụ con người có những thuộc tính: tên, tuổi, địa chỉ, chiều cao, màu tóc,… . Giả sử ta có 1 ứng dụng quản lý...

Words: 4910 - Pages: 20