What are some common security concerns when passing variables in PHP, and how can they be addressed to prevent manipulation of data?

One common security concern when passing variables in PHP is the risk of data manipulation through techniques like SQL injection or cross-site scripting. To prevent this, it is important to sanitize and validate user input before using it in your code. This can be achieved by using functions like htmlspecialchars() to encode special characters or prepared statements to prevent SQL injection attacks.

// Example of sanitizing user input using htmlspecialchars()
$user_input = "<script>alert('XSS attack!');</script>";
$clean_input = htmlspecialchars($user_input, ENT_QUOTES, 'UTF-8');
echo $clean_input;