Guest User

Untitled

a guest
Jan 24th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2.     include("header.php");
  3.    
  4.      if (isset($_POST['submit'])) {
  5.      
  6.         //load contents of form into variables
  7.         $pw = $_POST['pass'];
  8.         $name = $_POST['username'];
  9.         stripslashes($pw);
  10.         stripslashes($name);
  11.        
  12.         //register session
  13.         session_register();
  14.        
  15.         //pass in username and password into session
  16.         $_SESSION['uName'] = $name;
  17.         $_SESSION['uPw'] = $pw;
  18.        
  19.         //checks if username exists in database.
  20.         $check1 = mysql_query("SELECT password FROM users WHERE username = '$name'");
  21.  
  22.        
  23.         //if no user exists it prompts user to login.
  24.          if(mysql_num_rows($check1) == 0){
  25.             die('<div class="alert">Click <a href="register.php">here</a> to register</a></div>');
  26.          }
  27.            
  28.         //checks if the password for the user is correct.
  29.          $check = mysql_query("SELECT * FROM users WHERE username = '$name' and password = '$pw'")or die(mysql_error());
  30.          $count = mysql_num_rows($check);
  31.          
  32.          
  33.          //if so it redirects to mainpage
  34.          if($count == 1 ){
  35.               header("Location: mainpage.php");
  36.          }
  37.          
  38.          //prompts user that their password was wrong.
  39.          else{   
  40.             die ('<div class="alert">incorect password</div>');
  41.          }
  42.          }
  43.          
  44.          //redirects if register button is selected
  45.         if (isset($_POST['register'])) {
  46.        
  47.                       header("Location: register.php");
  48.         }
  49.        
  50.         //if submit not yet selected process login form.
  51.      else
  52.      {
  53.      ?>
  54.  
  55.         <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
  56.         <table width="219" border="0"  class="login"> <td></td>
  57.              <tr>
  58.                 <td width="68" ><strong>Username</strong></td><td width="144">
  59.                 <input type="text" name="username" maxlength="40">
  60.              </td></tr>
  61.              <tr>
  62.              <td><p><strong>Password</strong>:</p></td><td>
  63.              <input type="password" name="pass" maxlength="50">
  64.              </td></tr>
  65.              <tr>
  66.              <td colspan="2" align="center">
  67.              <input type="submit" name="submit" value="Login">
  68.              <input type="submit" name="register" value="Register">
  69.              </td></tr>  
  70.              </table>
  71.              </form>
  72.              <?php
  73.      }
  74.  ?>
  75.  </body>
  76.  </html>
Add Comment
Please, Sign In to add comment