PHP code example of stylers-llc / chopra-account-php-sdk

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

    

stylers-llc / chopra-account-php-sdk example snippets


$client = new Client([
	'client_key' => '[your_client_key]',
	'client_secret' => '[your_32_chars_client_secret]',
	'session_host' => '[memcache_host_name]',
	'session_port' => '[memcache_port]',
	'endpoint_basepath' => 'http://account.chopra.com/', 
	'api_key' => '[api_secret_key]',
	'api_endpoint' => 'http://account-api.chopra.com/', 
    'cookie_domain' => '[cookie_domain]'
]);

try {
	// it throws an exception if there is no cookie or it is wrong or it has a invalid session ID
	$ssoUser = $client->getUser();
} catch (SSOAuthException $e) {
	// in this case you should redirect to SSO check URL which restore the user session from an existing session ID or if the user is not logged in (there is no existing session) then creates a guest session
	header('Location: ' . $client->getCheckUrl('http://[yourhost.tld]')); 
    // you have to provide the redirect URL as parameter where the SSO should redirect back to. It can be any URL where this code snippet runs again. You can redirect to any URL because this code should be executed at each runtime.
}

if (!$client->memberLoggedIn()) {
	// we display an SSO login URL.

	// for the getLoginUrl params you have to give a redirect URL also
	echo '<a href="' . $client->getLoginUrl('http://[yourhost.tld]') . '">Login with SSO</a>';
}

if ($client->memberLoggedIn()) {
	echo $client->getLogoutUrl('http://[yourhost.tld]');
}

if ($client->memberLoggedIn()) {
	echo $client->getProfileEditUrl('http://[yourhost.tld]');
}

if (!$client->memberLoggedIn()) {
	echo '<a href="' . $client->getLoginUrl('http://[yourhost.tld]') . '">Login with SSO</a>';
	echo '<a href="' . $client->getSocialLoginUrl('http://[yourhost.tld]', 'google', ['id' => '{social_id}', 'token' => '{social_token}' ]) . '">Login with social</a>';
}

        $postData = [
            'zip_code' => '1234', // any zip code, geUser = $client->api()->makeCall(
            'mas_user_id',
            'POST',
            [],
            $postData
        );