分类: LINUX
2012-12-31 10:13:59
一,由于公司的centos系统中的php标准安装没有php-ldap相关插件,报错信息如下:
Fatal error: Call to undefined function ldap_connect() in /home/www/corp/login.php on line 11
二,安装php-ldap
yum install php-ldap
find / –name “*ldap.so”
#/usr/lib64/php/modules/ldap.so #查找模块位置
vim php.ini
添加extension=#/usr/lib64/php/modules/ldap.so
/etc/init.d/php-fpmd restart #重启php-fpmd
三,login1.php
$username = ;
$password = '密码';
$conn = ldap_connect('域控地址')
or die('warning');
if ($conn)
{
$bind = ldap_bind($conn,$username, $password);
if ($bind)
{
echo "yes";
} else {
echo "no";
}
}
?>
四,login2.php
$hostname="域控地址";
$port = 389;
$username_linux = "cn=Manager,dc=example,dc=com";#openldap账号
$username_windows = administrator@x.com;#域控账号
$password = "密码";
$basedn = "dc=yu,dc=com"; #基本DN
if( $port )
{
$ds=ldap_connect($hostname,$port);
}
else
{
$ds=ldap_connect($hostname);
}
if( $ds )
{
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ds, LDAP_OPT_REFERRALS,0);
$r=ldap_bind($ds,$username_windows,$password); #ldap_bind的返回值是一个布尔类型,我们可以根据返回值判断用户的登录证书是否有效
$sr=ldap_search($ds, $basedn,"(objectClass=*)");
echo "Number of entires returned is " . ldap_count_entries($ds, $sr) . "
";
$info = ldap_get_entries($ds, $sr);
var_dump($info);
ldap_close($ds);
}
else
{
echo "
?>