|
Posted by downlode on 11/10/06 11:48
Hi,
I have a basic script for querying an ldap server. It works fine from
my college's production server, but not from another server in the
network, though I have been assured access should be allowed from
there.
It fails at the ldap_bind() function. This function only returns a
boolean value. How might I retrieve a meaninful error message? Any
ideas where the problem is likely to lie, with this basic info?
Here is the code.
//----------------------------------------------------------------
$myclient="usernamehere";
echo "<h3>LDAP query test</h3>";
echo "<B>Connecting ...</B><BR>";
$ds=ldap_connect("xxxxx.xxxxx.ac.uk"); // working address supplied
here...
echo "connect result is ".$ds."<p>";
if ($ds) {
echo "Binding ...(anon)...";
$r=ldap_bind($ds);
echo "Bind result is ".$r."<p>";
echo "Searching for <B>$myclient</B> ...";
// Search surname entry
$sr=ldap_search($ds,"OU=STAFF, OU=DS, OU=SEC, O=LINST",
"CN=$myclient");
echo "Search result is ".$sr."<p>";
echo "Number of entires returned is
".ldap_count_entries($ds,$sr)."<p>";
echo "Getting entries ...<p>";
$info = ldap_get_entries($ds, $sr);
echo "Data for ".$info["count"]." items returned:<p>";
echo "<HR>";
for ($i=0; $i<$info["count"]; $i++) {
echo "Full name (fullname) entry is: ".
$info[$i]["fullname"][0] ."<br>";
echo "Job title (title) entry is: ". $info[$i]["title"][0]
.."<br>";
echo "Common name (cn) entry is: ". $info[$i]["cn"][0]
.."<br>";
echo "E-mail (mail) entry is: ". $info[$i]["mail"][0] ."<br>";
echo "Telephone (telephonenumber) entry is: ".
$info[$i]["telephonenumber"][0]."<br>";
echo "Domain (dn) is: ". $info[$i]["dn"] ."<P><HR>\n";
echo printall($info[$i]);
}
echo "<P><B>Closing connection</B>";
ldap_close($ds);
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
//----------------------------------------------------------------
Any suggestions welcome.
Mike
Navigation:
[Reply to this message]
|