Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP 5.3.5 ldap_search(): Search: Can't contact LDAP server
    primarykey
    data
    text
    <p>I have a LDAP PHP class which works on all other PHP installations in our company. However, the code stopped working now that I changed from SuSE to Ubuntu 11.04. The PHP version is 5.3.5.</p> <p>I try to connect to our LDAP server. After connecting to it I try to run ldap_search. It fails with the error message 'ldap_search(): Search: Can't contact LDAP server'. I had a look into the traffic using wireshark and could see communication happening between php and ldap, alas no connection happened.</p> <p>Thanks for your thoughts, Uwe</p> <p>Here is the code I use:</p> <pre><code>class ldap{ private $ldap_conn; private $ldaphost; private $ldapport; public function __construct () { $this-&gt;ldaphost = 'ldaps://ourserver.co.nz'; // obviously a fake name $this-&gt;ldapport = 636; $this-&gt;ldap_conn = ldap_connect($this-&gt;ldaphost, $this-&gt;ldapport) or die("Could not connect to $this-&gt;ldaphost"); } public function signin ($username,$password, $applicationName) { $dn = "o=MY_COM"; $filter="(cn=$username)"; $justthese = array("dn","fullname", "mail"); $sr=ldap_search($this-&gt;ldap_conn, $dn, $filter, $justthese); $people = ldap_get_entries($this-&gt;ldapconn, $sr); if (!$people || count($people) == 0 || $people['count'] == 0) { //Nothing found, quit. return AUTH_ERROR_NO_DN; } $dn = ($people[0]['dn']); if (($dn!='')&amp;&amp;($password!='')) { $loginStatus = @ldap_bind($this-&gt;ldapconn, $dn, $password); if ($loginStatus) { $fullname = $people[0]['fullname'][0]; if ($fullname=='') { $fullname =$dn; } $user = array( 'logged_in_dn' =&gt; $dn, 'password' =&gt; $password, 'username' =&gt; $fullname, 'cn' =&gt; $username, 'mail' =&gt; $people[0]['mail'][0], 'status' =&gt; 'AUTHENTICATED' ); } else { $user = array( 'status'=&gt; array('AUTH_ERROR_WRONG_PASSWORD'), 'details' =&gt; array( 'logged_in_dn' =&gt; '', 'password' =&gt; '', 'username' =&gt; '', 'cn' =&gt; '', 'mail' =&gt; '', 'status' =&gt; 'AUTHENTICATED' ) ); } } else { $user = array( 'status'=&gt; array('AUTH_ERROR_NO_DN'), 'details' =&gt; array( 'logged_in_dn' =&gt; '', 'password' =&gt; '', 'username' =&gt; '', 'cn' =&gt; '', 'mail' =&gt; '', 'status' =&gt; 'AUTHENTICATED' ) ); } return $user; } </code></pre> <p>This is the unit test executing the methods: class unit_ldapConnectTest extends TadPhpUnitTestCase</p> <pre><code>{ function testLdapconnection () { $ldap = new LDAP(); $user = $ldap-&gt;signin('myname','password',''); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload