Hi All :evilgrin:

I have currently a months training on PHP and currently busy with a Asset Register Project. I have a problems authenticating with Ldap from PHP.

Here is my code

First Form ( LoginPage.php)

<html>
<head>
<title>Login Form</title>
</head>

<body>

<p>Login Form</p>

<!-- create the “main” form with an input text box named pid and a password text box named password -->
<form name="main" method="post" action="authcheck.php">
<table>
<tr>
<td align="right">Username: </td>
<td> <input name="Username" type="text" id="Username"> </td>
</tr>
<tr>
<td align="right">password: </td>
<!-- make sure this is type “password”! -->
<td> <input name="password" type="password" id="password"> </td>
</tr>
<tr>
<td align="center" colspan="2"><input name="btnsubmit" type="submit" value="Submit"></td>
</tr>
</table>
</form>

</body>
</html>

Second Page (Authcheck.PHP)

<?php
$host = 'xx.xxxxxxxxxxxxx.net';
$port = 'xxx';
$baseDn = 'dc=xxxxxxxx,dc=net';
$pid = $POST['Username']; // get these values explicitly from the POST
$credential = $
POST['Username'];

/ldap will bind anonymously, make sure we have some credentials/
if (isset($Username) && $password != '' && isset($credential)) {
$ldap = ldap_connect($host,$port);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 10);
if (isset($ldap) && $ldap != '') {

/ search for pid dn /
$result = @ldap_search($ldap, $baseDn, 'uuUsername='.$Username, array('dn'));
if ($result != 0) {
$entries = ldap_get_entries($ldap, $result);
$principal = $entries[0]['dn'];
if (isset($principal)) {

/ bind as this user /
if (@ldap_bind($ldap, $principal, $credential)) {
print('Authenticate success');
} else {
print('Authenticate failure');
}
} else {
print('User not found in LDAP');
}
ldap_free_result($result);

} else {
print('Error occured searching the LDAP');
}
ldap_close($ldap);
} else {
print('Could not connect to LDAP at '.$host);
}
}
?>

    Hi;
    i'm also have porblem with ldap to add user

    i tried this code to check bind

    <?php
    
    // using ldap bind
    $ldaprdn  = 'administrator@jnct.com';     // ldap rdn or dn
    $ldappass = '123';  // associated password
    
    // connect to ldap server
    $ldapconn = ldap_connect("jnct1.jnct.com")
        or die("Could not connect to LDAP server.");
    
    if ($ldapconn) {
    
    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
    
    // verify binding
    if ($ldapbind) {
        echo "LDAP bind successful...";
    } else {
        echo "LDAP bind failed...";
    }
    
    }
    
    ?> 
    

    it successful.
    Now i try to add user by this code :

    <?php
        $dn = "OU=Users,DN=jnct,DN=com";
    
    $ad = ldap_connect("ldap://jnct1.jnct.com")
          or die("Couldn't connect to AD!");
    
    ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
    
    $bd = ldap_bind($ad,"administrator@jnct.com","123") 
          or die("Couldn't bind to AD!");
    
    $user["givenname"] = "Jason";
    $user["sn"] = "Gilmore";
    
    
    $result = ldap_mod_add($ad, $dn, $user);
    
    if ($result){ 
    echo "User added!";
    }else{
                     echo "There was a problem!";
    }
    
    ldap_unbind($ad);
    
    ?>
    

    The result is :
    Warning: ldap_mod_add() [function.ldap-mod-add]: Modify: Operations error in c:\camel\www\php\s.php on line 16
    There was a problem!


    Deatails:
    Domain Name : jnct.com ( local only)
    Mysever Name : jnct1
    OS:windows server2003 R2
    php : 4.4.4
    Server API : Apache
    admin : administrator
    Pass: 123

    Plz help me .

      Write a Reply...