Groups > Novell > Novell Developers discussion > Re: PHP, LDAP_BIND w/ Edir




PHP, LDAP_BIND w/ Edir

PHP, LDAP_BIND w/ Edir
Mon, 17 Jul 2006 22:06:09 GMT
I am trying to do an LDAP_bind using my username and password and for some
reason it won't bind.  I am sure the server, username, and password are
correct.

Does anyone have any ideas?

<?php
// basic sequence with LDAP is connect, bind, search, interpret search
// result, close connection

$server = 'ldap://161.31.24.18:389';
$dn="uid=MWeston,ou=fs,o=uca";
$pw="xxxxxxxxxxxx";
$searchstring="(objectclass=user)";
$attnames=array("uid","surname","mail","group
membership","givenname","department","ou",&qu
ot;fullname");

$ds=ldap_connect($server);  // must be a valid LDAP server!

ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($ds) { 
    $r=ldap_bind($ds,$dn,$pw); 
                           // read-only access
    if($r) echo "ldap_bind success<br>";
	
	//ldap_search searches sub.  
	//ldap_list searches one level.
	//ldap_read searches base.
    $r=ldap_search($ds,"ou=fs,o=uca", $searchstring, $attnames);  
	if($r) echo "ldap_search success<br>";
	
    echo "Number of entires returned is
".ldap_count_entries($ds,$r)."<p>";

    $entries = ldap_get_entries($ds, $r);
    echo "Data for ".$entries["count"]." items
returned:<p>";

    for ($i=0; $i<$entries["count"]; $i++) {
        echo "<p>";
		// Any multi-valued object will return like the following:
		// $entries[0]['mail']['count']=2
		// $entries[0]['mail'][0]='a@b.com'
		// $entries[0]['mail'][1]='b@b.com'
		foreach($attnames as $attname){
			if(isset($entries[$i][$attname])){
				if(is_array($entries[$i][$attname])){
					for($j=0;$j<$entries[$i][$attname]["count"];$j++){
						echo $attname." entry is: ". $entries[$i][$attname][$j]
."<br>";
					}
				}else{
					echo $attname." entry is:
".$entries[$i][$attname]."<br>";
				}
			}
		}
		echo "</p>";
    }
    ldap_close($ds);

} else {
    echo "<h4>Unable to connect to LDAP server</h4>";
}
?>                                                                           

             
Post Reply
Re: PHP, LDAP_BIND w/ Edir
Tue, 18 Jul 2006 07:32:26 GMT
So you're trying to bind to the non-SSL port, so is your LDAP server 
configured to allow cleartext binds? What's the error you're getting back?

-- 


Peter
Post Reply
about | contact