-
×InformationNeed Windows 11 help?Check documents on compatibility, FAQs, upgrade information and available fixes.
Windows 11 Support Center. -
-
×InformationNeed Windows 11 help?Check documents on compatibility, FAQs, upgrade information and available fixes.
Windows 11 Support Center. -
- HP Community
- Printers
- Printer Setup, Software & Drivers
- why can't my HP access Ldap or Windows ADS!

Create an account on the HP Community to personalize your profile and ask a question
04-04-2022
04:27 AM
- last edited on
04-04-2022
10:12 AM
by
Ric_ob
this is a littel PHP work to use ldap with php7.4 and STARTTLS.
<?php
if(isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
} else {
?>
<form action="#" method="POST">
<label for="username">Username: </label><input id="username" type="text" name="username" />
<label for="password">Password: </label><input id="password" type="password" name="password" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
}
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
$ldap="ldap://10.140.10.1:389";
//$username="administrator@example.net";
//$password="aiweiK5ee";
$ds=ldap_connect($ldap);
$ldapbind=false;
if(ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) {
echo "<p>1 - OK</p><br>";
if(ldap_set_option($ds, LDAP_OPT_REFERRALS, 0)) {
echo "<p>2 - OK</p><br>";
if(ldap_start_tls($ds)) {
echo "<p>3 - OK</p><br>";
$ldapbind = @ldap_bind($ds, $username, $password);
} else { echo "<p>1 - ERROR</p><br>"; }
} else { echo "<p>2 - ERROR</p><br>"; }
} else { echo "<p>3 - ERROR</p><br>"; }
// ldap_close($ds);
if(!$ldapbind) {
echo "<p>4 - ERROR</p><br>";
} else {
$filter="(&(objectClass=user)(objectClass=person)(objectClass=organizationalperson))";
$result = ldap_search($ds,"CN=Users,DC=example,DC=net",$filter);
ldap_sort($ds,$result,"samaccountname");
if ( $result == "" ) { echo "<p>result is nothing!</p><br>"; } else { echo "<p>result erfolgreich!</p><br>"; }
$info = ldap_get_entries($ds, $result);
if ( $info["count"] == 0 ) { echo "<p>info leer!</p><br>"; } else { echo "<p>info erfolgreich!</p><br>"; }
for ($i=0; $i<$info["count"]; $i++) {
if ( $info["count"] < 1 ) {
break;
}
echo "<br>" . $info[$i]["count"] . "," . $info[$i]["distinguishedname"][0] . "<br>";
echo "cn: ".$info[$i]["cn"][0]."<br>givenname: ".$info[$i]["givenname"][0]."<br> sn: ".$info[$i]["sn"][0]."<br> sAMAccountName: ".$info[$i]["samaccountname"][0]."<br>";
echo "c: ".$info[$i]["c"][0]."<br>co: ".$info[$i]["co"][0]."<br> l: ".$info[$i]["l"][0]."<br>";
echo "postalcode: ".$info[$i]["postalcode"][0]."<br>streetaddress: ".$info[$i]["streetaddress"][0]."<br> telephonenumber: ".$info[$i]["telephonenumber"][0]."<br>";
echo "mail: ".$info[$i]["mail"][0]."<br>memberof: ".$info[$i]["memberof"][0]."<br> st: ".$info[$i]["st"][0]."<br>";
//$sr = ldap_list($ds, $basis_dn, "memberof=*", $nur_dieses);
//echo '<pre>';//var_dump($info);//echo '</pre>';//$userDn = $info[$i]["distinguishedname"][0];
}
echo "<p>4 - OK<br>";
}
@ldap_close($ds);
?>
this works with cn with email and with Domain\username
this is so simple that it is beyond me why this setting is so faulty.