PHP code example of loginradius / php-sdk

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

    

loginradius / php-sdk example snippets


use LoginRadius\Sdk\Client;
use LoginRadius\Sdk\Config;

$client = new Client(new Config(apiKey: getenv('LR_API_KEY')));

$result = $client->login->checkUserNameAvailability(username: 'alice');

$config = new Config(
    apiKey: getenv('LR_API_KEY'),
    apiSecret: getenv('LR_API_SECRET'),   // server-side only
    accessToken: $sessionAccessToken,
);

use LoginRadius\Sdk\LoginRadiusException;

try {
    $client->user->getAccountDetails(accessToken: $accessToken);
} catch (LoginRadiusException $e) {
    if ($e->isAuth()) {
        // 401 — missing or invalid credentials
    }
    echo $e->statusCode(), ' ', $e->code(), ' ', $e->description();
}

use LoginRadius\Sdk\Sott;

$sott = Sott::generate($apiKey, $apiSecret);
bash
composer install
export LR_API_KEY=... LR_API_SECRET=...
php -S localhost:8080 demo/index.php