Page 1 of 1

Cannot get ldap to work

Posted: Sat Jun 05, 2010 6:34 am
by MacGoose
Hi!

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>";

	}

?>
It takes forever to do the binding and then it returns null. I have the ldap module on my server and it is enabled. To connect and bind to a server seems fairly easy - it's only a few simple functions, but still I can't do it.

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

Re: Cannot get ldap to work

Posted: Sat Jun 05, 2010 12:37 pm
by cpetercarter
Does this help?

Re: Cannot get ldap to work

Posted: Sat Jun 05, 2010 1:37 pm
by MacGoose
I'm sorry to say that it did not help at all. I have the same problem as before...

, MacGoose