PHP code example of silverback / iubenda-consent-solution

1. Go to this page and download the library: Download silverback/iubenda-consent-solution library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

silverback / iubenda-consent-solution example snippets



use Iubenda\ConsentSolution\Client;
use Iubenda\ConsentSolution\Consent;

$consentSolution = new ConsentSolution\Client( 'your-private-api-key' );
$consent = new ConsentSolution\Consent;

$user_id = 10;

$consent->setSubject( 
    [
        'id' => sha1( 'my_application_' . $user_id ), // you can omit this field
        'email' => '[email protected]',
        'first_name' => 'John',
        'last_name' => 'Doe',
        'full_name' => 'John Doe',
        'verified' => false
    ]
);

$consent->addLegalNotice( [ 'identifier' => 'privacy_policy' ] );            

$consent->addProof( [
    'content' => json_encode( [ 
        'first_name' => 'John', 
        'last_name' => 'Doe', 
        // other useful form fields
    ] ),
    'form' => '<form><input type="text" name="first_name">[...]</form>',
] );

$consent->preferences['privacy_policy'] = true;
$consent->preferences['third_party'] = false;
$consent->preferences['newsletter'] = true;

try {
    $saved_consent = $consentSolution->createConsent( $consent );
    echo "Successfully saved consent: " . $saved_consent->id;
} catch (\Exception $e) {
    echo "An error occurred: " . $e->getMessage();
}