Advertisement
jv17

Untitled

Nov 15th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if (isset($_POST['submit'])) {
  4.     // $lines is missing here just to avoid any problems.. but the connection to my db is working perfect..
  5.         $uid = trim($lines[0]);
  6.     $pw = trim($lines[1]);
  7.     $dbserver = trim($lines[2]);
  8.     $dbname = trim($lines[3]);
  9.     $userId = $_POST['username'];
  10.     $passId = $_POST['pwd'];
  11.     $messageErr = "";
  12.     $messageValid = "";
  13.     $valid = True;
  14.  
  15.     //Connect to the mysql server and get back our link_identifier
  16.     $link = mysqli_connect($dbserver,$uid,$pw,$dbname) or die('Could not connect: ' . mysqli_error($link));
  17.  
  18.     $db_selected = mysqli_select_db($link, $dbname) or die ('Can not use int322 : ' . mysqli_error($link));
  19.    
  20.     $name = mysqli_real_escape_string($link, $_POST['username']); // The function mysql_real_escape_string() stops hackers!
  21.     $pass = mysqli_real_escape_string($link, $_POST['pwd']); // We won't use MD5 encryption here because it is the simple tutorial, if you don't know what MD5 is, dont worry!
  22.     $result = mysqli_query($link, "SELECT * FROM users WHERE username='$userId' AND password='$passId'"); // This code uses MySQL to get all of the users in the database with that username and password.
  23.  
  24.     $count = mysqli_num_rows($result);
  25.    
  26.     if ($count==1) {
  27.         $row = mysqli_fetch_assoc($result);
  28.         if ($passId == $row['password']){
  29.             if (isset($_SESSION['loggedin'])) {
  30.                 echo "<form method='POST' action=''>";
  31.                                 echo "<table>";
  32.                 echo "<tr><td><strong class='pass'>Login Successful</strong><br></td></tr>";
  33.                 echo "<tr><td><input type='submit' name='logout' value='Logout'></td></tr>";
  34.                 echo "</form>";
  35.                                 echo "</table>";
  36.                 $logOut = $_POST['logout'];
  37.                 return true;
  38.                         }
  39.             if (isset($_POST['logout'])) {
  40.                     echo "<strong>Logout Successful</strong>";
  41.                     session_destroy();
  42.                     //header("Location: login.php");
  43.                 } else {
  44.                                     header("Location: login.php");
  45.                                 }
  46.                        
  47.         }
  48.         else {
  49.             $messageErr = "Invalid username or password!";
  50.             $valid = false;
  51.         }
  52.     }
  53.     else {
  54.         $messageErr = "Invalid username or password!";
  55.         $valid = false;
  56.     }
  57. }  
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement