Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
PHP and MySQL Web Development - P158: 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. | Solution Overview 757 This is nothing new.The safeString function is in the utilityfunctions.php file. It simply removes any non-alphanumeric characters from the input string via a regular expression replacement. Because we have covered this before we have not included it here in the text. The main reason that we need to validate input in this application is that we use the customer s input to create file names in the cache.We could run into serious problems if we allow customers to include . or in their input. Next we set up the customer s shopping cart if she does not already have one if isset HTTP_SESSION_VARS cart session_register cart HTTP_SESSION_VARS cart array We have a few last things to do before we can display the information in the top information bar on the page see Figure 31.1 for a reminder of what this looks like . A glimpse of the shopping cart is shown in the top bar of every page. It is therefore important that the cart variable is up to date before this is displayed. tasks that need to be done before the top bar is shown if action addtocart addToCart HTTP_SESSION_VARS cart ASIN mode if action deletefromcart deleteFromCart HTTP_SESSION_VARS cart ASIN if action emptycart HTTP_SESSION_VARS cart array Here we are adding or deleting items from the cart as necessary before displaying the cart. We will come back to these functions when we discuss the shopping cart and checking out. If you want to look at them now they are in the file cartfunctions.php. We are leaving them aside for a minute because we need to understand the interface to Amazon first. Next we include the file topbar.php. This file simply contains HTML and a style sheet and a single function call to the ShowSmallCart function from cartfunctions.php .This displays the small shopping cart summary you can see in the top right-hand corner of the figures. We will come back to this when we discuss the cart functions. Finally we come to the main event-handling loop. A summary of the possible .