1. Go to this page and download the library: Download websvc/yii2-ldap 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/ */
websvc / yii2-ldap example snippets
return [
//....
'components' => [
'ldap' => [
'class' => 'websvc\ldap\Connection',
// Mandatory Configuration Options
'dc' => [
'192.168.1.1',
'ad.com'
],
'baseDn' => 'dc=ad,dc=com',
'username' => '[email protected]',
'password' => 'password',
// Optional Configuration Options
'port' => 389,
'followReferrals' => false,
'useTLS' => true,
// Change pageSize (e.g. to 1000) if you are getting the following message
// with large result sets:
// ldap_search(): Partial search results returned: Sizelimit exceeded
'pageSize' => -1,
// Change the attribute to use for login
'loginAttribute' => 'uid',
// for check if user has access to application
'authAccess' => [
'cn' => 'cn=restricted,ou=Groups', // Cn name, will be concatenated with baseDn
'objectClass' => 'posixGroup', // object class to search
'attributeMatch' => 'memberUid', // attribute to match user
]
],
]
];
try {
if (Yii::$app->ldap->auth($this->username, $password)) {
// Credentials were correct.
} else {
// Credentials were incorrect.
}
} catch (Exception $e) {
// error
}
}
try {
$ldap = Yii::$app->ldap;
if($ldap->auth($this->username, $this->password)) { //Yii loginform username/password
$user_data = $ldap->checkAccessReturnUserdata();
if( !empty($user_data)){
if ($this->_user === null) {
// Do your magic
echo '<pre>';
print_r($user_data);
echo '</pre>';
}
}
} else {
// Credentials were incorrect.
// Will not return anything
}
} catch (Exception $e) {
// error
// Will not return anything
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.