PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
im unable to get the LDAP attibutes. But i can able to connect the LDAP server My code is
<?
require("ldapclass.php");
ini_set('memory_limit','64M');
$ldap = new ldap("dc 192.168.05","389","dc=sholen,dc=edu");
$ldap->ldapConn();
//binding with the database using username and password
$bind=$ldap->ldapBind("XXXX@sholen.edu","YYYYY");
//fixing directory name
$ouArray = array("staff");
//searching the department name for all the users in staff
$results = $ldap->ldapSearch("department","*",$ouArray,"department");
$i=0;
$results= array_unique($results);
//rearranging array
foreach($results as $output)
{
$name[$i]=$output;
echo " $name[$i] <br>";
$i++;
}
//ldap authentication
$auth = $ldap->ldapAuthenticate("search@sholen.edu","sholen123");
?>
The above code list the Departments in my ldap server....i want to list the attributes in my LDAP server...can any one HELP me please ????
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
Last edited by pickle on Mon Nov 30, 2009 10:41 am, edited 1 time in total.
Reason:Removed ldap username & password
You're obviously using an LDAP class to talk to LDAP, but you haven't posted the code for that class - so there's not a lot we can do.
When talking to LDAP, you set the attributes you want to retrieve when you do the query. Check the documentation for your LDAP class to see if there's a setAttributes() or some method to name the attributes you want.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
<? 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;
}
}
?>
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
The above code list the Departments in my ldap server....i want to list the attributes in my LDAP server...can you HELP me adding the code for getting attributes in same example ????