De gegevens van de gebruikers moet je echt via LDAP uit de AD halen. Daarna kan je ze opslaan in een sessie of in een andere DB, of natiirlijk elke keer als je ze nodig hebt ophalen uit de AD.
Ik heb het zo gedaan:
<?php
session_start();
include("settings.php");
$t = explode(".",$_POST['domain']);
$DC = ",";
for($i=0;$i<count($t);$i++) {
$DC .= "DC=".$t[$i];
if($i<count($i)) $DC .= ",";
}
$LDAP['container'] = $LDAP['container'].$DC;
unset($t);
if ($ds = ldap_connect($LDAP['address'],$LDAP['port'])) {
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($r = ldap_bind($ds,$_POST['user']."@".$_POST['domain'],$_POST['password'])) {
if($sr=ldap_search($ds, $LDAP['container'], "sAMAccountName=".$_POST['user'], array('cn','givenName','sn','mail','mobile','homedirectory'))) {
if($info = ldap_get_entries($ds, $sr)) {
//$_SESSION["name"] = $info[0]["cn"][0];
//$_SESSION["firstname"] = $info[0]["givenname"][0];
//$_SESSION["surname"] = $info[0]["sn"][0];
//$_SESSION["email"] = $info[0]["mail"][0];
//$_SESSION["mobile"] = $info[0]["mobile"][0];
//$_SESSION["homedirectory"] = $info[0]["homedirectory"][0];
ldap_unbind($ds);
header("location: page.php");
}
else {
echo "Couldn't collect userdata.";
}
}
else {
echo "Couldn't search in container for user details.";
}
}
else {
echo "Couldn't bind with server ".$LDAP['address'].". Check your username and password.";
}
}
else {
echo "Couldn't connect with server ".$LDAP['address'].".";
}
?>
Met dit als formulier:
<form action="login.php" method="post">
Domein: <select name="domain">
<?php
include("settings.php");
foreach($LDAP['domain'] as $domain) {
echo "<option value=\"".$domain[0]."\">".$domain[1]."</option>\n";
}
?>
</select>
<br />
Gebruikernaam: <input type="text" name="user" /><br />
Wachtwoord: <input type="password" name="password" /><br />
<input type="submit" />
</form>
En de settings.php
<?php
// LDAP Server Settings
$LDAP['address'] = "x.x.x.x";
$LDAP['port'] = 389;
$LDAP['container'] = "OU=SBSUsers,OU=Users,OU=MyBusiness"; // Without your domain
$LDAP['domain'] = array(array("domein.local","Domein"));
?>
Dit werkt op een standaard SBS2003 server. Let hierbij wel op de container.
Er staat véél meer info in de AD, maar ik heb er maar een aantal opgehaald. Sterker nog. Ik gebruik ze niet eens... :) Ik heb waar alle sessie-variabelen worden aangemaakt een connectie naar een MySQL-DB waarin ik de login wegschrijf. Vervolgens controleer ik via de MySQL of een gebruiker ingelogd is.
Ik hoop dat je hier iets aan hebt.
Elwin