01-15-2010, 06:36 PM
now my ldap connection work .
new code for op\op.login.php
if (!is_bool($ds)) {
// Ensure that the LDAP connection is set to use version 3 protocol.
// Required for most authentication methods, including SASL.
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
// try an anonymous bind first. If it succeeds, get the DN for the user.
$bind = @ldap_bind($ds, $login."@xxxxx.com", $pwd);
if ($bind) {
// Successfully authenticated. Now check to see if the user exists within
// the database. If not, add them in, but do not add their password.
$user = getUserByLogin($login);
if (is_bool($user) && !$settings->_restricted) {
// Retrieve the user's LDAP information.
$filter='(&(Sn=*)(givenname=*))';
$search = ldap_search($ds, $settings->_ldapBaseDN, $filter);
if (!is_bool($search)) {
$info = ldap_get_entries($ds, $search);
if (!is_bool($info) && $info["count"]==1 && $info[0]["count"]>0) {
$user = addUser($login, null, $info[0]['cn'][0], $info[0]['mail'][0], $settings->_language, $settings->_theme, "");
}*/
$tab=array();
for ($i=0; $i < $info["count"]; $i++){
if(strtoupper($info[$i]["samaccountname"][0])==strtoupper($login)){
$tab['cn']=$info[$i]["cn"][0];
$tab['mail']=$info[$i]["mail"][0];
$user = addUser($login, md5($pwd), $tab['cn'], $tab['mail'], $settings->_language, $settings->_theme, "");
}
}
}
}
if (!is_bool($user)) {
$userid = $user->getID();
}
}
ldap_close($ds);
}
}
new code for op\op.login.php
if (!is_bool($ds)) {
// Ensure that the LDAP connection is set to use version 3 protocol.
// Required for most authentication methods, including SASL.
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
// try an anonymous bind first. If it succeeds, get the DN for the user.
$bind = @ldap_bind($ds, $login."@xxxxx.com", $pwd);
if ($bind) {
// Successfully authenticated. Now check to see if the user exists within
// the database. If not, add them in, but do not add their password.
$user = getUserByLogin($login);
if (is_bool($user) && !$settings->_restricted) {
// Retrieve the user's LDAP information.
$filter='(&(Sn=*)(givenname=*))';
$search = ldap_search($ds, $settings->_ldapBaseDN, $filter);
if (!is_bool($search)) {
$info = ldap_get_entries($ds, $search);
if (!is_bool($info) && $info["count"]==1 && $info[0]["count"]>0) {
$user = addUser($login, null, $info[0]['cn'][0], $info[0]['mail'][0], $settings->_language, $settings->_theme, "");
}*/
$tab=array();
for ($i=0; $i < $info["count"]; $i++){
if(strtoupper($info[$i]["samaccountname"][0])==strtoupper($login)){
$tab['cn']=$info[$i]["cn"][0];
$tab['mail']=$info[$i]["mail"][0];
$user = addUser($login, md5($pwd), $tab['cn'], $tab['mail'], $settings->_language, $settings->_theme, "");
}
}
}
}
if (!is_bool($user)) {
$userid = $user->getID();
}
}
ldap_close($ds);
}
}