PHP code example of corbado / php-sdk

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

    

corbado / php-sdk example snippets


$config = new Corbado\Config('<Project ID>', '<API secret>', '<Frontend API URL>', '<Backend API URL>');
$sdk = new Corbado\SDK($config);

$user = $sdk->sessions()->getCurrentUser();

try {
    // Try to get non-existing user with ID 'usr-123456789'
    $user = $sdk->users()->get('usr-123456789');
} catch (ServerException $e) {
    // Show HTTP status code (400 in this case)
    echo $e->getHttpStatusCode() . PHP_EOL;
    
    // Show request ID (can be used in developer panel to look up the full request
    // and response, see https://app.corbado.com/app/logs/requests)
    echo $e->getRequestID() . PHP_EOL;
    
    // Show full request data
    var_dump($e->getRequestData());
    
    // Show runtime of request in seconds (server side)
    echo $e->getRuntime() . PHP_EOL;
    
    // Show validation error messages (server side validation in case of HTTP
    // status code 400 (Bad Request))
    var_dump($e->getValidationMessages());
    
    // Show full error data
    var_dump($e->getError());
}
bash
composer