Advertisement
PaulLT

login.php

Jun 1st, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2. error_reporting(-1);
  3. require('password.php');
  4. //include('iflogin.php');
  5. include('config.php');
  6. $pwd = $_POST['password'];
  7. $name = $_POST['email'];
  8. $con = new PDO('mysql:host='.DB_HOST.';dbname='.DB_DB.';charset=utf8_general_ci', DB_USERNAME, DB_PASSWORD, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
  9. $con->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  10. try{
  11. $sql = $con->prepare('SELECT * FROM users WHERE name=:name OR email=:name');
  12. $sql->bindValue(':name', $name);
  13. $result = $sql->fetch();
  14. }catch(PDOException $ex){
  15. echo 'Error! '.$ex->getMessage();
  16. }
  17.  
  18. // check password
  19. if(password_verify($pwd,$result['password'])){
  20. //calculate when the session should expire
  21. $expires = time() + (60 * SESSION_LENGTH);
  22. //log in
  23. $sql = $con->prepare("INSERT INTO `active_users` (`user`,`session_id`,`expires`) VALUES (`:user`,`:id`,`:expires`)");
  24. $sql->bindValue(':user', $result['id']);
  25. $sql->bindValue(':id', session_id());
  26. $sql->bindValue(':expires', $expires);
  27. $sql->execute();
  28. if($result['side']){
  29. $side = 'heaven';
  30. }else{
  31. $side = 'hell';
  32. }
  33. // redirect to game
  34. header('Location: /'.$side);
  35. }else{
  36. //password incorrect
  37. die("INCORRECT PASSWORD YOU BASTARD!");
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement