What is the correct syntax to retrieve a variable from a URL in PHP?
To retrieve a variable from a URL in PHP, you can use the $_GET superglobal array. This array contains key-value pairs of variables passed in the URL. To access a specific variable, you can use $_GET['variable_name']. Make sure to sanitize and validate the input to prevent security vulnerabilities.
// Retrieve a variable named 'id' from the URL
$id = $_GET['id'];
// Sanitize and validate the input
$id = filter_var($id, FILTER_SANITIZE_NUMBER_INT);
// Use the variable in your code
echo "The ID retrieved from the URL is: " . $id;