# Php ldap bind

**URL:** <https://forum.kirupa.com/t/php-ldap-bind/300123>\
**Category:** Uncategorized\
**Created:** [November 16, 2009, 3:58pm UTC](https://forum.kirupa.com/t/php-ldap-bind/300123 "2009-11-16T15:58:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blood\_dew](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@Blood\_dew](https://forum.kirupa.com/u/Blood_dew)\
**Post date:** [November 16, 2009, 3:58pm UTC](https://forum.kirupa.com/t/php-ldap-bind/300123/1 "2009-11-16T15:58:55Z")

</div>

I am trying to do log-ins to an intranet site for work. I’ve got ldap working to the point where I can authenticate as the domain administrator and perform a basic search in php. If I try to use my log in (which is a member of the administrators group) or a test user account, I cannot authenticate. The users I am testing with are in the same OU, I also tried giving domain users read and execute security rights to the php\_ldap.dll file of the webserver.

I’m working on a windows 2k domain  
my webserver is running a WAMP 2 in win 2003 install that includes php 5.2.9 and apache 2.2.11

Please ask if there is any additional information needed.

Here is the code I am using to handle the login process:

\<?php  
include (‘functions.php’);  
include (‘config.php’);

session\_start();

$username = $\_POST[‘username’]; #needs security methods  
$password = $\_POST[‘password’]; #needs security methods

$ldaprdn = ‘[example.org/Users/](http://example.org/Users/)’.$username; // ldap rdn or dn  
$ldappass = $password; // associated password

$ds=ldap\_connect(LDAP\_SERVER); // must be a valid LDAP server!  
echo "connect result is " . $ds . “\<br /\>”;

if ($ds) {  
echo “Binding …”;

$r=ldap\_bind($ds, $ldaprdn, $ldappass);

if ($r == 1) {

```
$_SESSION['valid_user'] = $username;

```

} else {

if (isset($\_SESSION[‘failed’]) == true) {  
$\_SESSION[‘failed’] = $\_SESSION[‘failed’] + 1;  
} else {  
$\_SESSION[‘failed’] = 1;  
}

}  
echo “Closing connection”;  
ldap\_close($ds);  
}

header (‘location: helpdesk.php’);

?\>

helpdesk.php checks to see if you have a valid session and attempts to build a dashboard page if a session username was created or not. As mentioned it is only working as administrator and no other users.

Thanks in advance for any insight.
