What are common security vulnerabilities in PHP programming and how can they be prevented?

One common security vulnerability in PHP programming is SQL injection, where attackers can manipulate SQL queries to access or modify sensitive data. This can be prevented by using prepared statements and parameterized queries to sanitize user input before executing SQL queries.

// Using prepared statements to prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();