What potential security risks are involved in directly passing session values into SQL queries in PHP?
Passing session values directly into SQL queries in PHP can lead to SQL injection attacks if the session values are not properly sanitized. To prevent this, it is important to sanitize the session values before using them in SQL queries by using prepared statements or escaping the values.
// Example of using prepared statements to prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $_SESSION['username']);
$stmt->execute();