tailieunhanh - MySQL /PHP Database Applications Second Edition phần 4

Bạn có thể muốn cung cấp cho các tập tin của bạn bao gồm một phần mở rộng riêng biệt. Inc là một sự lựa chọn điển hình. Một lợi thế của phương pháp này là các tập tin có thể được chạy trực tiếp từ trình duyệt, kể từ khi máy chủ web (thường) không được cấu hình để nhận ra inc như một tập tin PHP. | 198 Part 11 Working with PHP You might want to give your include files a distinct extension .inc is a typical choice. One advantage of this approach is that the files can t be run directly from a browser since the Web server is usually not configured to recognize .inc as a PHP file. You can also store your include files outside of your Web server s document path for even more security since some servers respond to unknown extensions by printing out the file oops there s your source code. Suppose you have two files and . Notice that we have made an important change in The TITLE tags now contain a PHP variable. HTML HEAD TITLE php echo page_title TITLE HEAD body bgcolor FFFFF link 8E0402 vlink 20297C You may have seen code like the above written like this TITLE page_title TITLE These short tags involve less typing it s true but whether or not they work is dependent on how PHP is configured. They re likely to be disabled by default now or in future releases so you should avoid using them. Now for the file php page_title Welcome to My Site include echo Here are the contents of my PHP pages. Anything could be here. Notice that the variable page_title is visible to the file pulled in by the include statement. When is served the resulting HTML page will be as follows Chapter 7 Writing Organized and Readable Code 199 HTML HEAD TITLE Welcome to My Site TITLE HEAD body bgcolor FFFFF link 8E0402 vlink 20297C Keep any code whether HMTL or PHP that is needed in a variety of pages within include files. Header and footer information database-connection code and pages that contain functions or classes are all good candidates for includes. At the start of an included file PHP reverts to HTML mode. If code within the file needs to be parsed as PHP you must first indicate that with the php marker. PHP contain a variety of commands that do slightly different things with included files. We look at these commands in the .

TỪ KHÓA LIÊN QUAN