Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
CHAPTER 6 ■ PASSWORD PROTECTION SENSITIVE ACTIONS AND AREAS Modifying the App to Handle the User Logout The last step you need to take before users can successfully log out is to add another array element to the $actions array in process.inc.php. Insert the following bold code into process.inc.php to complete the logout process: $val ) { define($name, $val); } /* * Create a lookup array for form actions */ $actions = array( 'event_edit' = array( 'object' = 'Calendar', 'method' = 'processForm', 'header' = 'Location: //' ), 'user_login' = array( 'object' = 'Admin', 'method' = 'processLoginForm', 'header' = 'Location: //' ),. | CHAPTER 6 PASSWORD PROTECTION SENSITIVE ACTIONS AND AREAS Modifying the App to Handle the User Logout The last step you need to take before users can successfully log out is to add another array element to the actions array in process.inc.php. Insert the following bold code into process.inc.php to complete the logout process php Enable sessions session_start Include necessary files include_once . . . sys config db-cred.inc.php Define constants for config info foreach C as name val define name val Create a lookup array for form actions actions array event_edit array object Calendar method processForm header Location . . user_login array object Admin method processLoginForm header Location . . user_logout array object Admin method processLogout header Location . . Make sure the anti-CSRF token was passed and that the requested action exists in the lookup array 221 CHAPTER 6 PASSWORD PROTECTION SENSITIVE ACTIONS AND AREAS if _POST token _SESSION token isset actions _POsT action use_array actions _POST action obj new use_array object dbo if TRUE msg obj- use_array method header use_array header exit else If an error occured output it and end execution die msg else Redirect to the main index if the token action is invalid header Location . . exit function autoload class_name filename . . . sys class class. . strtolower class_name . .inc.php if file_exists filename include_once filename Save this file then navigate to http localhost and click the Log Out button at the bottom of the calendar. Clicking this button causes the message below the calendar to now read Logged Out see Figure 6-8 . 222 CHAPTER 6 PASSWORD PROTECTION SENSITIVE ACTIONS AND AREAS Figure 6-8. Clicking the Log Out button removes the user data from the session Note Now that you know the login is working remove the Logged In Logged Out message logic and the paragraph tags that enclose it from index.php. Displaying Admin Tools Only to Administrators Your users can log in and log out the last steps you .