HTML Code index.php
<!DOCTYPE html>
<html>
<head>
<title>LDAP</title>
<style>
body {text-align: center;}
form{margin: 0 auto; width: :500px;}
input{padding: 10px; font-size: 20px;}
</style>
</head>
<body>
<h1> Authentication with Active Directory</h1>
<form action="ladp.php" method="POST">
<input type="text" name="username" /><br>
<input type="password" name="password" /><br>
<input type="submit" name="Login" /><br>
</form>
</body>
</html>
ldap.php
<?php
/*
//http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
//https://www.youtube.com/watch?v=AEjGhzZpGlg
$ldap_dn = "uid=".$_POST["username"].",dc=example,dc=com";
$ldap_password = $_POST["password"];
$ladp_con = ldap_connect("ldap.forumsys.com");
ldap_set_option($ladp_con, LDAP_OPT_PROTOCAL_VERSION, 3);
if(@ldap_bind($ladp_con,$ldap_dn,$ldap_password)){
echo 'Authenticated';
}else{
echo "Invalid Credentials";
}
*/
//Code2
$ldap_dn = "cn=read-only-admin,dc=example,dc=com";
$ldap_password = "password";
$ladp_con = ldap_connect("ldap.forumsys.com");
ldap_set_option($ladp_con, LDAP_OPT_PROTOCAL_VERSION, 3);
if(ldap_bind($ladp_con,$ldap_dn,$ldap_password)){
$filter = "(uid=newton)";
$result = ldap_search($ladp_con, "dc=example,dc=com", $filter) or exit("Unable to search");
$entries = ldap_get_entries($ladp_con, $result);
print "<pre>";
print_r($entries);
print "</pre>";
}else{
echo "Invalid user / pass or other errors!";
}
No comments:
Post a Comment