How effective is using a product key for online installation verification to prevent unauthorized distribution of software by customers?

Using a product key for online installation verification can be an effective way to prevent unauthorized distribution of software by customers. This method requires users to enter a unique product key during the installation process, which is then verified online to ensure it is valid. If the product key is not valid or has already been used, the installation process can be halted, preventing unauthorized distribution.

// Check if the product key is valid
function verifyProductKey($productKey) {
    // Make an API call to verify the product key
    // Return true if the product key is valid, false otherwise
}

$productKey = $_POST['product_key'];

if (verifyProductKey($productKey)) {
    // Proceed with the installation process
    echo "Product key verified. Installation successful.";
} else {
    // Halt the installation process
    echo "Invalid product key. Installation failed.";
}