
Originally Posted by
gep13
Although you are using the same credentials, I suspect that there is an issue with the identity of the process that is running Visual Studio, i.e. your account. For instance, do you know exactly what line the code is failing on? Are you even able to make the connection to the LDAP Server?
Gary
I'm not sure what identity of the process is, here's the php code I have that does pull records out of the LDAP:
Code:
<?php
$UID = $_GET['UID'];
$isPostBack = false;
$boolEditClicked = isset($_POST["EditButton"]);
$boolSaveClicked = isset($_POST["SaveButton"]);
$boolCancelClicked = isset($_POST["CancelButton"]);
$isPostBack = ($boolEditClicked || $boolSaveClicked || $boolCancelClicked);
echo "<html><title>LDAP Details: ".$UID."</title><head>";
?>
<style type="text/css">
body
{font-family: helvetica, verdana, arial;font-size: 12px;color: #000;}
tr th
{font-family: helvetica, verdana, arial;font-size: 12px;border: solid 1px #000;background-color: #C0C0C0;}
tr td
{font-family: helvetica, verdana, arial;font-size: 12px;color: #000;border: solid 1px #000;}
</style>
<script language="javascript" type="text/javascript">
function SubmitForm()
{
var xForm = window.document.DetailsForm;
xForm.method="post";
xForm.submit();
}
</script>
</head><body><form id="DetailsForm" name="DetailsForm"><center>
<?php
// basic sequence with LDAP is connect, bind, search, interpret search
// result, close connection
// using ldap bind
$ldaprdn = 'cn=root'; // ldap rdn or dn
$ldappass = 'password'; // associated password
// connect to ldap server
$ldapconn = ldap_connect("server") or die("Could not connect to LDAP server.");
if ($ldapconn) {
if ($boolSaveClicked) {
//Updating the current LDAP entry, the save button was clicked
$dnToEdit = "cn=users,dc=ecop,dc=com"."";
$result = ldap_search($ldapconn, $dnToEdit);
if ($result) {
//Not finished yet
}
} else {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
$srchString = "uid=".$UID;
//Search surname entry
$sr=ldap_search($ldapconn, "cn=users,dc=ecop,dc=com", $srchString);
$info = ldap_get_entries($ldapconn, $sr);
echo "<table border='1' cellspacing='0' cellpadding='5'><tr><th>LDAP Info</th><th>Factories</th></tr><tr><td><table border='0' cellspacing='0' cellpadding='5'>";
for ($i = 0; $i<$info["count"]; $i++) {
$strUid = "";
$strPW = "";
$strEmployeeType = "";
$strSn = "";
$strGivenName = "";
$strMail = "";
$strLanguage = "";
$strCN = "";
$intSupplierCount = 0;
for ($ii=0; $ii<$info[$i]["count"]; $ii++) {
$data = $info[$i][$ii];
for ($iii=0; $iii<$info[$i][$data]["count"]; $iii++) {
if ($data == "uid") {
$strUid = $info[$i][$data][$iii];
} else if ($data == "userpassword") {
$strPW = $info[$i][$data][$iii];
} else if ($data == "employeetype") {
$strEmployeeType = $info[$i][$data][$iii];
} else if ($data == "sn") {
$strSn = $info[$i][$data][$iii];
} else if ($data == "givenname") {
$strGivenName = $info[$i][$data][$iii];
} else if ($data == "mail") {
$strMail = $info[$i][$data][$iii];
} else if ($data == "preferredlanguage") {
$strLanguage = $info[$i][$data][$iii];
} else if ($data == "cn") {
$strCN = $info[$i][$data][$iii];
}
}
}
if ($strUid != "") {
echo "<tr><td>UID:</td><td>" . $strUid . "</td><td>CN:</td><td>";
if ($strCN != "") {
echo $strCN;
} else {
echo " ";
}
echo "</td></tr>";
if (!$boolEditClicked) {
//Display the results, not in edit mode
echo "<tr><td>Password:</td><td colspan='3'>" . $strPW . "</td></tr>";
echo "<tr><td>First Name:</td><td>" . $strGivenName . "</td><td>Last Name:</td><td>" . $strSn . "</td></tr>";
echo "<tr><td>Type:</td><td>";
if ($strEmployeeType != "") {
echo $strEmployeeType;
} else {
echo " ";
}
echo "</td><td>Language:</td><td>";
if ($strLanguage != "") {
echo $strLanguage;
} else {
echo " ";
}
echo "</td></tr>";
echo "<tr><td>Email:</td><td colspan='3'>";
if ($strMail != "") {
echo $strMail;
} else {
echo " ";
}
echo "</td></tr>";
} else {
//Edit the record
echo "<tr><td>Password:</td><td colspan='3'><input type='text' id='PasswordTextBox' name='PasswordTextBox' value='" . $strPW . "' style='width:100%;' /></td></tr>";
echo "<tr><td>First Name:</td><td><input type='text' id='FirstNameTextBox' name='FirstNameTextBox' value='" . $strGivenName . "' style='width:100%;' /></td><td>Last Name:</td><td><input type='text' id='LastNameTextBox' name='LastNameTextBox' value='" . $strSn . "' style='width:100%;' /></td></tr>";
echo "<tr><td>Type:</td><td><select id='TypeDropDownList' name='TypeDropDownList'><option value='Buyer'";
if ($strEmployeeType == "Buyer") {
echo " selected";
}
echo ">Buyer</option><option value='Planner'";
if ($strEmployeeType == "Planner") {
echo " selected";
}
echo ">Planner</option><option value='Supplier'";
if ($strEmployeeType == "Supplier") {
echo " selected";
}
echo ">Supplier</option></select></td>";
echo "<td>Language:</td><td><input type='text' id='LanguageTextBox' name='LanguageTextBox' value='" . $strLanguage . "' style='width:100%;' /></td></tr>";
echo "<tr><td>Email:</td><td colspan='3'><input type='text' id='EmailTextBox' name='EmailTextBox' value='" . $strMail . "' style='width:100%;' /></td></tr>";
}
}
}
echo "</table></td><td><ul>";
for ($i = 0; $i<$info["count"]; $i++) {
for ($ii=0; $ii<$info[$i]["count"]; $ii++) {
$data = $info[$i][$ii];
if ($data == "ecopsupplier") {
for ($jj=0; $jj<count($info[$i][$data])-1; $jj++) {
echo "<li>".$info[$i][$data][$jj]."</li>";
}
}
}
}
ldap_close($ldapconn);
echo "</ul></td></tr></table><br />\n";
if (!$boolEditClicked) {
echo "<input type='submit' id='EditButton' name='EditButton' value='Edit' onclick='Javascript:SubmitForm();' />";
} else {
echo "<input type='submit' id='SaveButton' name='SaveButton' value='Save' onclick='Javascript:SubmitForm();' /> ";
echo "<input type='submit' id='CancelButton' name='CancelButton' value='Cancel' onclick='Javascript:SubmitForm();' />";
}
} else {
die ("LDAP bind failed");
}
}
}
echo "<br /><br /><br /><input type='button' name='CloseButton' id='CloseButton' value='Close' onclick='Javascript:self.close();' /></form></center></body></html>";
?>
With that code I'm able to view the LDAP entry (I can even view it in "edit" mode with the textboxes and all), so I'm not sure why the insert doesn't work (insert page's code posted a couple of days ago).