-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser.php
More file actions
49 lines (37 loc) · 1.07 KB
/
user.php
File metadata and controls
49 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
*
*/
class User {
protected $pdo;
function __construct($pdo){
$this->pdo = $pdo;
}
public function checkInput($var){ #only to make valid email and pass
$var = htmlspecialchars($var);
$var = trim($var);
$var = stripcslashes($var);
return $var;
}
public function login($email, $password){
$stmt = $this->pdo->prepare("SELECT `user_id` FROM `users` WHERE `email` = :email AND `password` = :password");
$stmt->bindParam(":email", $email, PDO::PARAM_STR);
$stmt->bindParam(":password", $password, PDO::PARAM_STR); #md5 secure
$stmt->execute();
#this is changes that i have made.
$user = $stmt->fetch(PDO::FETCH_OBJ);
if($count > 0) {
$_SESSSION['user_id'] = $user->user_id;
header('Location: home.php');
}else {
return false;
}
}
public function userData($user_id){
$stmt = $this->pdo->prepare("SELECT * FROM `users` WHERE `user_id` = :user_id");
$stmt->bindParam(":user_id", $user_id, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetch(PDO::FETCH_OBJ);
}
}
?>