I am trying to search Active Directory if the user exists. I am getting the following error message. 'Unable to search LDAP server'. What could be wrong? Please suggest.
<?php
// LDAP variables
$ldaphost = "servername"; // your ldap servers
$ldapport = 389; // your ldap server's port number
// Connecting to LDAP
$ldapconn = ldap_connect($ldaphost, $ldapport)
or die("Could not connect to $ldaphost");
$user = 'mylastname';
//search user in /Admin/IT/Users
$dn = "OU=Admin, OU=IT, OU=Users, DC=school, DC=edu";
$filter = "(sAMAccountName=" . $user . ")";
$attr = array("memberof");
$result = ldap_search($ldapconn , $dn, $filter, $attr) or exit("Unable to search LDAP server");
$entries = ldap_get_entries($ldapconn, $result);
echo $entries["count"]." entries returned\n";
?>