Ví dụ, giả sử các bản ghi ứng dụng của bạn trong một khách hàng và sau đó chuyển biến ủy quyền, chẳng hạn như đăng nhập = có, trong một biến ẩn trong hình thức. Khi bạn kiểm tra xem người dùng có thẩm quyền để xem một trang Web, bạn cần phải sử dụng mã như sau | Chapter 3 User Authentication with HTTP 71 Writing the WebPage class The WebPage class is used frequently throughout this book whenever a Web page needs to be displayed. The WebPage class has a single function to display a Web page. The class expects the name of a file that contains the code that defines the Web page to be passed. If the Web page displays any information stored in PHP variables an array of the data to be displayed in the Web page must also be passed. The properties The WebPage properties store the information needed to display the Web page. private filename private data filename is the name of the file that contains the code that defines the Web page HTML code and perhaps some PHP code for parts of the Web page that use PHP variables. The file that defines the Web page for the authentication application presented in this chapter is named . The same file is used for the procedural code and is shown in Listing 3-2. data is an array that contains the PHP variables for the Web page. If information contained in PHP variables is displayed on the page the PHP variables must be passed in an array. If no PHP variables are displayed data can be NULL. The code Listing 3-6 contains the complete code for the WebPage class. The constructor and the single displayPage method are discussed in detail after the code listing. Notice the line numbers at the ends of some of the lines of code. The discussion following the listing refers to the line numbers. Listing 3-6 The Code for the WebPage Class php Class WebPage Desc Class that stores the information needed to display a Web page. class WebPage private filename private data function __construct filename data NULL 11 Continued 12 Part II Building a User Authentication Application Listing 3-6 Continued if is_string filename 13 this- filename filename else throw new Exception Filename must be a string if data NULL or is_array data 21 this- data data else 25 throw new Exception Data must be passed in an array