Login   Register  
PHP Classes
elePHPant
Icontem

File: demo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Satish Kumar  >  LDAP configuration  >  demo.php  >  Download  
File: demo.php
Role: Example script
Content type: text/plain
Description: ldap class working demo
Class: LDAP configuration
Manipulate data records stored in a LDAP server
Author: By
Last change:
Date: 5 years ago
Size: 1,556 bytes
 

Contents

Class file image Download
<?php
require_once(dirname(__FILE__).'/config.php');//configuration file
require_once(dirname(__FILE__).'/class.ldap.php');//ldap class file

//Initialize class file
$conobj=new Connect2LDAP();

//Connect LDAP Server
$ds=Connect2LDAP::connect2LDAPServer($conobj->ldapserver,$conobj->ldapport);

//Bind with LDAP instance
Connect2LDAP::bind2LDAPServer($ds,$conobj->basedn,$conobj->basepass);


$searchdn="ou=Group,dc=domain,dc=com";
$filter="cn=*";



//Search LDAP directory
Connect2LDAP::searchLDAPDirectory($ds,$conobj->searchdn,$conobj->filter);


// Prepare for LDAP insert data-------------


//Please change the record entry as required by your company directory structure
   
$record['objectclass'][0] = "top";
   
$record['objectclass'][1] = "posixAccount";
   
$record['objectclass'][2] = "inetOrgPerson";

   
$record["uid"]="abc";
   
$record["mail"]="a@a.com";
   
$record["givenName"]="abc";
   
$record["sn"]="test1";
   
$record["cn"]="abc";
   
$record["displayName"]="abc";
   
$record["userPassword"]='{md5}'base64_encode(pack('H*'md5("111"))); //encrypt password "111" using MD5
   
$record["homeDirectory"]="/home/test";
   
$record["gidNumber"]="31048";
   
$record["uidNumber"]="160908";

//LDAP insert dn
$adddn="ou=People,dc=domain,dc=com";

$newadddn="uid=abc,".$adddn;

    
Connect2LDAP::addRecord($ds,$newadddn,$record);

//---------------------------------------

//Delete LDAP record
$deletedn="uid=abc,".$conobj->adddn;
    
Connect2LDAP::deleteRecord($ds,$deletedn,true);

//Close LDAP Connection
    
Connect2LDAP::closeLDAPConnection($ds);
?>