Specifications
Listing Categories
The first script, index.php, lists all the categories in the database. It is shown in Listing 25.2.
LISTING 25.2 index.php—Script to Produce the Front Page of the Site
<?
include (‘book_sc_fns.php’);
// The shopping cart needs sessions, so start one
session_start();
do_html_header(“Welcome to Book-O-Rama”);
echo “<p>Please choose a category:</p>”;
// get categories out of database
$cat_array = get_categories();
// display as links to cat pages
display_categories($cat_array);
// if logged in as admin, show add, delete, edit cat links
if(session_is_registered(“admin_user”))
{
display_button(“admin.php”, “admin-menu”, “Admin Menu”);
}
do_html_footer();
?>
The script begins by including book_sc_fns.php, the file that includes all the function libraries
for this application.
After that, we must begin a session. This will be required for the shopping cart functionality to
work. Every page in the site will use the session.
There are some calls to HTML output functions such as
do_html_header() and
do_html_footer() (both contained in output_fns.php).
We also have some code that checks if the user is logged in as an administrator and gives her
some different navigation options if she is—we’ll return to this in the section on the adminis-
tration functions.
The most important part of this script is
// get categories out of database
$cat_array = get_categories();
// display as links to cat pages
display_categories($cat_array);
Building a Shopping Cart
C
HAPTER 25
25
B
UILDING A
SHOPPING CART
551
31 7842 CH25 3/6/01 3:38 PM Page 551










