php – Integrate LDAP server with vanilla forum-ThrowExceptions

Exception or error:

I’m trying to integrate vanilla forum with my company LDAP server. It’s not successful. I have no idea what’s wrong 🙁

Here’s how I do this:

The flow:

enter image description here

The plugin jsconnect is installed and config as follow:

  • ClientID: generated
  • Secret: generated
  • Authentication URL:LoginController.php

Source of LoginController.php

include 'ChromePhp.php';
require_once 'functions.jsconnect.php';

// using ldap bind

$user_ = $_POST['user'];
$pass_ = $_POST['pass'];

// $ldaprdn  = 'uid=riemann,dc=example,dc=com';     // ldap rdn or dn
// $ldappass = 'password';  // associated password
$ldaprdn  = 'uid=';
// connect to ldap server
$ldapconn = ldap_connect("")
    or die("Could not connect to LDAP server.");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

ChromePhp::log("LDAP bind start...");
$validatedUser= FALSE;
if ($ldapconn) {

    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

    // verify binding
    if ($ldapbind) {
        // echo "LDAP bind successful...";
        ChromePhp::log("LDAP bind successful...");
        $validatedUser =TRUE;
    } else {
        // echo "LDAP bind failed...";
        ChromePhp::log("LDAP bind failed...");


$attributes = array('mail','cn');
$accountname = $user_; 
$filter_person = "uid={$accountname}";
$search = ldap_search($ldapconn,"DC=example,DC=com",$filter_person , $attributes);
$data = ldap_get_entries($ldapconn, $search);
$fullname= $data[0]['cn'];
$mail= $data[0]['mail'];
$clientID = "string";
$secret = "stringSecret";

$userArray = array();
if ($validatedUser) {
   ChromePhp::log("start fill user...");
   $userArray['uniqueid'] = $user_;
   $userArray['name'] = $fullname['0'];
   $userArray['email'] = $mail['0'];
   $userArray['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 = false; 
WriteJsConnect($userArray, $_GET, $clientID, $secret, $secure);
//header("Location: ../../../v/"); /* Redirect browser */  //somehow add this make the file stop working :p 

The problem is

  • The LoginController output is {“name”:””,”photourl”:””} Seems not
  • When php jump past WriteJsConnect($user, $_GET, $clientID,
    $secret, $secure);
    nothing happen, no new user created, the role is
    still guest.
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *