Advertisement
didine46

Untitled

Dec 19th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. if (isset($_SESSION["logged_in"]))
  5. {
  6.  header("Location: home.php");
  7. }
  8.  
  9. $username=$_POST["username"];
  10. $password=$_POST["password"];
  11.  
  12. // encrypt in MD5 and compare what's on the database
  13. $password=md5($password);
  14.  
  15.  
  16. $db = new PDO('mysql:host=127.0.0.1;dbname=dropbin;charset=utf8', '', '');
  17. $stmt = $db->query("SELECT * FROM user where username='$username' and password='$password'");
  18. echo "you are using $username and password $password<br>";
  19. $authenticated=true;
  20. if($stmt)
  21. {
  22.    
  23.         $authenticated=false;
  24.         while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  25.            
  26.             echo "First Name: ". $row['first_name']. " <br> last name is:  ". $row['last_name'] ." <br>Email: ".$row["email"];
  27.             $_SESSION["logged_in"]=true;
  28.             $_SESSION["username"]=$row["username"];
  29.             $_SESSION["first_name"]=$row["first_name"];
  30.             $_SESSION["last_name"]=$row["last_name"];
  31.             $_SESSION["email"]=$row["email"];
  32.             $_SESSION["user_id"]=$row["id"];
  33.            
  34.            
  35.            
  36.            
  37.             //forward to home page
  38.              header("Location: home.php");
  39.         }  
  40.        
  41.        
  42.  
  43. }
  44. if(!$authenticated)
  45.     echo "Sorry wrong username and password";
  46.  
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement