I'm trying to connect to an LDAP server to authenticate user credentials.
I've found a few users with this same issue but their solutions did not work for me.
here's what I'm using:
<?php
define('LDAP_SERVER', 'LDAP://pdc.mydomain.com');
define('LDAP_PORT', 389);
define('LDAP_TOP', 'dc=mydomain,dc=com');
if(isset($_POST['username']))
{
if(!($ds = ldap_connect(LDAP_SERVER, LDAP_PORT)))
{
die ("Could not connect to mydomain domain");
}
$un = $_POST['username'].",".LDAP_TOP;
//echo stripslashes($un)."<br>";
$ldapbind = ldap_bind($ds, stripslashes($un), $_POST['password']);
if($ldapbind)
echo "login success";
else
echo "login failed";
}
?>
I've tried using "mydomain\myusername" and just "myusername".
I added the stripslashes() function when neither worked to test that, and still no dice.
the error I get every time is: Warning: ldap_bind(): Unable to bind to server: Invalid credentials
any help would be greatly appreciated
TIA
I know it is a pretty old question and if you still need an answer then what happens if you run this code in a single php file?
More info is here.