PHP User authentic with LDAP

2011 January 3 at 3:33 pm Leave a comment

Jika dalam suatu perusahaan memiliki banyak aplikasi, apa yang akan dirasakan para user?  Emmm… mudah ditebak mereka para user akan kesulitan mengingat user dan password dari masing-masing aplikasi, dan para administrator aplikasi akan disibukan memenage banyak database user Beruntung ada LDAP(Lightweight Directory Access Protocol) yang bisa membaca AD System. Sehingga user/password aplikasi akan sama dengan user/password Operating system. Berikut cuplikan code




$base_dn=”dc=mydomain; dc=co; dc=id”;#ex:


$rs = @ldap_connect($server,$port);
@ldap_set_option($rs, LDAP_OPT_PROTOCOL_VERSION, $ldap_version);
@ldap_set_option($rs, LDAP_OPT_REFERRALS, $ldap_ref);
$result = @ldap_search($rs, $base_dn,”(sAMAccountName={$username})”);
$result_user = @ldap_get_entries($rs, $result);
if($result_user[“count”] ==1 ){

$first_user = $result_user[0];
$ldap_user_dn = $first_user[“dn”];
$bind_user = @ldap_bind($rs, $ldap_user_dn, $password);
if ($bind_user)$success=true;



if($success)echo “Sucess”;
else echo “Invalid User / Password”;

<form method=post>
<tr><td>user Name <td>:<td><input type=text name=user_name value=”<? echo $username ?>”>
<tr><td>password <td>:<td><input type=password name=pwd value=”<? echo $password ?>”>
<tr><td><input type=submit value=”Click Here to Test”>

Entry filed under: PHP. Tags: .

Install php 5 mssql di server ubuntu Basic Photographi

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


%d bloggers like this: