Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Checks to make sure the login info is correct.
- This page attempts to validate the (p_id, password) by checking
- whether there is a row in the Person table that contains the p_id and the md5 hash of the
- password. If so, start a session and store the user’s p_id as a session variable and go to
- the home page. If not, show a login failed message and return to Initial page.
- */
- ?>
- <?php include("header.php"); ?>
- <?php
- if (!isset($_POST["email"]) || !isset($_POST["password"]) ){
- echo $_POST["email"].$_POST["password"];
- echo "One of the required fields was empty. Please try again.<br />";
- echo "<a href=\"login.php\">Back</a>";
- die();
- }
- $link = connectDB();
- if(!$link){
- echo "Error connecting to DB<br \>";
- die();
- }
- $stmt = $link->prepare("SELECT p_id FROM person WHERE p_id = ? AND password = ?");
- if($DEBUG_MODE)
- echo '[DEBUG]SELECT p_id FROM person WHERE p_id = ? AND password = ?';
- $stmt->bind_param('ss', $_POST["email"], md5($_POST["password"]));
- $stmt->bind_result($p_id);
- if (!$stmt->execute()){
- echo "Error executing prepared statement<br />";
- die();
- }
- if ($DEBUG_MODE)
- echo "[DEBUG]Statement was executed correctly.<br />";
- $stmt->store_result();
- if ($stmt->fetch()) {
- echo "You were successfully authenticated as ".$p_id."<br />";
- $_SESSION["p_id"] = $p_id;
- echo "<a href=\"home.php\">Home</a>";
- }
- else{
- echo "Wrong Email/Password combination. Please try again.<br />";
- echo "<a href=\"login.php\">Back</a>";
- }
- ?>
- <?php include("footer.php"); ?>
Advertisement
Add Comment
Please, Sign In to add comment