Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?php
  2. include_once("../vendor/autoload.php");
  3. session_start();
  4.  
  5. if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true)
  6. {
  7. header("location: /mainpage.php");
  8. exit;
  9. }
  10.  
  11. if (!empty($_POST))
  12. {
  13.  
  14. $username = $_POST["email"];
  15. $password = $_POST["password"];
  16. $mng = new MongoDB\Driver\Manager("mongodb://localhost:27017");
  17.  
  18. $filter = [
  19. '_id'=>$username,
  20. 'password' =>$password
  21. ];
  22.  
  23. $query = new MongoDB\Driver\Query($filter);
  24. $cursor = $mng->executeQuery('Assignment2.MyUsersCollection', $query);
  25.  
  26. foreach($cursor as $row)
  27. {
  28. $_SESSION["userid"] = $row->_id;
  29. $_SESSION["loggedin"] = true;
  30. header("location: /mainpage.php");
  31. }
  32.  
  33. echo '<script type="text/JavaScript">
  34. alert("Your UserID or Password is incorrect");
  35. </script>';
  36. }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement