bài giảng lập trình web php - chương 05 project - trường đh sp tp. hcm

25 343 0
bài giảng lập trình web php - chương 05  project -  trường đh sp tp. hcm

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Đ i H c Sư Ph m Tp H Chí Minh LẬP TRÌNH WEB PHP Chương 05: PROJECT Nội dung • • • • • • Thi t k giao di n, b c c Hi n th ti ng Vi t trang Web Xây d ng hàm k t n i CSDL dùng chung Login Upload/Download Trang s n ph m: xem, đ t mua (viewer) thêm, c p nh t, xóa (admin) • Phân trang • Xu t b n website Layout • Tùy ch n Ít nh t s có: Banner (hình nh cơng ty, t ch c, cá nhân, …) Menu/Link (Các liên k t trang) Main (N i dung trang web) Footer (B n quy n – Đ a ch ) Tiếng việt trang Web • Th meta file HTML/PHP • DreamWeaver: Ctrl + J ch n Encoding: UTF8 • CSDL: mysqli_query("SET NAMES utf8;"); Hàm kết nối CSDL dùng chung //File: connect.php define(“HOST”, “localhost”); define("USR", "root"); define("PWD", ""); define("DBNAME","baitap"); $conn = mysqli_connect(HOST,USR,PWD) or die(“Khơng k t n i đư c!”); mysqli_select_db(DBNAME); Login Page • Xây d ng file login.php dùng đ đăng nh p Process Login Page require(“connect.php”); $sql = "SELECT count(*) FROM user WHERE username='{$_POST['user']}' AND password ='".md5($_POST['pass'])."'"; $result = mysqli_query($sql); if(mysqli_num_rows($result)){ echo 'Đăng nh p thành công'; $_SESSION[‘user’] = $_POST['user']; } else{ //echo 'Đăng nh p l i'; header(‘location:login.php’); } Upload • Xây d ng file upload.php đ upload file Xử lý upload • Khai báo nơi lưu tr : $target_path = "data/"; $target_path = $target_path.basename( $_FILES['uploadedfile']['name']); • Upload file lên server: move_uploaded_file($_FILES['uploadedfile'][' tmp_name'], $target_path) • Lưu s thông tin vào CSDL $sql = "INSERT INTO file (chude, tenfile, loaifile) VALUES ('{$_POST['chude']}', '{$target_path}','$loaifile')"; Download file • Cách 1: Tr c ti p qua th • Cách 2: Xây d ng trang download function DownloadFile($file) { // $file = include path if(file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' filesize($file)); ob_clean(); flush(); readfile($file); exit; } } • G i: DownloadFile($_GET[filename]); 10 WEB SẢN PHẨM PRESENTED BY HIEN, LUONG TRAN HY HIENLTH@HCMUP.EDU.VN u cầu • Ngư i dùng (viewer): Xem thơng tin t ng ch ng lo i s n ph m Xem chi ti t 01 s n ph m Mua hàng • Qu n tr (admin) T o 01 (lo i) s n ph m m i Ch nh s a/Xóa thơng tin 01 s n ph m G i hàng 12 Phân trang • S d ng bi n truy n d ng GET, m c đ nh trang đ u tiên n u bi n chưa đ t tr if (isset($_GET[page])) $page = $_GET[page]; else $page = 1; • S lư ng s n ph m trình bày 01 trang: $pp = ?? • Truy v n CSDL ý: LIMIT $start, $pp Trong $start = ($page – 1) * $pp; 13 XUẤT BẢN SITE PRESENTED BY HIEN, LUONG TRAN HY HIENLTH@MATH.HCMUP.EDU.VN Xuất website • http://vn2k.net/signup.php • Đi n thơng tin theo m u Tên đăng nh p (username) M t kh u (password) Email Lo i site ngôn ng Đi n mã xác nh n 15 Xuất website (tt) • Lưu gi thơng tin v website 16 Upload thơng tin lên host • B ng FTP (dùng Total Commander) • Tr c ti p: Vào Cpanel → File Manager File lưu tr thư m c 17 Upload thơng tin lên host • Ch n Upload B m đ Upload 18 Upload thông tin lên host dùng Total Commander • B m nút FTP 19 Upload thơng tin lên host dùng Total Commander • Session: Đi n vào tên tùy ý • Hostname, username, password n thông tin c a b n 20 Upload thông tin lên host dùng Total Commander Ch n connect 21 Upload thông tin lên host dùng Total Commander • Th c hi n ch n file copy (F5) 22 Tạo sử dụng CSDL • Ch n MySQL Database c a s CPanel Import Database C a s PHPMyAdmin 23 Bộ đếm đọc file 24 Câu hỏi thảo luận 25 ... header(''Content-Description: File Transfer''); header(''Content-Type: application/octet-stream''); header(''Content-Disposition: attachment; filename=''.basename($file)); header(''Content-Transfer-Encoding:... trang) Main (N i dung trang web) Footer (B n quy n – Đ a ch ) Tiếng việt trang Web • Th meta file HTML /PHP • DreamWeaver: Ctrl... header(''Content-Transfer-Encoding: binary''); header(''Expires: 0''); header(''Cache-Control: must-revalidate, post-check=0, pre-check=0''); header(''Pragma: public''); header(''Content-Length: '' filesize($file)); ob_clean(); flush();

Ngày đăng: 06/07/2014, 04:50

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan