Here is my code.
function login($username,$password){
global $db;
$sql = "SELECT * FROM users133 WHERE username=:username";
$stmt = $db->prepare($sql);
$stmt->execute(array(':username' => $username));
if ($stmt->rowCount() > 0){
$result = $stmt->fetchAll();
$hash = $result[0]['password'];
if (password_verify($password, $hash)) {
$_SESSION['loggedIn'] = $result[0]['id'];
header("location: ?page=profile"); /*<----AFTER LOGING IN YOU GET TO THIS PAGE*/
}else{
header("location: ?page=loginfailed");
}
}
else{
header("location: ?page=loginfailed");
}
}
Yeah i know this post is duplicate but there is additional things that i need to ask!! I spend like 6 hours today reading how to do prepared statements. i read about the $stmt->bindParam command that makes the database check if the input value is int, string and so on(in case the user played with the inspect element option or putted malicious code in the form). Is that necessary for SELECT prepared statement? I am planning to copy the code from this login function and use it elsewhere in my site. That's why i need to ask if it is 100% safe the way it is right now.