I'm trying to get ldap to work using php. This is my code:
Code: Select all
<?php
echo "<h3>LDAP query test</h3>";
echo "Connecting to...<br />";
$ds = ldap_connect( "ldap.ntnu.no" );
echo "Connect result is ( " . $ds . " )<br />";
if( $ds ) {
echo "Binding...<br />";
$r = ldap_bind( $ds );
echo "Bind result is ( " . $r . " )<br />";
if( $r ) {
echo "Searching...<br />";
$sr = ldap_search( $ds, "dc=NTNU, dc=no", "ou=*" );
echo "Search result is ( " . $sr . " )<br />";
if( $sr ) {
echo "Number of entires returned is " . ldap_count_entries( $ds, $sr ) . "<br />";
}else {
echo "<h4>Search returned null!</h4>";
}
}else {
echo "<h4>Unable to bind to LDAP server!</h4>";
}
echo "Closing connection...<br />";
ldap_close( $ds );
echo "Closed!<br />";
}else {
echo "<h4>Unable to connect to LDAP server!</h4>";
}
?>
I've been unsing JXplorer and it have no problem reading the same ldap directory as I try to connect to using php. Using JXplorer I connect anonymously just as I do using php.
Any help appreciated as I am so stuck.
TIA!
, MacGoose