Debugging LDAP php scripts

Sometimes trying to find out what's wrong when you try to connect to an LDAP from your php scripts and programs can be very hard.

Here is one of the most important commands which you can use in order to troubleshoot your ldap connections.

ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);

To show the errors you must use the ldap error function:

Here is an example of error handling php and ldap:

// Set the ldap server
$ldapurl = "";
// Set the debug flag
$debug = true;

// Set debugging
if ($debug) {
  ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);

// connect to ldap server
$ldapconn = ldap_connect($ldapurl) or die ("Couldn't connect"); 

// binding to ldap server
echo "Trying to bind with $ldapuser - $ldappass\n";
$ldapbind = @ldap_bind($ldapconn, $ldapuser, $ldappass);

if (!$ldapbind) {
echo "Unable to bind to server $ldapurl\n";
echo "OpenLdap error message: " . ldap_error($ldapconn) . "\n";

// Rest of code goes here



  1. Thanks a lot, just what i was after

  2. Thanks Michael, this helped a lot.


  3. :( que se poner en esta definicion xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  4. I am looking for some good blog sites for studying. I was searching over search engines and found your blog site. Well i like your high quality blog site design plus your posting abilities. Keep doing it.

    PSD to Wordpress
    wordpress website development


  5. Consistently learning the new skills and using them to improve myself in the form of performance for betterment.

    Cpa offers

  6. This is often very useful for an entry. I just marked this post for future reference. Keep sharing that kind of beautiful message. Thank you for sharing. This is a terribly delicate subject.

  7. This is so amazing post very interesting.Keep sharing dude.Well done.
    Download Latest Version HTTP Debugger Pro Crack

  8. hi was just seeing if you minded a comment. i like your website and the thme you picked is super. I will be back.
    how to convert psd to wordpress

  9. replica rolex watches uk, combining elegant style and cutting-edge technology, a variety of styles of replica rolex sea dweller watches, the pointer walks between your exclusive taste style.

  10. Crack Download After looking through a few blog articles on your website,we sincerely appreciate the way you blogged.We’ve added it to our list of bookmarked web pages and will be checking back in the nearfuture. Please also visit my website and tell us what you think.Great work with hard work you have done I appreciate your work thanks for sharing it.
    HTTP Debugger Pro Crack