Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2. //First check to see if you are logged in
  3. if ($_SESSION['logged'] == 1) {
  4.     echo "<h2>Info</h2><p>You are already logged in!</p>";
  5. } else {
  6.  
  7. //Form Submittion
  8.     if ($_GET['action'] == "submit") {
  9.    
  10.     //Form Inputs
  11.         $Password = $_POST['Password'];
  12.         $Username = $_POST['Username'];
  13.  
  14.     //Query the database and select the Username by password
  15.         $query = "SELECT * FROM users WHERE Password = '$Password'";
  16.         $result = mysql_query($query);
  17.  
  18.     //If it returns a result, assign the sessions username as whats in the database
  19.         if (@mysql_num_rows($result) > 0) {
  20.             session_unset();
  21.             session_start();
  22.             while ($row = mysql_fetch_assoc($result)) {
  23.             $_SESSION['username'] = $row['Username'];
  24.             }
  25.         //make this variable 1 meaning you are logged in
  26.             $_SESSION['logged'] = 1;
  27.            
  28.         //Content after submittion
  29.             echo "<h2>Info</h2><p>Logged in!</p>";
  30.             echo "<META HTTP-EQUIV=Refresh CONTENT='0; URL=index.php'>";
  31.         } else {
  32.         //Bad credentials
  33.             echo "<h2>Info</h2><p>Incorrect Username or Password</p>";
  34.             echo "<META HTTP-EQUIV=Refresh CONTENT='1; URL=index.php?x=login'>";
  35.         }
  36.     } else {
  37.  ?>
  38.  
  39.  
  40. <form method="post" action="index.php?x=login&action=submit">
  41.     <p>
  42.             Username - <input type="text" name="Username" class="Input" style="width: 100px; height: 13px;" /><br />
  43.             Password - <input type="password" name="Password" class="Input" style="width: 100px; height: 13px;" /><br />
  44.             <input type="submit" name="submit" class="Button" value="Login" /><br />
  45.     </p>
  46. </form>
  47. <?php } } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement