What is the best practice for passing an ID with a link in PHP?

When passing an ID with a link in PHP, the best practice is to use query parameters in the URL. This allows you to easily retrieve the ID on the receiving end using the $_GET superglobal. Make sure to properly sanitize and validate the ID before using it to prevent any security vulnerabilities.

// Example of passing an ID with a link using query parameters
$id = 123; // ID to pass
$link = "example.php?id=" . $id; // Constructing the link with the ID

// In example.php, retrieve the ID using $_GET
if(isset($_GET['id'])) {
    $id = $_GET['id'];
    // Sanitize and validate the ID before using it
}