Đặt những dòng này vào một file văn bản được gọi là danh sách , và đặt file này trong thư mục gốc tài liệu máy chủ web của bạn. Tiếp theo, bạn sẽ tạo ra kịch bản chính nó, tạo thành hy vọng sẽ được gọi là danh sách | Put these lines into a text file called listing and place this file in your Web server document root. Next you ll create the script itself which the form expects to be called listing . Listing User Login Script 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 php check for required fields from the form if _POST username _POST password header Location exit connect to server and select database conn mysql_connect localhost joeuser somepass or die mysql_error mysql_select_db testDB conn or die mysql_error create and issue the query sql select f_name l_name from auth_users where username _POST username AND password password _POST password result mysql_query sql conn or die mysql_error get the number of rows in the result set should be 1 if a match if mysql_num_rows result 1 if authorized get the values of f_name l_name f_name mysql_result result 0 f_name l_name mysql_result result 0 l_name set authorization cookie setcookie auth 1 0 0 prepare message for printing and user menu msg P f_name l_name is authorized p msg . P Authorized Users Menu msg . ul li a href secret page a u else redirect back to login form if not authorized header Location exit 39 40 HTML 41 HEAD 42 TITLE Listing User Login TITLE 43 HEAD 44 BODY 45 print msg 46 BODY 47 HTML Put these lines into a text file called and place this file in your Web server document root. In a moment you ll try it out but first let s examine what the script is doing. Line 3 checks for the two required fields from the form. They are the only two fields in the form username and password . If either one of these fields is not present the script will redirect the user back to the login form. If the two fields are present the script moves along to lines 9-11 which connect to the database server and select the database to use in preparation for issuing the SQL query to