Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <?php
  2.  
  3. $dsn = 'mysql:host=localhost;dbname=social';
  4. $user = 'root';
  5. $pass = '1234';
  6.  
  7. try{
  8. $pdo = new PDO($dsn, $user, $pass);
  9.  
  10. }catch(PDOException $e){
  11. echo 'Connection error!' . $e->getMessage();
  12. }?>
  13.  
  14. <?php
  15. include 'includes/connection.php';
  16. include 'classes/user.php';
  17. include 'classes/tweet.php';
  18. include 'classes/follow.php';
  19.  
  20. global $pdo;
  21.  
  22. session_start();
  23.  
  24. $getFromU = new User($pdo);
  25. $getFromT = new Tweet($pdo);
  26. $getFromF = new Follow($pdo);
  27.  
  28. define("BASE_URL", "http://localhost/finalproject/src/");?>
  29.  
  30. <?php
  31.  
  32. class User{
  33. protected $pdo;
  34.  
  35. function __construct($pdo){
  36. $this->pdo = $pdo;
  37. }
  38.  
  39. public function checkInput($var){
  40. $var = htmlspecialchars($var);
  41. $var = trim($var);
  42. $var = stripcslashes($var);
  43. return $var;
  44. }
  45.  
  46. public function login($email, $password){
  47. $stmt = $this->pdo->prepare("SELECT 'user_id' FROM 'users' WHERE
  48. 'email' = :email AND 'password' = :password");
  49. $stmt->bindParam(":email", $email, PDO::PARAM_STR);
  50. $stmt->bindParam(":password", md5($password), PDO::PARAM_STR);
  51. $stmt->execute();
  52.  
  53. $user = $stmt->fetch(PDO::FETCH_OBJ);
  54. $count = $stmt->rowCount();
  55.  
  56. if($count > 0){
  57. $_SESSION['user_id'] = $user->user_id;
  58. header('Location: home.php');
  59. }else{
  60. return false;
  61. }
  62. }
  63. }?>
  64.  
  65. <?php
  66.  
  67. if(isset($_POST['login']) && !empty($_POST['login'])){
  68. $email = $_POST['email'];
  69. $password = $_POST['password'];
  70.  
  71. if(!empty($email) or !empty($password)){
  72. $email = $getFromU->checkInput($email);
  73. $password = $getFromU->checkInput($password);
  74.  
  75. if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  76. $error = "Invalid format";
  77. }else{
  78. if($getFromU->login($email, $password) === false){
  79. echo $email;
  80. echo $password;
  81. $error = "The email or password is incorrect!";
  82. }
  83. }
  84. }else{
  85. $error = "Please enter username and password!";
  86. }
  87. }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement