note 98351 added to function.ldap-bind

From: Date: Thu, 10 Jun 2010 11:48:50 +0000
Subject: note 98351 added to function.ldap-bind
Groups: php.notes 
Request: Send a blank email to php-notes+get-170014@lists.php.net to get a copy of this message
I'm using OpenLDAP on linux and found out the right bind sequence the hard way... so I'm sharing it with you: (wkaiser solution is ok if everything works fine, but for development I would suggest using ldap_error command like this) <?php $ldapconfig['host'] = '10.10.10.10'; $ldapconfig['port'] = NULL; $ldapconfig['basedn'] = 'dc=company,dc=com'; $ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']); $dn="uid=".$username.",ou=people,".$ldapconfig['basedn']; if ($bind=ldap_bind($ds, $dn, $password)) { echo("Login correct"); } else { echo("Unable to bind to server.</br>"); echo("msg:'".ldap_error($ds)."'</br>");#check if the message isn't: Can't contact LDAP server :) #if it say something about a cn or user then you are trying with the wrong $dn pattern i found this by looking at OpenLDAP source code :) #we can figure out the right pattern by searching the user tree #remember to turn on the anonymous search on the ldap server if ($bind=ldap_bind($ds)) { $filter = "(cn=*)"; if (!($search=@ldap_search($ds, $ldapconfig['basedn'], $filter))) { echo("Unable to search ldap server<br>"); echo("msg:'".ldap_error($ds)."'</br>");#check the message again } else { $number_returned = ldap_count_entries($ds,$search); $info = ldap_get_entries($ds, $search); echo "The number of entries returned is ". $number_returned."<p>"; for ($i=0; $i<$info["count"]; $i++) { var_dump($info[$i]);#look for your user account in this pile of junk and apply the whole pattern where you build $dn to match exactly the ldap tree entry } } } else { echo("Unable to bind anonymously<br>"); echo("msg:".ldap_error($ds)."<br>"); } } ?> as you can see most of the examples use "cn=username" and OpenLDAP uses "uid=username" but who knows what will be used in the future builds, this code will help you check it out (I hope :) ---- Server IP: 69.147.83.197 Probable Submitter: 91.199.25.129 (proxied: 127.0.0.1) ---- Manual Page -- http://www.php.net/manual/en/function.ldap-bind.php Edit -- https://master.php.net/note/edit/98351 Del: integrated -- https://master.php.net/note/delete/98351/integrated Del: useless -- https://master.php.net/note/delete/98351/useless Del: bad code -- https://master.php.net/note/delete/98351/bad+code Del: spam -- https://master.php.net/note/delete/98351/spam Del: non-english -- https://master.php.net/note/delete/98351/non-english Del: in docs -- https://master.php.net/note/delete/98351/in+docs Del: other reasons-- https://master.php.net/note/delete/98351 Reject -- https://master.php.net/note/reject/98351 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170014) next »