PHP code example of veribenim / php-sdk

1. Go to this page and download the library: Download veribenim/php-sdk 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/ */

    

veribenim / php-sdk example snippets



use Veribenim\VeribenimClient;

// SDK'yı başlat
$client = new VeribenimClient(
    token: 'your_api_token',
    domain: 'example.com', // Bundle script URL için (example.com → examplecom.js)
    lang: 'tr',
    debug: false
);

// Form rızası kaydet
$client->logFormConsent(
    formName: 'contact',
    consented: true,
    consentText: 'KVKK şartlarını kabul ettim',
    metadata: ['email' => '[email protected]']
);

// Veri sahibi erişim isteği
$client->submitDsar(
    requestType: 'access',
    fullName: 'John Doe',
    email: '[email protected]'
);


Veribenim\VeribenimClient;

$client = new VeribenimClient(
    token: 'your_site_token_here',  // https://veribenim.com/dashboard
    domain: 'example.com',          // Bundle script URL (example.com → examplecom.js)
    lang: 'tr',                      // Dil seçimi
    debug: false                     // Production'da false
);

// .env dosyanız varsa:
$client = new VeribenimClient(
    token: $_ENV['VERIBENIM_TOKEN'],
    domain: $_ENV['VERIBENIM_DOMAIN'] ?? '',
    lang: $_ENV['VERIBENIM_LANG'] ?? 'tr',
    debug: $_ENV['APP_DEBUG'] ?? false
);

// app/Providers/AppServiceProvider.php
public function register()
{
    $this->app->singleton(VeribenimClient::class, function () {
        return new VeribenimClient(
            token: config('veribenim.token'),
            domain: config('veribenim.domain'),
            lang: config('veribenim.lang'),
            debug: config('app.debug')
        );
    });
}

// wp-content/plugins/veribenim-consent/veribenim-consent.php
$veribenim = new VeribenimClient(
    token: get_option('veribenim_token'),
    lang: 'tr'
);

// Hook'lar ile entegre edin
add_action('wp_footer', function() use ($veribenim) {
    $veribenim->logImpression();
});

use Veribenim\VeribenimClient;

$client = new VeribenimClient('TOKEN_HERE');

// Tüm metodlar:
$client->logFormConsent(...);      // Form rızası
$client->getPreferences(...);      // Tercih al
$client->savePreferences(...);     // Tercih kaydet
$client->logImpression();          // Sayfa ziyareti
$client->logConsent(...);          // Manuel rıza
$client->withdrawConsent(...);     // Rızayı geri çek (KVKK Md.11/1-e)
$client->submitDsar(...);          // DSAR isteği
$client->getFormSchema(...);       // Form şeması (çoklu dil)
$client->submitForm(...);          // Form gönderimi
$client->renderFormHtml(...);      // Sunucu tarafı form render
$client->collectAnalytics(...);    // Web analytics hit
$client->trackEvent(...);          // Özel olay (tracked event) tetikleme
$client->getVendors();             // IAB TCF v2.2 vendor listesi
$client->scanCookies(...);         // Çerez/tracker taraması
$client->verifyDomain(...);        // Domain doğrulama
$client->scriptTag();              // Banner script tag'i
$client->impressionPixelUrl(...);  // 1x1 pixel fallback URL

try {
    $client->logFormConsent(
        formName: 'newsletter_signup',
        consented: true,
        consentText: 'Haber bültenine abone olmak için kişisel verilerinizin işlenmesine rıza veriyorum.',
        metadata: [
            'email' => '[email protected]',
            'source' => 'homepage',
            'language' => $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? 'tr'
        ]
    );
    
    // İşlem başarılı
    $response = json_encode(['status' => 'success']);
} catch (Exception $e) {
    // Hata yönetimi
    error_log('Veribenim error: ' . $e->getMessage());
}

[
    'success' => true,
    'message' => 'Form consent logged',
    'consent_id' => '550e8400-e29b-41d4-a716-446655440000'
]

// Oturumdan session ID'yi al
$sessionId = $_COOKIE['veribenim_session'] ?? null;

$preferences = $client->getPreferences($sessionId);

// Çıktı:
// [
//     'necessary' => true,
//     'analytics' => false,
//     'marketing' => true,
//     'preferences' => true,
// ]

if ($preferences['analytics']) {
    // Analytics kodu çalıştır
    echo "<script>gtag('config', 'GA_ID');</script>";
}

$client->savePreferences([
    'necessary' => true,    // Her zaman true
    'analytics' => true,
    'marketing' => false,
    'preferences' => true
]);

// AJAX ile
header('Content-Type: application/json');
echo json_encode(['status' => 'saved']);

// Her sayfada çalıştır
$client->logImpression();

// Veya Analytics entegrasyonu
if ($client->getPreferences()['analytics']) {
    $client->logImpression();
}

$client->logConsent([
    'categories' => ['analytics', 'marketing'],
    'language' => 'tr',
    'ip_address' => $_SERVER['REMOTE_ADDR'],
    'user_agent' => $_SERVER['HTTP_USER_AGENT'],
    'consent_timestamp' => date('c')
]);

public function handleDataRequest() {
    $requestType = $_POST['request_type'];  // Validation yap!
    $fullName = $_POST['full_name'];
    $email = $_POST['email'];
    $description = $_POST['description'] ?? '';
    
    try {
        $response = $client->submitDsar(
            requestType: $requestType,
            fullName: $fullName,
            email: $email,
            description: $description
        );
        
        // E-mail kullanıcıya gönder
        mail($email, 'İsteğiniz kaydedildi', 
            'En kısa zamanda size dönüş yapılacaktır.');
            
        return ['success' => true, 'request_id' => $response['id']];
        
    } catch (Exception $e) {
        return ['success' => false, 'error' => $e->getMessage()];
    }
}

[
    'success' => true,
    'request_id' => '550e8400-e29b-41d4-a716-446655440000',
    'status' => 'submitted',
    'estimated_completion' => '2026-04-30'
]

// Kullanıcı "Tüm izinleri geri çek" butonuna tıkladığında
$sessionId = $_COOKIE['veribenim_session'] ?? null;

try {
    $client->withdrawConsent($sessionId);
    // Başarılı — tüm consent verisi temizlendi, log kaydı tutuldu
    http_response_code(200);
    echo json_encode(['withdrawn' => true]);
} catch (Exception $e) {
    error_log('Withdraw error: ' . $e->getMessage());
}

// Sayfa yüklenirken kontrol et
$preferences = $client->getPreferences($sessionId);

if ($preferences['consent_renewal_

use Veribenim\VeribenimClient;
use Veribenim\VeribenimConfig;

$client = new VeribenimClient(new VeribenimConfig(
    token: getenv('VERIBENIM_TOKEN'),
    domain: 'siteniz.com',
    lang: 'tr',
    timeout: 10,   // HTTP timeout (saniye)
    debug: false,  // Production'da MUTLAKA false
));
bash
composer 
bash
composer