Hi tsinka,
Yes theres a lot of incomplete documentation of the windows port. So I have to just try and understand as much as i can from the documentation there is.
How silly of my not to inlude the binding details. You are right i have root dn and the password to bind to the ldap server in my slapd.conf
rootdn "cn=Manager,dc=mydomain,dc=com"
rootpw *****
but im not sure exactly where to use them. I thought maybe here
$ldap["user"] = "uname";
$ldap["pass"] = "password";
but i think that this where the names of the form text fields will be eg
<input name="password" type="text">
$ldap["pass"] = "password";
this is my current code, I have added a submit button.
<?php
if($_POST["Submit1"]) {
// LDAP variables
$ldap["user"] = "uname";
$ldap["pass"] = "password";
$ldap["host"] = " localhost ";
$ldap["port"] = 389;
//$ldap["dn"] = "uid=".$ldap["user"].",ou=users,dc=mydomain,dc=com";
$ldap["base"] = "dc=mydomain,dc=com";
// connecting to ldap
$ldap["conn"] = ldap_connect( $ldap["host"], $ldap["port"] )
or die( "Could not connect to {$ldap["host"]}" );
// set protocol version
ldap_set_option($ldap["conn"], LDAP_OPT_PROTOCOL_VERSION, 3);
// binding to ldap
//$ldap["bind"] = ldap_bind( $ldap["conn"], $ldap["dn"], $ldap["pass"] );
$ldap["bind"] = ldap_bind( $ldap["conn"], $ldap["user"], $ldap["pass"] );
if( !$ldap["bind"] )
{
echo ldap_error( $ldap["conn"] );
exit;
}
// search for the user on the ldap server and return all
// the user information
$ldap["result"] = ldap_search( $ldap["conn"], $ldap["base"], "uid=".$ldap["user"] );
if( $ldap["result"] )
{
// retrieve all the entries from the search result
$ldap["info"] = ldap_get_entries( $ldap["conn"], $ldap["result"] );
}
else
{
echo ldap_error( $ldap["conn"] );
exit;
}
if( $ldap["info"] )
{
// Add the user’s department name and email address
// to the session
$SESSION["userdept"] = $ldap["info"][0]["department"][0];
$SESSION["usermail"] = $ldap["info"][0]["mail"][0];
}
else
{
echo ldap_error( $ldap["conn"] );
exit;
}
// close connection to ldap server
$ldap_close( $ldap["conn"] );
}else { }?>
<form name="login" method="post" action="<? $PHP_SELF ?>">
<p>
Username
<input name="uname" type="text">
</p>
<p>Password
<input name="password" type="text">
</p>
<p>
<input type="submit" name="Submit1" value="Submit">
</p>
<p>
</p>
</form>