Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php ob_start(); ?>
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5.  
  6. <body>
  7.  
  8. <?php
  9. // store the inputs & hash the password
  10. $username = $_POST['username'];
  11. $password = hash('sha512', $_POST['password']);
  12.  
  13. // connect
  14. $conn = new PDO('mysql:host=sql.computerstudi.es;dbname=gc200339576', 'gc200339576', 'ANiYXWZf');
  15.  
  16. // write the query
  17. $sql = "SELECT user_id FROM users WHERE username = :username AND password = :password";
  18.  
  19. // create the command, run the query and store the result
  20. $cmd = $conn->prepare($sql);
  21. $cmd->bindParam(':username', $username, PDO::PARAM_STR, 50);
  22. $cmd->bindParam(':password', $password, PDO::PARAM_STR, 128);
  23. $cmd->execute();
  24. $users = $cmd->fetchAll();
  25.  
  26. // if count is 1, we found a matching username and password in the database
  27. if (count($users) >= 1) {
  28. echo 'Logged in Successfully.';
  29.  
  30. foreach ($users as $user) {
  31. //get user_id and store it b/c web is stateless
  32. //take user to subscribe.php
  33.  
  34. //access current user session
  35. session_start();
  36.  
  37. //store users unique id in a session variable
  38. $_SESSION['user_id'] = $user['user_id'];
  39.  
  40. //redirect
  41. header('location:menu.php');
  42. }
  43. }
  44. else {
  45. echo 'Invalid Login';
  46. }
  47.  
  48. $conn = null;
  49. ?>
  50.  
  51. </body>
  52. </html>
  53. <?php ob_flush(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement