T4VN is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support
    HOME  |  HOSTING COUPON  |  TEMPLATE  |  PHP SCRIPTS  |  LINK TO US  |  LINK  |  REGISTER | CONTACT
::: Member Login :::
 Username
 Password
 
Forgot your password ?
::: PHP Tutotal :::
  PHP Basic (7)
  PHP Advanced (4)
  PHP Database (2)
  Coding Step By Step (8)
  PHP and AJAX (0)
::: PHP Example :::
  Arrays (1)
  Code Highlighters (3)
  Database Functions (12)
  Date & Time (5)
  E-Mail (6)
  Forms (5)
  Guestbooks (1)
  Logging (2)
  Miscellaneous (10)
  Password Generators (3)
  Randomizers (3)
  String Manipulation (10)
  User Authentication (6)
::: Search On T4VN :::
::: T4VN Statistics :::
  PHP Scripts : 64
  PHP Example : 67
  PHP Tutorials : 21
  PHP News : 93
  Total Coupon : 36
  Other Tutorials :
  Member : 215
  Visitor Online : 2
  Today Visit: 127
  Total Visitor : 285993
  Most Online : 41
::: Sponsored Links :::

PR 4 For This Webpage

Vinaora Logo
Home Today :

LDAP class

Author : countnikon

This class has the ability to authenticate against LDAP and Active Directory. It also has the ability to perform searches against LDAP and AD to pull information from the LDAP and AD Schema.

PHP Example :

<?PHP
class ldap
{
  var 
$ldapConn//ldap connection storage variable
  
var $ldapBind//ldap bind storage variable
  
var $entries;  //ldap entries variable
  
var $ldapLookupUser;
  var 
$ldapLookupPass;
  var 
$server;
  var 
$port;
  var 
$by;
  var 
$search;
  var 
$baseDN;
  function 
ldap($server,$port,$baseDN)
  {
    
$this->server=$server;
    
$this->port=$port;
    
$this->baseDN=$baseDN;
  }
  function 
ldapConn()
  {
    
$this->ldapConn = @ldap_connect($this->server,$this->port);
    return 
$this->ldapConn;
  }
  function 
ldapBind($ldapLookupUser,$ldapLookupPass)
  {
    if(@
ldap_bind($this->ldapConn,$ldapLookupUser,$ldapLookupPass))
    {
      
$this->ldapBind = @ldap_bind($this->ldapconn,$ldapLookupUser,$ldapLookupPass);
      return 
true;
    }
    else
      return 
false;
  }
  function 
ldapAuthenticate($usrname,$password)
  {
    if(@
ldap_bind($this->ldapConn,$usrname,$password))
      return 
true;
    else
      return 
false;
  }
  function 
ldapSearch($by,$search,$ous,$searchby)
  {
    
$c=0;
    foreach(
$ous as $ou)
    {
      
$read=ldap_search($this->ldapConn,"ou=$ou,$this->baseDN""$searchby=*$search*");
      
$entries ldap_get_entries($this->ldapConn$read);
      for (
$i=0$i<$entries["count"]; $i++)
      {
        if(
$entries[$i][$by][0])
          
$values[$c]=$entries[$i][$by][0];
        
$c++;
      }
    }
    return 
$values;
  }
}
?>



Usage Example:


PHP Example :

0<?PHP 
1
require("ldapclass.php"); 
2$ldap = new ldap("dc controller","389","dc=domain,dc=net"); 
3$ldap->ldapConn(); 
4echo "<hr>"
5echo "Binding Connection<br>"
6$bind=$ldap->ldapBind("user","pass"); 
7if($bind==true
8  echo "Bind Successful<br>"
9else 
10  echo "Bind Failed<br>"
11echo "<hr>"
12echo "Trying to lookup user...<br>"
13$ouArray = array('ou1','ou2','ou3','ou4','ou5'); 
14$results $ldap->ldapSearch("mail","usrname",$ouArray,"samaccountname"); 
15foreach($results as $output
16  echo $output."<br>"
17$results $ldap->ldapSearch("title","usrname",$ouArray,"samaccountname"); 
18foreach($results as $output
19  echo $output."<br>"
20echo "<hr>"
21$auth $ldap->ldapAuthenticate("usrname","pass"); 
22if($auth
23  echo "successful authentication<br>"
24else 
25  echo "Bad.  You no get in."
26?> 


Other Example
PHP 5 Object Oriented - Member access abstraction
Very easy login page
Security Image
Easy Simple Password Protector
Guest Login That Uses A Cookie


::: Resources :::
  Links Directory
  Programming 2 3
  Webmaster 2 3
  Web Design 2 3
  Web Hosting 2 3
  Other Links 2 3
  Asian ShowBiz News
  Teach Seo For You
::: New Templates :::




::: Other Tutorials :::
 Program Design

  Powered By T4VN.NET - Version 2.0 - CopyRight © T4VN.NET 2005-2007