Skip to content

Instantly share code, notes, and snippets.

@samueljon
Created March 14, 2017 13:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samueljon/f33fae69cb5eaab799faf84ed934f803 to your computer and use it in GitHub Desktop.
Save samueljon/f33fae69cb5eaab799faf84ed934f803 to your computer and use it in GitHub Desktop.
For debugging Ldap connectivity issues in php
<?php
// Set the ldap server
$ldapurl = "host.domain.tld";
$ldapuser = "user@domain.tld";
$ldappass = 'userpassword';
// 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";
exit;
}
// Rest of code goes here
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment