Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: PHP and LDAP


Message #1 by cullan.crothers@w... on Fri, 11 May 2001 17:33:55
Dear Pro PHP:

***This is the correct email for my problem. disregard the first one it 
had a code error in it.*** Below is the correct version of my problem.

I am having trouble with PHP using ldap_add() when trying to add users 
into a directory in Netscape Directory Server. My Server name is 
teresa.jxn.wcom.com, my port is 389, and my directory tree is ou=people, 
o=jxn.wcom.com. The ou=people part is where I am tring to add the users 
using PHP. I can search, delete, and modify entries just fine using PHP's 
LDAP functions, but when I try to use the ldap_add I get the error ***LDAP
Add operation cannot be completed***. My code that I use for the 
ldap_modify function (that works fine) looks like this ----->>>>>

<HTML>
<BODY>

<?php

$base_DN = "ou=People, o=jxn.wcom.com";
$dnString = "uid=TCrothers, ou=People, o=jxn.wcom.com";

$connect = ldap_connect("teresa.jxn.wcom.com", 389);

$resultEntry = ldap_search($connect, $base_DN, "(cn=*Crothers*)");
if(ldap_count_entries($connect, $resultEntry) <= 0)
{
   echo "No entries returned from the directory!";
}
else
{
   $result = ldap_get_entries($connect, $resultEntry);
}

//The attributes to be modified

$newEntry["cn"] = "Teresa Crothers";
$newEntry["uid"] = "TCrothers";
$newEntry["mail"] = "TeresaDCrothers@n...";
//modify the entry
if((ldap_modify($connect, $dnString, $newEntry)) == false)
{
echo "LDAP modification failed!";
}
else
{
echo "<CENTER>The entry was modified successfully!</CENTER>";
}

//Finished modifying
//Now display the results

$search = ldap_search($connect, $base_DN, "(cn=*Grow*)");

if(ldap_count_entries($connect, $search) <= 0)
{
   echo "No entries returned from the directory!";
}
else
{
   $result = ldap_get_entries($connect, $search);
}
echo "<center><TABLE BORDER=\"1\" bgcolor=\"navajowhite\"><TR>";
echo "<TR><TH><B>Name</B></TH><TH><B>E-mail</B></TH><TH><B>User 
ID</B></TH><TH><B>Telephone</TH>";
echo "</TR>";

$numentries = $result["count"];

for($i = 0; $i < $numentries; $i++)
{
   echo "<TR><TD>" . $result[$i]["cn"][0] . "</TD><TD>" . $result[$i]
["mail"][0] . "</TD>";
   echo "<TD>" . $result[$i]["uid"][0] . "</TD><TD>" . $result[$i]
["telephonenumber"][0] . "</TD></TR>";
}

echo "</TABLE></center>";

?>

</body>
</HTML>
-------------------------->>>>>>>>>

That code works fine. 

****The addition code that brings the error looks like this ------>>>>****

<?php

$connect = ldap_connect("teresa.jxn.wcom.com", 389); 
$bind = ldap_bind($connect, "cn=Directory Manager", "cullancrothers");

    $info["cn"] = "Brian Pope";
    $info["givenname"] = "Brian";
    $info["sn"] = "Pope";
    $info["uid"] = "BPope";
    $info["mail"] = "ketzelkat@y...";
    $info["telephonenumber"]="000-000-0000";
$add = ldap_add($connect, "cn=Brian Pope, ou=people, o=jxn.wcom.com", 
$info);
   
?>

Something in this add code doesn't line up right and I can't tell what it 
is. See if anybody has an answer to this.

Thanks;

Cullan Crothers
cullan.crothers@w...

  Return to Index