<?php
$filter = "(mail=name@test.com)";
//$ldapuser = 'cmdbldap'; // 域用户名
//$ldappass = "CmdbLd@p"; // 域用户密码
$mail = 'name@test.com'; // 域用户名
$pwd = "password";
$basedn = "OU=jianshu,DC=jianshu,DC=com";
// 这里配置域服务器的ip或者域名
$ldapconn = ldap_connect("ldap.jianshu.com.cn") 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 );
if($ldapconn){
$ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass) or die ("Error trying to bind: ".ldap_error($ldapconn));
if ($ldapbind) {
echo "LDAP bind successful...\n\n";
$result = ldap_search($ldapconn,$basedn, $filter) or die ("Error in search query: ".ldap_error($ldapconn));
var_dump($result);
$data = ldap_get_entries($ldapconn, $result);
var_dump($data[0]['dn']);
if ( $data[0] ){
$sr = ldap_bind( $ldapconn, $data[0]['dn'],'');
print_r("$sr\n");
if ( $sr ){
echo "True!\n";
}else{
echo "sencond false!\n";
}
}else{
echo "first false!\n";
}
echo "\n";
}
}else{
echo "False";
}
ldap_close($ldapconn);
?>
网友评论