Skip to content

Instantly share code, notes, and snippets.

@vijayjt
Created April 10, 2017 19:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijayjt/18385c691bf32de7d3a33a12a60af605 to your computer and use it in GitHub Desktop.
Save vijayjt/18385c691bf32de7d3a33a12a60af605 to your computer and use it in GitHub Desktop.
Code for testing LDAP connection from an Azure Web App in an ASE to a AD DC in a VNet
<?php
$domain = 'acme.local';
$username = 'aduser';
$password = 'replaceWithPassword';
$ldapconfig['host'] = '192.168.21';
$ldapconfig['port'] = 389;
$ldapconfig['basedn'] = 'dc=acme,dc=local';
$ldap_dn = "DC=acme,DC=local";
//print_r($ldapconfig);
$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
if ($ds) {
echo("ldap connect completed\n");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
$bind=ldap_bind($ds, $username.'@'.$domain, $password);
if ($bind) {
echo "LDAP bind successful...$bind <br />";
$attributes= array( "sn", "givenname", "mail", "samaccountname");
$filter = '(&(objectCategory=person)(samaccountname=*))';
$results = ldap_search($ds, $ldap_dn, $filter, $attributes);
if ($retval) {
echo("Login correct <br />");
$info = ldap_get_entries($ds, $results);
print_r($info);
for ($i=0; $i<$entries["count"]; $i++)
{
echo $entries[$i]["displayname"]
[0]."(".$entries[$i]["l"][0].")<br />";
}
} else {
echo("Login incorrect <br />".ldap_error($retval));
}
}else {
echo "ERROR: LDAP bind failed...<br />";
}
ldap_unbind($bind);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment