What are common security vulnerabilities in PHP scripts, such as SQL injections and cross-site scripting?

SQL injections occur when user input is not properly sanitized, allowing malicious SQL queries to be executed on the database. To prevent SQL injections, developers should use prepared statements and parameterized queries to sanitize user input before executing SQL queries.

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

Cross-site scripting (XSS) vulnerabilities occur when user input is not properly sanitized and can be executed as code in a web page, allowing attackers to steal sensitive information or perform malicious actions. To prevent XSS vulnerabilities, developers should use htmlspecialchars() function to escape user input before displaying it on the web page.

```php
// Using htmlspecialchars to prevent XSS vulnerabilities
echo htmlspecialchars($user_input);