What is the best practice for passing variables through URLs in PHP?

When passing variables through URLs in PHP, it is best practice to use URL encoding to ensure that special characters are properly handled and to prevent injection attacks. One common method is to use the `urlencode()` function to encode the variables before appending them to the URL. When receiving the variables, you can use the `$_GET` superglobal to access and sanitize the values.

// Encoding variables before passing them through URLs
$variable1 = 'example value';
$encoded_variable1 = urlencode($variable1);

// Appending the encoded variables to the URL
$url = 'http://example.com/page.php?var1=' . $encoded_variable1;

// Retrieving and sanitizing the variables
$received_variable1 = isset($_GET['var1']) ? $_GET['var1'] : '';
$decoded_variable1 = urldecode($received_variable1);