Improve debugging information for ldap
diff --git a/ldap.php b/ldap.php
index 6232364..f203950 100755
--- a/ldap.php
+++ b/ldap.php
@@ -34,14 +34,20 @@
 
         //First: Connect to  LDAP Server
         $connect = ldap_connect($ldap_host, $ldap_port)
-                or debug(">>Could not connect to LDAP server to add user<<");
+                or debug(">>Could not connect to LDAP server to add user $ldap_user<<");
         ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
         ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
 
         //Login to LDAP
-        ldap_bind($connect, $ldap_user, $ldap_pass)
-                or debug(">>Could not bind to $ldap_host to add user<<");
-
+        $bind = ldap_bind($connect, $ldap_user, $ldap_pass);
+        if (!$bind) {
+             debug(">>Could not bind to $ldap_host to add user $ldap_user<<");
+            if (ldap_get_option($connect, LDAP_OPT_DIAGNOSTIC_MESSAGE, $extended_error)) {
+               debug("Error Binding to LDAP: $extended_error");
+             } else {
+               debug("Error Binding to LDAP: No additional information is available.");
+             }
+         }
 
         $result = ldap_search($connect, $ldaptree, "(" . $filter . "=" . $query . ")") or die("Error in search query: " . ldap_error($connect));
         $data = ldap_get_entries($connect, $result);
@@ -95,8 +101,16 @@
 
         // Adding new user
 
-        $add = ldap_add($connect, $base_dn, $info)
-                or debug(">>Not able to load user <<");
+        $add = ldap_add($connect, $base_dn, $info);
+        if (!$add) {
+              debug(">>Not able to add user $info<<");
+             debug(">>Could not bind to $ldap_host to add user $ldap_user<<");
+            if (ldap_get_option($connect, LDAP_OPT_DIAGNOSTIC_MESSAGE, $extended_error)) {
+               debug("Error Binding to LDAP: $extended_error");
+             } else {
+               debug("Error Binding to LDAP: No additional information is available.");
+             }
+         }
 
         // Close connection
         ldap_close($connect);