Hello,
Can someone please look at my search.php code and tell me how to authenticate to an ldap server. The code I am using will allow me to see info on the ldap server. However, I can not figure out how to search and authenticate. Any help would be greatly appreciated.
Note: There is a form page with a username, password, and submit button that uses the search.php page as its action. I want to be able to type in username(cn) and password to log in and authenticate to ldap server.
<html>
<head>
</head>
<body>
<?php
/*
** ldap_list example
** This script explores the OUs at CTW
** Links are created to explore units within units
*/
if(!isset($dn))
{
$dn = "ou=Floor09,o=CTW";
}
print("<B>Search DN:</B> $dn<BR>\n"
//connect to LDAP server
if(!($ldap=ldap_connect("localhost"))
{
die("Could not connect to LDAP server!"
}
$filter = "objectClass=*";
$attributes = array("cn", "mail", "givenname", "surname", "telephonenumber"
$query = "(&(cn=" . $POST['cn'] . ")";
//perform search
if(!($result = ldap_search($ldap, $dn, $filter, $attributes)))
{
die("Nothing Found!"
}
$entries = ldap_get_entries($ldap, $result);
for($i = 0; $i < $entries["count"]; $i++)
{
if(!$entries[$i]["mail"][0])
{
}
else
{
//print($entries[$i]["dn"]);
//print(" "
print($entries[$i]["cn"][0]);
print(" "
print($entries[$i]["mail"][0]);
print(" "
print($entries[$i]["givenname"][0]);
print(" "
print($entries[$i]["surname"][0]);
print(" "
print($entries[$i]["telephonenumber"][0]);
}
print("<BR>\n"
}
ldap_free_result($result);
//close ldap connection
ldap_close($ldap);
?>
</body>
</html>
Thanks!
Can someone please look at my search.php code and tell me how to authenticate to an ldap server. The code I am using will allow me to see info on the ldap server. However, I can not figure out how to search and authenticate. Any help would be greatly appreciated.
Note: There is a form page with a username, password, and submit button that uses the search.php page as its action. I want to be able to type in username(cn) and password to log in and authenticate to ldap server.
<html>
<head>
</head>
<body>
<?php
/*
** ldap_list example
** This script explores the OUs at CTW
** Links are created to explore units within units
*/
if(!isset($dn))
{
$dn = "ou=Floor09,o=CTW";
}
print("<B>Search DN:</B> $dn<BR>\n"
//connect to LDAP server
if(!($ldap=ldap_connect("localhost"))
{
die("Could not connect to LDAP server!"
}
$filter = "objectClass=*";
$attributes = array("cn", "mail", "givenname", "surname", "telephonenumber"
$query = "(&(cn=" . $POST['cn'] . ")";
//perform search
if(!($result = ldap_search($ldap, $dn, $filter, $attributes)))
{
die("Nothing Found!"
}
$entries = ldap_get_entries($ldap, $result);
for($i = 0; $i < $entries["count"]; $i++)
{
if(!$entries[$i]["mail"][0])
{
}
else
{
//print($entries[$i]["dn"]);
//print(" "
print($entries[$i]["cn"][0]);
print(" "
print($entries[$i]["mail"][0]);
print(" "
print($entries[$i]["givenname"][0]);
print(" "
print($entries[$i]["surname"][0]);
print(" "
print($entries[$i]["telephonenumber"][0]);
}
print("<BR>\n"
}
ldap_free_result($result);
//close ldap connection
ldap_close($ldap);
?>
</body>
</html>
Thanks!