I have a PHP login page with LDAP authentication. The script connect successfully to my LDAP server, and it is possible for me to log in with my credentials.
But I want to make the script more specific. I Want that the script connect to specific user group in my AD. The usergroup is TEST_LDAP. And it located in OU=Groups,OU=BE,OU=Company,DC=wetnl. I have tried it, but without succes.
Here is the PHP script:
session_start();
$succes = TRUE;
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if ( isset($_POST['gebruikersnaam']) && isset($_POST['wachtwoord']))
{
/* aanmelden via LDAP */
$ds=ldap_connect("10.10.10.110"); // geef hier het ip-adres in van een geldige LDAP server!
if(!$ds)
{
$succes = FALSE;
$foutmelding = 'Geen verbinding met Active Directory';
}
if($succes === TRUE)
{
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
$r=ldap_bind($ds, $_POST['gebruikersnaam'], $_POST['wachtwoord']);
if($r)
{
$_SESSION['gebruiker_id'] = $row['GEBRUIKERID'];
$_SESSION['aangemeld'] = TRUE;
header("Location: index.php");
}
else
{
$succes = FALSE;
$foutmelding = 'Inloggen is niet gelukt door ongeldige combinatie gebruikersnaam/wachtwoord.<br/>';
}
ldap_close($ds);
}
}
else
{
$error = 'Vul zowel gebruikersnaam als wachtwoord in om in te loggen.';
}
}