13-post_variables/index.php

Go to the documentation of this file.
00001 <?php
00014 $message='';
00015 
00025 function get_post($var1)
00026 {
00027     if(isset($_POST[$var1]))
00028         return $_POST[$var1];
00029     else
00030         return "";
00031 }
00032 
00033 
00040 function show_login_page()
00041 {
00042     global $message;
00043     ?>
00044         <html>
00045             <head>
00046                 <title>Login page</title>
00047             </head>
00048             <body>
00049                 <?php echo $message; ?>
00050                 <form action="index.php" method="POST">
00051                     Username: <input type="text" name="username1" value="" /> <br/>
00052                     Password: <input type="password" name="password1" value="" /> <br/>
00053                     <input type="submit" value="Login" name="submit1" /><br/>
00054                 </form>
00055             </body>
00056         </html>
00057     <?php
00058 }
00059 
00060 
00070 function main()
00071 {
00072     global $message;
00073 
00074     if(get_post('submit1')=="")
00075     {
00076         //if page is being displayed for first time
00077         show_login_page();
00078     }
00079     else
00080     {
00081         $username1=get_post('username1');
00082         $password1=get_post('password1');
00083         if($username1==$password1 && $username1!="")
00084         {
00085             echo "Congratulations! Username and Password match.";
00086         }
00087         else
00088         {   //Note that $message must be declared as global in main()
00089             //for this to work.
00090             $message="Sorry! Username and password do not match.<br/>\n";
00091             show_login_page();
00092         }
00093     }
00094 }
00095 
00096 main();
00097 
00098 ?>

Generated on Fri Nov 4 14:16:54 2011 for PHP example documentation by  doxygen 1.4.7