Cannot get ldap to work

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MacGoose
Forum Newbie
Posts: 4
Joined: Wed Jan 27, 2010 11:38 am

Cannot get ldap to work

Post 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
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Cannot get ldap to work

Post by cpetercarter »

Does this help?
MacGoose
Forum Newbie
Posts: 4
Joined: Wed Jan 27, 2010 11:38 am

Re: Cannot get ldap to work

Post by MacGoose »

I'm sorry to say that it did not help at all. I have the same problem as before...

, MacGoose
Post Reply