Danh mục

Giải pháp thiết kế web động với PHP - p 12

Số trang: 10      Loại file: pdf      Dung lượng: 608.33 KB      Lượt xem: 12      Lượt tải: 0    
Thư Viện Số

Hỗ trợ phí lưu trữ khi tải xuống: 5,000 VND Tải xuống file đầy đủ (10 trang) 0

Báo xấu

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

LIGHTENING YOUR WORKLOAD WITH INCLUDESFigure 4-12. The ugly gap is removed by creating a style rule directly related to the image size.If the caption still protrudes, make sure there s no gap between the closing PHP tag and px in the block. CSS does not permit whitespace between the value and unit of measurement.8.The code in random_image.php and the code you have just inserted prevent errors if the selected image can t be found, but the code that displays the image is devoid of similar checks. Temporarily change the name of one of the images, either in random_image.php or...
Nội dung trích xuất từ tài liệu:
Giải pháp thiết kế web động với PHP - p 12 LIGHTENING YOUR WORKLOAD WITH INCLUDESFigure 4-12. The ugly gap is removed by creating a style rule directly related to the image size.If the caption still protrudes, make sure there s no gap between the closing PHP tag and px in the block. CSS does not permit whitespace between the value and unit of measurement. 8. The code in random_image.php and the code you have just inserted prevent errors if the selected image can t be found, but the code that displays the image is devoid of similar checks. Temporarily change the name of one of the images, either in random_image.php or in the images folder. Reload index.php several times. Eventually, you should see an error message like that in Figure 4-13. It looks very unprofessional.Figure 4-13. An error in an include file can destroy the look of your page. 9. The conditional statement at the foot of random_image.php sets $imageSize only if the selected image both exists and is readable, so if $imageSize has been set, you know it s all systems go. Add the opening and closing blocks of a conditional statement around the that displays the image in index.php like this: 91 CHAPTER 4 LIGHTENING YOUR WORKLOAD WITH INCLUDES To check whether a class has been defined, use class_exists() in the same way, passing a string containing the class name as the argument: if (class_exists(MyClass)) { // use MyClass } Assuming you want to use the function or class, a more practical approach is to use a conditional statement to include the definition file if the function or class hasn t already been defined. For example, if the definition for doubleIt() is in a file called utilities.inc.php: if (!function_exists(doubleIt)) { require_once(includes/utilities.inc.php); }Temporarily turning on error messages Error messages are there to help the developer. Unfortunately, displaying them in a live website exposes information that could be useful to an attacker, which is why it s now common for hosting companies to turn off the display of error messages. Depending on the nature of the error, all you might see when accessing the page is a blank screen. This isn t very helpful when you need to find out what s wrong with a page that worked perfectly in your local testing environment. Fortunately, it s easy to turn on the display of error messages temporarily for an individual page with ini_set(), which can be used to override some directives in php.ini, the server s PHP configuration file. Add the following code at the top of the page that s causing problems: Upload the file to your remote server, and reload the page in your browser. You should then be able to read the error message onscreen. Fix the problem, and test the page again. If the page displays correctly, remove the extra line of code. If you still see a blank screen, it means there s a syntax error in your PHP code. Using ini_set() has no effect if there s a parse error. The most common cause of errors is forgetting to upload the include file to your remote server. Even if you have uploaded all the files, you might get an error message telling you that you don t have permission to access an include file. This is likely to happen in the following circumstances: • The server is running in safe mode: If your hosting company is running PHP in a highly restricted way, you will see a warning that a safe mode restriction is in effect. Run phpinfo(), and check the value of safe_mode_include_dir in the Core section. All your include files must be stored in this location. Adjust your site structure accordingly. Safe mode is scheduled to be removed from the next major version of PHP, so this problem is less common. 93 CHAPTER 4 • The open_basedir directive has been set: The open_basedir directive restricts your ability to include or open files. This should affect you only when the include file is outside your web server s document root. The warning message produced by PHP lists the allowed path(s). Move your include file to a permitted location, and adjust the path in the include command accordingly.Dealing with missing include files Assuming your include files ...

Tài liệu được xem nhiều: