Creating the Public Template


Before I get into the heart of the public side, I'll need to create the requisite HTML header and footer files. I'll whip through these quickly, since the techniques involved should be familiar territory by this point in the book.

To make header.html

1.

Create a new PHP document in your text editor (Script 14.3).

 <?php # Script 14.3 - header.html 

Script 14.3. The header file creates the initial HTML and begins the PHP session.


2.

Begin the session.

 session_start(); ?> 

It's very important that the user's session is maintained across every page, so I'll start the session in the header file. If the session was lost on a single page, then a new session would begin on subsequent pages, and the user's historythe contents of the shopping cartwould be gone.

3.

Create the HTML head.

 <!DOCTYPE html PUBLIC "-//W3C//DTD  XHTML 1.0 Transitional//EN "http://www.w3.org/TR/xhtml1/DTD/  xhtml1-transitional.dtd> <html xmlns="http://www.w3.org/1999/  xhtml xml:lang="en" lang="en"> <head>   <meta http-equiv="content-type"    content="text/html; charset=    iso-8859-1 />   <title><?php echo $page_title;    ?></title> </head> <body> 

As with all the other versions of this script, the page's title will be set as a PHP variable and printed out within the title tags.

4.

Create the top row of the table.

 <table cellspacing="0"  cellpadding="0 border="0"  align="center width="600">   <tr>     <td align="center" colspan="3">      <img src="/books/3/386/1/html/2/images/title.jpg      width="600 height="61"      border="0 alt="title"      /></td>   </tr>   <tr>     <td><a href="index.php">      <img src="/books/3/386/1/html/2/images/home.jpg      width="200 height="39"      border="0 alt="home page"      /></a></td>     <td><a href="browse_prints.php">     <img src="/books/3/386/1/html/2/images/prints.jpg"      width="200 height="39"      border="0 alt="view the      prints /></a></td>     <td><a href="view_cart.php">      <img src="/books/3/386/1/html/2/images/cart.jpg      width="200 height="39"      border="0 alt="view your      cart /></a></td>   </tr> 

This layout will use images to create the links for the public pages (Figure 14.19).

Figure 14.19. The banner created by the header file.


5.

Start the middle row.

 <tr>   <td align="left" colspan="3"    bgcolor="#ffffcc><br /> 

All of each individual page's content will go in the middle row, so the header file begins this row and the footer file will close it.

6.

Save the file as header.html and upload to your Web server (create an includes directory in which to store it).

To make footer.html

1.

Create a new HTML document in your text editor (Script 14.4).

 <!-- Script 14.4 - footer.html --> 

Script 14.4. The footer file closes the HTML, creating a copyright message in the process.


2.

Complete the middle row, create the bottom row, and complete the HTML (Figure 14.20).

      <br /></td>   </tr>   <tr>      <td align="center" colspan="3"       bgcolor="#669966><font color=       "#ffffff>&copy; Copyright...       </font></td>   </tr> </table> </body> </html> 

Figure 14.20. The copyright row created by the footer file.


3.

Save the file as footer.html and upload to your Web server (also in the includes directory).

To make index.php

1.

Create a new PHP document in your text editor (Script 14.5).

 <?php # Script 14.5 - index.php $page_title = 'Make an Impression!'; include ('./includes/header.html'); ?> 

Script 14.5. The script for the site's home page.


2.

Create the page's content.

 <p>Welcome to our site....please  use the links above...blah, blah,  blah.</p> <p>Welcome to our site....please  use the links above...blah, blah,  blah.</p> 

Obviously a real e-commerce site would have some actual content on the main page. You could put lists of recently added items here (if you added a date_entered column to the prints table), highlight specials, or do whatever.

3.

Complete the HTML page.

 <?php include ('./includes/footer.html'); ?> 

4.

Save the file as index.php, upload to your Web server, and test in your Web browser (Figure 14.21).

Figure 14.21. The public home page for the e-commerce site.


Tips

  • The images used in this example are available for download through the book's companion Web site: www.DMCInsights.com/phpmysql2.

    The images are available on the Extras page and as part of the downloadable files found on the Scripts page.

  • Since sessions are key to the functionality of this application, review the information presented in Chapter 9 or in the PHP manual to understand all of the session considerations.




    PHP and MySQL for Dynamic Web Sites. Visual QuickPro Guide
    PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    ISBN: 0321336577
    EAN: 2147483647
    Year: 2005
    Pages: 166
    Authors: Larry Ullman

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net