PHP and MySQL Web Development - P91

PHP and MySQL Web Development - P91: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | 422 Chapter 20 Using Session Control in PHP The example consists of three simple first provides a login form and authentication for members of our Web second displays information only to members who have logged in successfully. The third logs out a member. To understand how this works look at Figure is the initial page displayed by . Figure Because the user has not yet logged in show her a login page. This page gives the user a place to log in. If she attempts to access the Members section without logging in first she will get the message shown in Figure . Figure Users who haven t logged in can t see the site content they will be shown this message instead. Implementing Authentication with Session Control 423 However if the user logs in first with username testuser and password test123 as set up in Chapter 14 and then attempts to see the Members page she will get the output shown in Figure . Figure After the user has logged in she can access the Members areas. Let s look at the code for this application. Most of the code is in script can be seen in Listing will go through it bit by bit. Listing The Main Part of the Authentication Application php session_start if isset HTTP_POST_VARS userid isset HTTP_POST_VARS password if the user has just tried to log in userid HTTP_POST_VARS userid password HTTP_POST_VARS password db_conn mysql_connect localhost webauth webauth mysql_select_db auth db_conn query select from auth . where name userid . and pass password password result mysql_query query db_conn if mysql_num_rows result 0 if they are in the database register the user id HTTP_SESSION_VARS valid_user userid 424 Chapter 20 Using Session Control in PHP Listing Continued html body h1 Home page h1 if isset HTTP_SESSION_VARS valid_user echo You are logged in as . HTTP_SESSION_VARS valid_user . br echo a href

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.