9. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
C?u h━nh ph?n quy?n WRITE cho th? m?c upload
PHP Warning:
move_uploaded_file(upload/14.jpg)
[function.move-uploaded-file]:
failed to open stream: Permission
denied in .
10. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
N?i dung
? Upload File
? G?i Email
? Cookies
? Sessions
11. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
G?i Email
? C? ch? g?i Email
? G?i mail s? d?ng Outlook
? G?i mail s? d?ng Web Mail
C PHP mail() C Non Authentication
C PHP PEAR package C SMTP Authentication
12. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
G?i Email
? C? ch? g?i Email
? G?i mail s? d?ng Outlook
? G?i mail s? d?ng Web Mail
C PHP mail() C Non Authentication
C PHP PEAR package C SMTP Authentication
13. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
C? ch? g?i Email Mail server
Mail Client
mail(to,subject,message´)
Web Server
Internet
or Intranet
Internet
or Intranet
14. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
C? ch? g?i Email
15. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
V┴ d? C?u h━nh G?i Email s? d?ng GMAIL
16. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
G?i Email
? C? ch? g?i Email
? G?i mail s? d?ng Outlook
? G?i mail s? d?ng Web Mail
C PHP mail() C Non Authentication
C PHP PEAR package C SMTP Authentication
18. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
G?i Email
? C? ch? g?i Email
? G?i mail s? d?ng Outlook
? G?i mail s? d?ng Web Mail
C PHP mail() C Non Authentication
C PHP PEAR package C SMTP Authentication
19. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
G?i mail s? d?ng PHP mail() - Non Authentication
? mail(to,subject,message,headers,parameters)
Key Specifies
TO ??a ch━ email ng??i nh?n
SUBJECT Ti┷u ?? Email (KH?NG ???c ch?a k? t? xu?ng d┛ng)
MESSAGE N?i dung Email
HEADERS
Th?ng tin th┷m (vd: FROM, BCC, CC,´) C│c th?ng tin n┐y n┷n ph?n c│ch nhau
b?ng k? t? xu?ng d┛ng (rn)
PARAMETERS Tham s? c?u h━nh cho ?ng d?ng g?i mail
20. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
C?u h━nh m?c ??nh c?a PHP mail() C Non Authentication
? C?u h━nh m?c ??nh ???c ??nh ngh?a trong file php.ini
Default ? ngh?a
SMTP localhost DSN ho?c IP Address c?a SMTP Server
smtp_port 25 Port c?a SMTP
sendmail_from NULL ??a ch? ng??i g?i
sendmail_path NULL ???ng d?n ??n ?ng d?ng g?i mail
(UNIX)
22. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
G?i Email
? C? ch? g?i Email
? G?i mail s? d?ng Outlook
? G?i mail s? d?ng Web Mail
C PHP mail() C Non Authentication
C PHP PEAR package C SMTP Authentication
23. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
G?i mail s? d?ng PHP PEAR package C SMTP Authentication
1. S? d?ng PEAR package Mail.php
C require_once(?Mail.php?);
2. Kh?i t?o th? hi?n ?? g?i mail s? d?ng Mail::factory()
C $smtp = Mail::factory(?smtp?, $params);
? $params[^host ̄] = ^hostname ̄;
? $params[^auth ̄] = true;
? $params[^username ̄] = ^smtp_username ̄;
? $params[^password ̄] = ^smtp_password ̄;
3. G?i mail s? d?ng h┐m send()
C $mail = $smtp->send($to, $headers, $message)
? $headers['From'] = 'from@example.com';
? $headers['To'] = $to;
? $headers['Subject'] = 'Test message';
? $headers['Cc'] = 'cc@example.com';
? $headers['Reply-To'] = 'from@example.com';
4. Ki?m tra l?i g?i mail
C if (PEAR::isError($mail))
echo($mail->getMessage());
35. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
L┐m th? n┐o ?? ng?n kh?ng cho ng??i d┫ng truy c?p
v┐o c│c trang web n?u ch?a ??ng nh?p?
1. T?o trang login.htm y┷u c?u ng??i d┫ng ??ng nh?p.
2. T?o trang validateuser.php l┐ trang x? l┴ th?ng tin ??ng nh?p t? trang
login
C K?t n?i v?i CSDL, ki?m tra xem th?ng tin ??ng nh?p c┏ ?┣ng hay kh?ng.
C N?u kh?ng ?┣ng th━ cho redirect ??n trang login.htm.
C C┛n n?u ??NG th━ d┫ng m?t bi?n Session ?? l?u tr?ng th│i login th┐nh
c?ng l?i.
? V┴ d? $_SESSION["IsLogin^] = 1.
? L?u ? l┐ ph?i ??t gi│ tr? m?c ??nh cho bi?n n┐y l┐ 0 khi kh?i t?o m?t
Session.
3. T?o trang logout.php l┐ trang x? l? khi ng??i d┫ng logout
? Reset tr?ng th│i login l┐ ch?a ??ng nh?p
36. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
L┐m th? n┐o ?? ng?n kh?ng cho ng??i d┫ng truy c?p
v┐o c│c trang web n?u ch?a ??ng nh?p?
4. Trong t?t c? c│c trang mu?n b?o m?t, ph?i th┷m ?o?n m?
sau ?? ki?m tra ng??i d┫ng ?? login hay ch?a, n?u ch?a
th━ redirect l?i trang login.htm
<?php
session_start();
if ($_SESSION["IsLogin^] != 1)
header(^Location: login.htm^);
?>
37. L?p tr━nh v┐ Thi?t k? Web 1 C B┐i 9 : PHP n?ng cao
? 2007 Khoa CNTT - ?HKHTN
So s│nh
Clients
Web servers
Database/File
Session (client1)
Session (client2)cookies
cookies
Th?ng tin chia s? V? tr┴
l?u tr?
Th?i gian
t?n t?i
S? client S? trang web
s? d?ng
Database/File Server D┐i N N
Session Server Ng?n 1 N
Cookies Client D┐i 1 N
Internet
or Intranet