Advertisement
Guest User

Untitled

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