PHP code example of verifence / verifence-php

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

    

verifence / verifence-php example snippets


use Verifence\Client;
use Verifence\QuotaExceededException;

$vf = new Client(getenv('VERIFENCE_KEY'));

// Before you hand a message to Twilio/Vonage/etc:
$verdict = $vf->check(
    phone: '+14155552671',
    clientIp: $request->ip(),   // the END USER's IP, from your inbound request
    userId: 'u_123',
);

if (! $verdict['allow']) {
    // Do not send — you just saved the message fee.
    return response()->json(['error' => 'too_many_verification_requests'], 429);
}

// ... send the SMS with your provider ...

// After the user enters the correct code:
$vf->confirm(clientIp: $request->ip());

try {
    $verdict = $vf->check('+14155552671', $ip);
} catch (QuotaExceededException $e) {
    // $e->resetsAt() → ISO-8601 reset time
}
bash
composer