Page 331 - Beginning PHP 5.3
P. 331

Chapter 10: Preserving State With Query Strings
                             function displayPage() {
                               displayPageHeader();
                             ? >

                                  < p > Welcome,  < strong > < ?php echo $_SESSION[“username”] ? > < /strong > ! You are

                             currently logged in. < /p >

                                  < p > < a href=”login.php?action=logout” > Logout < /a > < /p >

                                < /body >
                               < /html >
                               < ?php
                             }
                             function displayLoginForm( $message=”” ) {
                               displayPageHeader();
                             ? >
                                  < ?php if ( $message ) echo ‘ < p class=”error” > ’ . $message . ‘ < /p > ’ ? >
                                  < form action=”login.php” method=”post” >
                                    < div style=”width: 30em;” >
                                      < label for=”username” > Username < /label >
                                      < input type=”text” name=”username” id=”username” value=”” / >
                                      < label for=”password” > Password < /label >
                                      < input type=”password” name=”password” id=”password” value=”” / >
                                      < div style=”clear: both;” >
                                        < input type=”submit” name=”login” value=”Login” / >
                                      < /div >
                                    < /div >
                                  < /form >
                                < /body >
                               < /html >
                               < ?php
                             }
                             function displayPageHeader() {
                             ? >
                               < !DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
                               “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd” >
                               < html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en” >
                                < head >
                                  < title > A login/logout system < /title >
                                  < link rel=”stylesheet” type=”text/css” href=”common.css” / >
                                  < style type=”text/css” >
                                   .error { background: #d33; color: white; padding: 0.2em; }
                                  < /style >
                                < /head >
                                < body >
                                  < h1 > A login/logout system < /h1 >
                               < ?php
                             }

                             ? >








                                                                                                         293





                                                                                                      9/21/09   9:05:16 AM
          c10.indd   293
          c10.indd   293                                                                              9/21/09   9:05:16 AM
   326   327   328   329   330   331   332   333   334   335   336