What are the best practices for passing variables in URLs in PHP?

When passing variables in URLs in PHP, it is important to properly sanitize and validate the input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One common practice is to use PHP's `urlencode()` function to encode the variables before appending them to the URL. Additionally, it is recommended to use the `$_GET` superglobal array to retrieve the variables from the URL.

// Sanitize and validate input before passing variables in URL
$variable1 = urlencode($variable1);
$variable2 = urlencode($variable2);

// Append variables to URL
$url = "http://example.com/page.php?variable1=$variable1&variable2=$variable2";

// Retrieve variables from URL
$variable1 = $_GET['variable1'];
$variable2 = $_GET['variable2'];