What are common pitfalls when using PHP for login functionality?
Common pitfalls when using PHP for login functionality include not securely storing passwords (using plain text or weak hashing), not properly sanitizing user input to prevent SQL injection attacks, and not implementing proper session management to prevent unauthorized access.
// Example of securely storing passwords using password_hash() function
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Example of sanitizing user input using mysqli_real_escape_string() function
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
// Example of implementing proper session management
session_start();
$_SESSION['logged_in'] = true;