What best practices should be followed when passing variables between PHP scripts, especially when dealing with the $_GET superglobal array?

When passing variables between PHP scripts, especially when using the $_GET superglobal array, it is important to properly sanitize and validate the input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One best practice is to use filter_input() function to retrieve and sanitize input from $_GET array. Additionally, always validate and sanitize the input before using it in your code to ensure data integrity and security.

// Retrieving and sanitizing input from $_GET array using filter_input()
$variable = filter_input(INPUT_GET, 'variable', FILTER_SANITIZE_STRING);

// Validating the input before using it in your code
if ($variable !== false) {
    // Use the sanitized input in your code
    echo "Variable: " . $variable;
} else {
    // Handle invalid input
    echo "Invalid input";
}