PHP code example of vanilla / js-connect-php

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

    

vanilla / js-connect-php example snippets


$jsConnect = new \Vanilla\JsConnect\JsConnect();

// 1. Add your client ID and secret. These values are defined in your dashboard.
$jsConnect->setSigningCredentials($clientID, $secret);

// 2. Grab the current user from your session management system or database here.
$signedIn = true; // this is just a placeholder

// YOUR CODE HERE.

// 3. Fill in the user information in a way that Vanilla can understand.
if ($signedIn) {
    // CHANGE THESE FOUR LINES.
  	$jsConnect
        ->setUniqueID('123')
      	->setName('Username')
      	->setEmail('[email protected]')
      	->setPhotoUrl('https://example.com/avatar.jpg');
} else {
  $jsConnect->setGuest(true);
}

// 4. Generate the jsConnect response and redirect.
$jsConnect->handleRequest($_GET);


// 1. Get your client ID and secret here. These must match those in your jsConnect settings.
$clientID = "1234";
$secret = "1234";

// 2. Grab the current user from your session management system or database here.
$signedIn = true; // this is just a placeholder

// YOUR CODE HERE.

// 3. Fill in the user information in a way that Vanilla can understand.
$user = array();

if ($signedIn) {
    // CHANGE THESE FOUR LINES.
    $user['uniqueid'] = '123';
    $user['name'] = 'John PHP';
    $user['email'] = '[email protected]';
    $user['photourl'] = '';
}

// 4. Generate the jsConnect string.

// This should be true unless you are testing.
// You can also use a hash name like md5, sha1 etc which must be the name as the connection settings in Vanilla.
$secure = true;
writeJsConnect($user, $_GET, $clientID, $secret, $secure);