Advertisement
Guest User

Untitled

a guest
May 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.46 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. if(isset($_SESSION['username']) && isset($_SESSION['password'])){
  6.     if($_REQUEST['username'] == "admin" && $_REQUEST['password'] == "secret") {
  7.         header("Location: adminview.php");
  8.     }  else {
  9.       header("Location: view.php");
  10.    }
  11. }
  12. ?>
  13. <html>
  14.  
  15. <head>
  16. <meta http-equiv="Content-Language" content="zh-tw" />
  17. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  18. <title>Nice Form</title>
  19. <link rel="stylesheet" href="css/formStyle.css" type="text/css" />
  20. </head>
  21.  
  22. <body>
  23. <br />
  24.  
  25. <?php
  26. if(isset($_SESSION['loginIncorrect'])){
  27. ?>
  28. <p align="center"><b>Incorrect username/password combination! Please try again.</b></p>
  29. <?php
  30. unset($_SESSION['loginIncorrect']);
  31. }
  32. ?>
  33.  
  34. <form method="POST" action="login.php">
  35.     <div align="center">
  36.         <table border="0" width="300" class="border">
  37.             <tbody>
  38.             <tr>
  39.                 <td colspan="2" class="heading" height="26" align="center">Login
  40.                 Information</td>
  41.             </tr>
  42.             <tr>
  43.                 <td width="82" class="content">Username:</td>
  44.                 <td width="202">
  45.                 <input type="text" name="username" size="20" class="content" /></td>
  46.             </tr>
  47.             <tr>
  48.                 <td width="82" class="content">Password:</td>
  49.                 <td width="202">
  50.                 <input type="password" name="password" size="20" class="content" /></td>
  51.             </tr>
  52.             <tr>
  53.                 <td width="82">&nbsp;</td>
  54.                 <td width="202">
  55.                 <input type="submit" value="Submit" name="submit" class="content" /><input type="reset" value="Reset" class="content" /></td>
  56.             </tr>
  57.         </tbody>
  58.         </table>
  59.     </div>
  60. </form>
  61. <a href="register.php">Register</a>
  62. </body>
  63.  
  64. </html>
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. //login.php starts here
  72.  
  73. <?php
  74. session_start();
  75.         if($_REQUEST['username'] == "admin" && $_REQUEST['password'] == "secret") {
  76.             $_SESSION['username'] = 'admin';
  77.             $_SESSION['password'] = 'secret';
  78.             header("Location: adminview.php");
  79.         }
  80.         include('connectMySQL.php');
  81.         $db = new MySQLDatabase();
  82.         $db->connect("test", "test", "messageboard");
  83.         $query = "select username,password from users";
  84.         $result = mysql_query($query);
  85.             if($result) {
  86.         while($row = mysql_fetch_array($result)){
  87.             if($_REQUEST['username'] == $row['username'] && $_REQUEST['password']==$row['password']) {
  88.             $_SESSION['username'] = $row['username'];
  89.             $_SESSION['password'] = $row['password'];
  90.             header("Location: view.php");
  91.             }
  92.         }
  93.         }
  94.    
  95.     else {
  96.         die(mysql_error());
  97.     }
  98.             $_SESSION['loginIncorrect'] = true;
  99.             header("Location: form.php");
  100.        
  101.         $db->disconnect();
  102.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement