mkaplan

Untitled

Apr 20th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2. /*
  3.     Checks to make sure the login info is correct.
  4.     This page attempts to validate the (p_id, password) by checking
  5.     whether there is a row in the Person table that contains the p_id and the md5 hash of the
  6.     password. If so, start a session and store the user’s p_id as a session variable and go to
  7.     the home page. If not, show a login failed message and return to Initial page.
  8. */
  9. ?>
  10. <?php include("header.php"); ?>
  11. <?php
  12. if (!isset($_POST["email"]) || !isset($_POST["password"]) ){
  13.     echo $_POST["email"].$_POST["password"];
  14.     echo "One of the required fields was empty. Please try again.<br />";
  15.     echo "<a href=\"login.php\">Back</a>";
  16.     die();
  17. }
  18. $link = connectDB();
  19. if(!$link){
  20.     echo "Error connecting to DB<br \>";
  21.     die();
  22. }
  23.  
  24. $stmt = $link->prepare("SELECT p_id FROM person WHERE p_id = ? AND password = ?");
  25. if($DEBUG_MODE)
  26.     echo '[DEBUG]SELECT p_id FROM person WHERE p_id = ? AND password = ?';
  27. $stmt->bind_param('ss', $_POST["email"], md5($_POST["password"]));
  28. $stmt->bind_result($p_id);
  29.  
  30. if (!$stmt->execute()){
  31.     echo "Error executing prepared statement<br />";
  32.     die();
  33. }
  34.  
  35. if ($DEBUG_MODE)
  36.     echo "[DEBUG]Statement was executed correctly.<br />";
  37.  
  38. $stmt->store_result();
  39. if ($stmt->fetch()) {
  40.     echo "You were successfully authenticated as ".$p_id."<br />";
  41.     $_SESSION["p_id"] = $p_id;
  42.     echo "<a href=\"home.php\">Home</a>";
  43. }
  44. else{
  45.     echo "Wrong Email/Password combination. Please try again.<br />";
  46.     echo "<a href=\"login.php\">Back</a>";
  47. }
  48.  
  49. ?>
  50. <?php include("footer.php"); ?>
Advertisement
Add Comment
Please, Sign In to add comment